Skip to content

Commit 4a94617

Browse files
sebas2dayfrantuma
authored andcommitted
Keep required field when converting composed model to OpenAPI
1 parent 415d6ed commit 4a94617

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-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
@@ -1194,6 +1194,7 @@ public Schema convert(io.swagger.models.Model v2Model) {
11941194
composed.setTitle(composedModel.getTitle());
11951195
composed.setExtensions(convert(composedModel.getVendorExtensions()));
11961196
composed.setAllOf(composedModel.getAllOf().stream().map(this::convert).collect(Collectors.toList()));
1197+
composed.setRequired(composedModel.getRequired());
11971198

11981199
addProperties(v2Model, composed);
11991200

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class V2ConverterTest {
9696
private static final String ISSUE_1715_YAML = "issue-1715.yaml";
9797

9898
private static final String ISSUE_1767_YAML = "issue-1767.yaml";
99+
private static final String ISSUE_1796_YAML = "issue-1796.yaml";
99100

100101
private static final String API_BATCH_PATH = "/api/batch/";
101102
private static final String PETS_PATH = "/pets";
@@ -877,6 +878,16 @@ public void testIssue1767() throws Exception {
877878
assertNull(secondOperationSecurityRequirements);
878879
}
879880

881+
@Test(description = "OpenAPI v2 converter - composed model should keep required properties")
882+
public void testissue1796() throws Exception {
883+
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1796_YAML);
884+
assertNotNull(oas);
885+
ComposedSchema schema = (ComposedSchema) oas.getComponents().getSchemas().get("ComposedModel");
886+
assertNotNull(schema.getRequired());
887+
assertEquals(schema.getRequired().size(), 1);
888+
assertEquals(schema.getRequired().get(0), "name");
889+
}
890+
880891
@Test()
881892
public void testInlineDefinitionProperty() throws Exception {
882893
SwaggerConverter converter = new SwaggerConverter();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
swagger: "2.0"
2+
info:
3+
title: composed model conversion test
4+
version: 1.0.0
5+
paths:
6+
/composed:
7+
get:
8+
operationId: composed
9+
responses:
10+
"200":
11+
description: OK
12+
schema:
13+
$ref: "#/definitions/ComposedModel"
14+
definitions:
15+
BaseModel:
16+
type: object
17+
required:
18+
- uuid
19+
properties:
20+
uuid:
21+
type: string
22+
ComposedModel:
23+
type: object
24+
required:
25+
- name
26+
allOf:
27+
- $ref: "#/definitions/BaseModel"
28+
properties:
29+
name:
30+
type: string

0 commit comments

Comments
 (0)