@Test public void adds_regex_to_corresponding_path_parameter_and_keeps_regexless_path_parameter_untouched() { Set<PathParameter> pathParameters = newHashSet( new PathParameter(ClassName.valueOf(String.class.getName()), "param"), new PathParameter(ClassName.valueOf(String.class.getName()), "other"), new PathParameter(ClassName.valueOf(String.class.getName()), "last") ); Collection<PathParameter> result = decorate(pathParameters, "/api/boring/{param}/{other:[1-9]}/{last}"); assertThat(result).extracting(patternToOptionalOfString()) .contains(Optional.empty(), Optional.of("[1-9]"), Optional.empty()); }
public static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path) { final Map<String, String> parametersRegex = extractParametersRegex(path); return pathParameters.stream() .map(pathParameter -> { if (parametersRegex.containsKey(pathParameter.getName())) { return new PathParameter(pathParameter.getType(), pathParameter.getName(), parametersRegex.get(pathParameter.getName()) ); } return pathParameter; }) .collect(toList()); }
ApiPaths { public static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path) { final Map<String, String> parametersRegex = extractParametersRegex(path); return pathParameters.stream() .map(pathParameter -> { if (parametersRegex.containsKey(pathParameter.getName())) { return new PathParameter(pathParameter.getType(), pathParameter.getName(), parametersRegex.get(pathParameter.getName()) ); } return pathParameter; }) .collect(toList()); } }
ApiPaths { public static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path) { final Map<String, String> parametersRegex = extractParametersRegex(path); return pathParameters.stream() .map(pathParameter -> { if (parametersRegex.containsKey(pathParameter.getName())) { return new PathParameter(pathParameter.getType(), pathParameter.getName(), parametersRegex.get(pathParameter.getName()) ); } return pathParameter; }) .collect(toList()); }  }
ApiPaths { public static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path) { final Map<String, String> parametersRegex = extractParametersRegex(path); return pathParameters.stream() .map(pathParameter -> { if (parametersRegex.containsKey(pathParameter.getName())) { return new PathParameter(pathParameter.getType(), pathParameter.getName(), parametersRegex.get(pathParameter.getName()) ); } return pathParameter; }) .collect(toList()); }  static String sanitize(String path); static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path); }
ApiPaths { public static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path) { final Map<String, String> parametersRegex = extractParametersRegex(path); return pathParameters.stream() .map(pathParameter -> { if (parametersRegex.containsKey(pathParameter.getName())) { return new PathParameter(pathParameter.getType(), pathParameter.getName(), parametersRegex.get(pathParameter.getName()) ); } return pathParameter; }) .collect(toList()); }  static String sanitize(String path); static Collection<PathParameter> decorate(Collection<PathParameter> pathParameters, String path);  }