Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit 1811f78

Browse files
committed
Merge remote-tracking branch 'origin/2.0' into 2.0-OpenAPITools
2 parents fe26de1 + 94fd427 commit 1811f78

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,17 @@ private RequestBody convertFormDataToRequestBody(List<io.swagger.models.paramete
659659
schema.setMinLength(sp.getMinLength());
660660
schema.setMaxLength(sp.getMaxLength());
661661

662-
Object exampleExtension = sp.getVendorExtensions().get("x-example");
663-
if (exampleExtension != null) {
664-
schema.setExample(exampleExtension);
662+
if (sp.getVendorExtensions() != null) {
663+
Object exampleExtension = sp.getVendorExtensions().get("x-example");
664+
if (exampleExtension != null) {
665+
schema.setExample(exampleExtension);
666+
}
667+
Object nullableExtension = sp.getVendorExtensions().get("x-nullable");
668+
if (nullableExtension != null) {
669+
schema.setNullable((Boolean) nullableExtension);
670+
}
671+
schema.setExtensions(convert(sp.getVendorExtensions()));
665672
}
666-
schema.setExtensions(convert(sp.getVendorExtensions()));
667673

668674
if (sp.getMultipleOf() != null) {
669675
schema.setMultipleOf(new BigDecimal(sp.getMultipleOf().toString()));

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class V2ConverterTest {
8888
private static final String ISSUE_762_JSON = "issue-762.json";
8989
private static final String ISSUE_765_YAML = "issue-765.yaml";
9090
private static final String ISSUE_768_JSON = "issue-786.json";
91+
private static final String ISSUE_820_YAML = "issue-820.yaml";
9192

9293
private static final String API_BATCH_PATH = "/api/batch/";
9394
private static final String PETS_PATH = "/pets";
@@ -724,6 +725,33 @@ public void testIssue755() throws Exception {
724725
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_755_YAML);
725726
assertNotNull(oas);
726727
}
728+
729+
@Test(description = "OpenAPI v2 converter - Conversion param extensions should be preserved")
730+
public void testIssue820() throws Exception {
731+
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_820_YAML);
732+
assertNotNull(oas);
733+
Operation post = oas.getPaths().get("/issue820").getPost();
734+
assertNotNull(post.getRequestBody().getContent().get("multipart/form-data"));
735+
assertNotNull(post.getRequestBody().getContent().get("multipart/form-data").getSchema());
736+
Map<String, Schema> properties = post.getRequestBody().getContent().get("multipart/form-data").getSchema().getProperties();
737+
assertNotNull(properties);
738+
assertEquals(properties.size(), 3, "size");
739+
Schema foo = properties.get("foo");
740+
assertNotNull(foo);
741+
assertNotNull(foo.getExtensions());
742+
assertEquals(foo.getExtensions().get("x-ext"), "some foo");
743+
assertEquals(foo.getNullable(), null);
744+
Schema bar = properties.get("bar");
745+
assertNotNull(bar);
746+
assertNotNull(bar.getExtensions());
747+
assertEquals(bar.getExtensions().get("x-ext"), "some bar");
748+
assertEquals(bar.getNullable(), Boolean.TRUE);
749+
Schema baz = properties.get("baz");
750+
assertNotNull(baz);
751+
assertNotNull(baz.getExtensions());
752+
assertEquals(baz.getExtensions().get("x-ext"), "some baz");
753+
assertEquals(baz.getNullable(), Boolean.FALSE);
754+
}
727755

728756
private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
729757
SwaggerConverter converter = new SwaggerConverter();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
swagger: "2.0"
2+
info:
3+
version: "1.0.1"
4+
title: "Test for issue 820"
5+
basePath: "/v1"
6+
paths:
7+
/issue820:
8+
post:
9+
operationId: "issue820"
10+
parameters:
11+
- name: foo
12+
in: formData
13+
description: some foo param
14+
required: false
15+
type: string
16+
x-ext: some foo
17+
- name: bar
18+
in: formData
19+
description: some bar param
20+
required: true
21+
type: integer
22+
x-nullable: true
23+
x-ext: some bar
24+
- name: baz
25+
in: formData
26+
description: some baz param
27+
required: true
28+
type: integer
29+
x-nullable: false
30+
x-ext: some baz
31+
responses:
32+
200:
33+
description: "success"

0 commit comments

Comments
 (0)