Repository: swagger-api/swagger-parser
Pull request #1718 (2022-05-04 14:11:10)

Bug/issue1169 nosplit v3
This contains a fix for path-element fixing (Delegated PR for @lucian-r)


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
index b15ab812..fcdddb12 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
@@ -621,9 +621,12 @@ public class OpenAPIDeserializer {
 					}
 					ObjectNode path = (ObjectNode) pathValue;
 					PathItem pathObj = getPathItem(path, String.format("%s.'%s'", location, pathName), result);
-					String[] eachPart = pathName.split("[-/.]+");
-					Arrays.stream(eachPart)
-							.filter(part -> part.startsWith("{") && part.endsWith("}") && part.length() > 2)
+                    List<String> eachPart = new ArrayList<>();
+                    Matcher m = Pattern.compile("\\{(.+?)\\}").matcher(pathName);
+                    while (m.find()) {
+                        eachPart.add(m.group());
+                    }
+					eachPart.stream()
 							.forEach(part -> {
 								String pathParam = part.substring(1, part.length() - 1);
 								boolean definedInPathLevel = isPathParamDefined(pathParam,


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index e1c5288d..b9ab21cd 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -806,6 +806,18 @@ public class OpenAPIV3ParserTest {
         assertNotNull(apispec);
     }
 
+    @Test
+    public void testIssue1169noSplit() {
+        ParseOptions options = new ParseOptions();
+        options.setResolve(true);
+        SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation("issue1169-noSplit.yaml", null, options);
+        assertTrue(parseResult.getMessages().size() == 0);
+        OpenAPI apispec = parseResult.getOpenAPI();
+        assertNotNull(apispec);
+    }
+
+
+
     @Test
     public void testIssue339() throws Exception {
         OpenAPIV3Parser openAPIV3Parser = new OpenAPIV3Parser();
diff --git a/modules/swagger-parser-v3/src/test/resources/issue1169-noSplit.yaml b/modules/swagger-parser-v3/src/test/resources/issue1169-noSplit.yaml
new file mode 100644
index 00000000..12c0e083
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue1169-noSplit.yaml
@@ -0,0 +1,35 @@
+openapi: 3.0.1
+info:
+  title: Sample title
+  version: 1.0.0
+servers:
+  - url: /
+paths:
+  /path_{p0}/{p1}{p2}/another-{p3}:
+    put:
+      parameters:
+        - name: p0
+          in: path
+          required: true
+          schema:
+            type: string
+        - name: p1
+          in: path
+          required: true
+          schema:
+            type: string
+        - name: p2
+          in: path
+          required: true
+          schema:
+            type: string
+        - name: p3
+          in: path
+          required: true
+          schema:
+            type: string
+      responses:
+        200:
+          description: sample desc
+          content: {}
+components: {}