Skip to content

Commit 50d8cfb

Browse files
authored
Merge pull request #1716 from wsalembi/issue-1715
[swagger-parser-v2-converter] vendor extensions from body params not copied to RequestBody
2 parents e31007f + 081aca1 commit 50d8cfb

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

modules/swagger-parser-v2-converter/src/main/java/io/swagger/v3/parser/converter/SwaggerConverter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.P
831831
}
832832
}
833833
convertExamples(((BodyParameter) param).getExamples(), content);
834+
body.setExtensions(convert(param.getVendorExtensions()));
834835
body.content(content);
835836
return body;
836837
}

modules/swagger-parser-v2-converter/src/test/java/io/swagger/parser/test/V2ConverterTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public class V2ConverterTest {
9797
private static final String ISSUE_1164_YAML = "issue-1164.yaml";
9898
private static final String ISSUE_1261_YAML = "issue-1261.yaml";
9999

100+
private static final String ISSUE_1715_YAML = "issue-1715.yaml";
101+
100102
private static final String API_BATCH_PATH = "/api/batch/";
101103
private static final String PETS_PATH = "/pets";
102104
private static final String PET_FIND_BY_STATUS_PATH = "/pet/findByStatus";
@@ -852,6 +854,16 @@ public void testissue1261() throws Exception {
852854

853855
}
854856

857+
@Test(description = "OpenAPI v2 converter - vendor extensions on body parameters copied to output RequestBody")
858+
public void testissue1715() throws Exception {
859+
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1715_YAML);
860+
assertNotNull(oas);
861+
RequestBody requestBody = oas.getPaths().get("/foo").getPost().getRequestBody();
862+
assertNotNull(requestBody.getExtensions());
863+
assertEquals(1, requestBody.getExtensions().size());
864+
assertEquals("bar", requestBody.getExtensions().get("x-foo"));
865+
}
866+
855867
@Test()
856868
public void testInlineDefinitionProperty() throws Exception {
857869
SwaggerConverter converter = new SwaggerConverter();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
swagger: '2.0'
2+
info:
3+
title: Test for Issue 1715
4+
version: 1.0.0
5+
paths:
6+
/foo:
7+
post:
8+
operationId: doFoo
9+
parameters:
10+
- in: body
11+
name: body
12+
schema:
13+
$ref: '#/definitions/SomeObj'
14+
required: true
15+
x-foo: bar
16+
responses:
17+
'200':
18+
description: OK
19+
definitions:
20+
SomeObj:
21+
type: string
22+
minLength: 1
23+
maxLength: 3
24+
pattern: ^[0-9]+$

0 commit comments

Comments
 (0)