@Test public void shouldNotHaveEmptyStringQuoting() { OpenAPI3PathResolver resolver = instantiatePathResolver("path_multi_simple_label"); Optional<Pattern> optional = resolver.solve(); Pattern p = optional.get(); String pattern = p.toString(); assertThat(pattern.contains("\\Q\\E")).isFalse(); }
public Optional<Pattern> solve() { if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches()) throw RouterFactoryException.createUnsupportedSpecFeature("Path template not supported"); Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath); if (!parameters.isEmpty() && parametersMatcher.find()) { StringBuilder regex = new StringBuilder(); int lastMatchEnd = 0; boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/'; parametersMatcher.reset(); int i = 0; while (parametersMatcher.find()) { String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start()); if (toQuote.length() != 0) regex.append(Pattern.quote(toQuote)); lastMatchEnd = parametersMatcher.end(); String paramName = parametersMatcher.group(1); Optional<JsonObject> parameterOptional = parameters.stream().filter(p -> p.getString("name").equals(paramName)).findFirst(); if (parameterOptional.isPresent()) { JsonObject parameter = parameterOptional.get(); JsonObject fakeSchema = OpenAPI3Utils.generateFakeSchema(parameter.getJsonObject("schema", new JsonObject()), openAPIHolder); String style = parameter.getString("style", "simple"); boolean explode = parameter.getBoolean("explode", false); boolean isObject = OpenAPI3Utils.isSchemaObjectOrCombinators(fakeSchema); boolean isArray = OpenAPI3Utils.isSchemaArray(fakeSchema); String groupName = "p" + i; if (style.equals("simple")) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } else if (style.equals("label")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=" ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else { regex.append( RegexBuilder.create() .escapeCharacter(".").zeroOrOne() .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]" ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } else if (style.equals("matrix")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(";").quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else if (isArray && explode) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().atomicGroup( RegexBuilder.create() .append(";").quote(paramName).append("=") .notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).oneOrMore() ) ); mappedGroups.put(groupName, paramName); } else { regex.append( RegexBuilder.create() .append(";").quote(paramName).append("=") .namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } } else { throw RouterFactoryException.createUnsupportedSpecFeature("Missing parameter definition for parameter name: " + paramName); } i++; } String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length()); if (toAppendQuoted.length() != 0) regex.append(Pattern.quote(toAppendQuoted)); if (endSlash) regex.append("\\/"); return Optional.of(Pattern.compile(regex.toString())); } else { return Optional.empty(); } }
OpenAPI3PathResolver { public Optional<Pattern> solve() { if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches()) throw RouterFactoryException.createUnsupportedSpecFeature("Path template not supported"); Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath); if (!parameters.isEmpty() && parametersMatcher.find()) { StringBuilder regex = new StringBuilder(); int lastMatchEnd = 0; boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/'; parametersMatcher.reset(); int i = 0; while (parametersMatcher.find()) { String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start()); if (toQuote.length() != 0) regex.append(Pattern.quote(toQuote)); lastMatchEnd = parametersMatcher.end(); String paramName = parametersMatcher.group(1); Optional<JsonObject> parameterOptional = parameters.stream().filter(p -> p.getString("name").equals(paramName)).findFirst(); if (parameterOptional.isPresent()) { JsonObject parameter = parameterOptional.get(); JsonObject fakeSchema = OpenAPI3Utils.generateFakeSchema(parameter.getJsonObject("schema", new JsonObject()), openAPIHolder); String style = parameter.getString("style", "simple"); boolean explode = parameter.getBoolean("explode", false); boolean isObject = OpenAPI3Utils.isSchemaObjectOrCombinators(fakeSchema); boolean isArray = OpenAPI3Utils.isSchemaArray(fakeSchema); String groupName = "p" + i; if (style.equals("simple")) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } else if (style.equals("label")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=" ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else { regex.append( RegexBuilder.create() .escapeCharacter(".").zeroOrOne() .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]" ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } else if (style.equals("matrix")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(";").quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else if (isArray && explode) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().atomicGroup( RegexBuilder.create() .append(";").quote(paramName).append("=") .notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).oneOrMore() ) ); mappedGroups.put(groupName, paramName); } else { regex.append( RegexBuilder.create() .append(";").quote(paramName).append("=") .namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } } else { throw RouterFactoryException.createUnsupportedSpecFeature("Missing parameter definition for parameter name: " + paramName); } i++; } String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length()); if (toAppendQuoted.length() != 0) regex.append(Pattern.quote(toAppendQuoted)); if (endSlash) regex.append("\\/"); return Optional.of(Pattern.compile(regex.toString())); } else { return Optional.empty(); } } }
OpenAPI3PathResolver { public Optional<Pattern> solve() { if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches()) throw RouterFactoryException.createUnsupportedSpecFeature("Path template not supported"); Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath); if (!parameters.isEmpty() && parametersMatcher.find()) { StringBuilder regex = new StringBuilder(); int lastMatchEnd = 0; boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/'; parametersMatcher.reset(); int i = 0; while (parametersMatcher.find()) { String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start()); if (toQuote.length() != 0) regex.append(Pattern.quote(toQuote)); lastMatchEnd = parametersMatcher.end(); String paramName = parametersMatcher.group(1); Optional<JsonObject> parameterOptional = parameters.stream().filter(p -> p.getString("name").equals(paramName)).findFirst(); if (parameterOptional.isPresent()) { JsonObject parameter = parameterOptional.get(); JsonObject fakeSchema = OpenAPI3Utils.generateFakeSchema(parameter.getJsonObject("schema", new JsonObject()), openAPIHolder); String style = parameter.getString("style", "simple"); boolean explode = parameter.getBoolean("explode", false); boolean isObject = OpenAPI3Utils.isSchemaObjectOrCombinators(fakeSchema); boolean isArray = OpenAPI3Utils.isSchemaArray(fakeSchema); String groupName = "p" + i; if (style.equals("simple")) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } else if (style.equals("label")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=" ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else { regex.append( RegexBuilder.create() .escapeCharacter(".").zeroOrOne() .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]" ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } else if (style.equals("matrix")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(";").quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else if (isArray && explode) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().atomicGroup( RegexBuilder.create() .append(";").quote(paramName).append("=") .notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).oneOrMore() ) ); mappedGroups.put(groupName, paramName); } else { regex.append( RegexBuilder.create() .append(";").quote(paramName).append("=") .namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } } else { throw RouterFactoryException.createUnsupportedSpecFeature("Missing parameter definition for parameter name: " + paramName); } i++; } String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length()); if (toAppendQuoted.length() != 0) regex.append(Pattern.quote(toAppendQuoted)); if (endSlash) regex.append("\\/"); return Optional.of(Pattern.compile(regex.toString())); } else { return Optional.empty(); } } OpenAPI3PathResolver(String oasPath, List<JsonObject> parameters, OpenAPIHolder openAPIHolder); }
OpenAPI3PathResolver { public Optional<Pattern> solve() { if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches()) throw RouterFactoryException.createUnsupportedSpecFeature("Path template not supported"); Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath); if (!parameters.isEmpty() && parametersMatcher.find()) { StringBuilder regex = new StringBuilder(); int lastMatchEnd = 0; boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/'; parametersMatcher.reset(); int i = 0; while (parametersMatcher.find()) { String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start()); if (toQuote.length() != 0) regex.append(Pattern.quote(toQuote)); lastMatchEnd = parametersMatcher.end(); String paramName = parametersMatcher.group(1); Optional<JsonObject> parameterOptional = parameters.stream().filter(p -> p.getString("name").equals(paramName)).findFirst(); if (parameterOptional.isPresent()) { JsonObject parameter = parameterOptional.get(); JsonObject fakeSchema = OpenAPI3Utils.generateFakeSchema(parameter.getJsonObject("schema", new JsonObject()), openAPIHolder); String style = parameter.getString("style", "simple"); boolean explode = parameter.getBoolean("explode", false); boolean isObject = OpenAPI3Utils.isSchemaObjectOrCombinators(fakeSchema); boolean isArray = OpenAPI3Utils.isSchemaArray(fakeSchema); String groupName = "p" + i; if (style.equals("simple")) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } else if (style.equals("label")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=" ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else { regex.append( RegexBuilder.create() .escapeCharacter(".").zeroOrOne() .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]" ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } else if (style.equals("matrix")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(";").quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else if (isArray && explode) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().atomicGroup( RegexBuilder.create() .append(";").quote(paramName).append("=") .notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).oneOrMore() ) ); mappedGroups.put(groupName, paramName); } else { regex.append( RegexBuilder.create() .append(";").quote(paramName).append("=") .namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } } else { throw RouterFactoryException.createUnsupportedSpecFeature("Missing parameter definition for parameter name: " + paramName); } i++; } String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length()); if (toAppendQuoted.length() != 0) regex.append(Pattern.quote(toAppendQuoted)); if (endSlash) regex.append("\\/"); return Optional.of(Pattern.compile(regex.toString())); } else { return Optional.empty(); } } OpenAPI3PathResolver(String oasPath, List<JsonObject> parameters, OpenAPIHolder openAPIHolder); Optional<Pattern> solve(); Pattern getResolvedPattern(); Map<String, String> getMappedGroups(); }
OpenAPI3PathResolver { public Optional<Pattern> solve() { if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches()) throw RouterFactoryException.createUnsupportedSpecFeature("Path template not supported"); Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath); if (!parameters.isEmpty() && parametersMatcher.find()) { StringBuilder regex = new StringBuilder(); int lastMatchEnd = 0; boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/'; parametersMatcher.reset(); int i = 0; while (parametersMatcher.find()) { String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start()); if (toQuote.length() != 0) regex.append(Pattern.quote(toQuote)); lastMatchEnd = parametersMatcher.end(); String paramName = parametersMatcher.group(1); Optional<JsonObject> parameterOptional = parameters.stream().filter(p -> p.getString("name").equals(paramName)).findFirst(); if (parameterOptional.isPresent()) { JsonObject parameter = parameterOptional.get(); JsonObject fakeSchema = OpenAPI3Utils.generateFakeSchema(parameter.getJsonObject("schema", new JsonObject()), openAPIHolder); String style = parameter.getString("style", "simple"); boolean explode = parameter.getBoolean("explode", false); boolean isObject = OpenAPI3Utils.isSchemaObjectOrCombinators(fakeSchema); boolean isArray = OpenAPI3Utils.isSchemaArray(fakeSchema); String groupName = "p" + i; if (style.equals("simple")) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } else if (style.equals("label")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=" ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else { regex.append( RegexBuilder.create() .escapeCharacter(".").zeroOrOne() .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]" ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } else if (style.equals("matrix")) { if (isObject && explode) { Map<String, JsonObject> properties = OpenAPI3Utils.solveObjectParameters(fakeSchema); List<RegexBuilder> regexBuilders = new ArrayList<>(); for (Map.Entry<String, JsonObject> entry : properties.entrySet()) { groupName = "p" + i; regexBuilders.add( RegexBuilder.create().group( RegexBuilder.create() .escapeCharacter(";").quote(entry.getKey()).append("=") .namedGroup(groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ) ) ); mappedGroups.put(groupName, entry.getKey()); i++; } regex.append( RegexBuilder.create().anyOfGroup( properties.size(), regexBuilders.stream() ) ); } else if (isArray && explode) { regex.append( RegexBuilder.create().namedGroup( groupName, RegexBuilder.create().atomicGroup( RegexBuilder.create() .append(";").quote(paramName).append("=") .notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).oneOrMore() ) ); mappedGroups.put(groupName, paramName); } else { regex.append( RegexBuilder.create() .append(";").quote(paramName).append("=") .namedGroup( groupName, RegexBuilder.create().notCharactersClass( "!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null ).zeroOrMore() ).zeroOrOne() ); mappedGroups.put(groupName, paramName); } } } else { throw RouterFactoryException.createUnsupportedSpecFeature("Missing parameter definition for parameter name: " + paramName); } i++; } String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length()); if (toAppendQuoted.length() != 0) regex.append(Pattern.quote(toAppendQuoted)); if (endSlash) regex.append("\\/"); return Optional.of(Pattern.compile(regex.toString())); } else { return Optional.empty(); } } OpenAPI3PathResolver(String oasPath, List<JsonObject> parameters, OpenAPIHolder openAPIHolder); Optional<Pattern> solve(); Pattern getResolvedPattern(); Map<String, String> getMappedGroups(); static final Pattern OAS_PATH_PARAMETERS_PATTERN; static final Pattern ILLEGAL_PATH_MATCHER; }