From e0fdd8fb2977c59e7f69879428630c64fae9b11a Mon Sep 17 00:00:00 2001 From: wsalembi Date: Tue, 26 Apr 2022 09:30:30 +0200 Subject: [PATCH] [swagger-parser-v2-converter] vendor extensions from body params not copied to RequestBody #1715 --- .../v3/parser/converter/SwaggerConverter.java | 1 + .../swagger/parser/test/V2ConverterTest.java | 12 ++++++++++ .../src/test/resources/issue-1715.yaml | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 modules/swagger-parser-v2-converter/src/test/resources/issue-1715.yaml 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 480795040c..83f62bedf1 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 @@ private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.P } } convertExamples(((BodyParameter) param).getExamples(), content); + body.setExtensions(convert(param.getVendorExtensions())); body.content(content); return body; } 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 da1d632148..cbfa88547a 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 void testissue1261() throws Exception { } + @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 0000000000..6d17cbca3d --- /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