Repository: swagger-api/swagger-parser
Pull request #1716 (2022-04-26 07:36:49)

[swagger-parser-v2-converter] vendor extensions from body params not copied to RequestBody
Solves issue #1715 


Patch:
diff --git a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
index 48079504..83f62bed 100644
--- a/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
+++ b/modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java
@@ -831,6 +831,7 @@ public class SwaggerConverter implements SwaggerParserExtension {
             }
         }
         convertExamples(((BodyParameter) param).getExamples(), content);
+        body.setExtensions(convert(param.getVendorExtensions()));
         body.content(content);
         return body;
     }


Test patch:
diff --git a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
index da1d6321..cbfa8854 100644
--- a/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
+++ b/modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java
@@ -97,6 +97,8 @@ public class V2ConverterTest {
     private static final String ISSUE_1164_YAML = "issue-1164.yaml";
     private static final String ISSUE_1261_YAML = "issue-1261.yaml";
 
+    private static final String ISSUE_1715_YAML = "issue-1715.yaml";
+
     private static final String API_BATCH_PATH = "/api/batch/";
     private static final String PETS_PATH = "/pets";
     private static final String PET_FIND_BY_STATUS_PATH = "/pet/findByStatus";
@@ -852,6 +854,16 @@ public class V2ConverterTest {
 
     }
 
+    @Test(description = "OpenAPI v2 converter - vendor extensions on body parameters copied to output RequestBody")
+    public void testissue1715() throws Exception {
+        OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1715_YAML);
+        assertNotNull(oas);
+        RequestBody requestBody = oas.getPaths().get("/foo").getPost().getRequestBody();
+        assertNotNull(requestBody.getExtensions());
+        assertEquals(1, requestBody.getExtensions().size());
+        assertEquals("bar", requestBody.getExtensions().get("x-foo"));
+    }
+
     @Test()
     public void testInlineDefinitionProperty() throws Exception {
         SwaggerConverter converter = new SwaggerConverter();
diff --git a/modules/swagger-parser-v2-converter/src/test/resources/issue-1715.yaml b/modules/swagger-parser-v2-converter/src/test/resources/issue-1715.yaml
new file mode 100644
index 00000000..6d17cbca
--- /dev/null
+++ b/modules/swagger-parser-v2-converter/src/test/resources/issue-1715.yaml
@@ -0,0 +1,24 @@
+swagger: '2.0'
+info:
+  title: Test for Issue 1715
+  version: 1.0.0
+paths:
+  /foo:
+    post:
+      operationId: doFoo
+      parameters:
+        - in: body
+          name: body
+          schema:
+            $ref: '#/definitions/SomeObj'
+          required: true
+          x-foo: bar
+      responses:
+        '200':
+          description: OK
+definitions:
+  SomeObj:
+    type: string
+    minLength: 1
+    maxLength: 3
+    pattern: ^[0-9]+$
\ No newline at end of file