File tree Expand file tree Collapse file tree 4 files changed +87
-4
lines changed
swagger-parser-v2-converter/src
main/java/io/swagger/v3/parser/converter
java/io/swagger/parser/test
swagger-parser-v3/src/main/java/io/swagger/v3/parser/util Expand file tree Collapse file tree 4 files changed +87
-4
lines changed Original file line number Diff line number Diff line change @@ -1067,11 +1067,15 @@ public Schema convert(io.swagger.models.Model v2Model) {
10671067 result = arraySchema ;
10681068 } else if (v2Model instanceof ComposedModel ) {
10691069 ComposedModel composedModel = (ComposedModel ) v2Model ;
1070-
1071- ComposedSchema composed = Json .mapper ().convertValue (v2Model , ComposedSchema .class );
1072-
1070+ ComposedSchema composed = new ComposedSchema ();
1071+ composed .setDescription (composedModel .getDescription ());
1072+ composed .setExample (composedModel .getExample ());
1073+ if (composedModel .getExternalDocs () != null ) {
1074+ composed .setExternalDocs (convert (composedModel .getExternalDocs ()));
1075+ }
1076+ composed .setTitle (composedModel .getTitle ());
1077+ composed .setExtensions (convert (composedModel .getVendorExtensions ()));
10731078 composed .setAllOf (composedModel .getAllOf ().stream ().map (this ::convert ).collect (Collectors .toList ()));
1074-
10751079 result = composed ;
10761080 } else {
10771081 String v2discriminator = null ;
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ public class V2ConverterTest {
7777 private static final String ISSUE_673_YAML = "issue-673.yaml" ;
7878 private static final String ISSUE_676_JSON = "issue-676.json" ;
7979 private static final String ISSUE_708_YAML = "issue-708.yaml" ;
80+ private static final String ISSUE_740_YAML = "issue-740.yaml" ;
8081 private static final String ISSUE_756_JSON = "issue-756.json" ;
8182 private static final String ISSUE_758_JSON = "issue-758.json" ;
8283 private static final String ISSUE_762_JSON = "issue-762.json" ;
@@ -619,6 +620,16 @@ public void testIssue708() throws Exception {
619620 assertEquals (schema .getPattern (), "^[0-9]+$" );
620621 }
621622
623+ @ Test (description = "OpenAPI v2 converter - Migrate a schema with AllOf" )
624+ public void testIssue740 () throws Exception {
625+ final OpenAPI oas = getConvertedOpenAPIFromJsonFile (ISSUE_740_YAML );
626+ assertNotNull (oas );
627+ Schema schema = oas .getComponents ().getSchemas ().get ("Action" );
628+ assertTrue (schema instanceof ComposedSchema );
629+ ComposedSchema composedSchema = (ComposedSchema ) schema ;
630+ assertEquals (composedSchema .getAllOf ().size (), 2 );
631+ }
632+
622633 @ Test (description = "OpenAPI v2 converter - no model in body parameter" )
623634 public void testIssue756 () throws Exception {
624635 OpenAPI oas = getConvertedOpenAPIFromJsonFile (ISSUE_756_JSON );
Original file line number Diff line number Diff line change 1+ swagger : ' 2.0'
2+ info :
3+ description : ' Test'
4+ version : 1.0.0
5+ title : OpenAPI Test Issue 740
6+ license :
7+ name : Apache-2.0
8+ url : ' http://www.apache.org/licenses/LICENSE-2.0.html'
9+ host : petstore.swagger.io
10+ basePath : /v2
11+ schemes :
12+ - http
13+ paths :
14+ /ping :
15+ post :
16+ summary : test
17+ operationId : pingOperation
18+ consumes :
19+ - application/json
20+ produces :
21+ - application/json
22+ parameters :
23+ - in : body
24+ name : body
25+ required : true
26+ schema :
27+ $ref : ' #/definitions/Entity'
28+ responses :
29+ ' 200 ' :
30+ description : OK
31+ schema :
32+ $ref : ' #/definitions/Action'
33+ definitions :
34+ Entity :
35+ type : " object"
36+ properties :
37+ id :
38+ type : " string"
39+ example : " 1438752"
40+ description : " The ID of the entity."
41+ readOnly : true
42+ title : " Entity"
43+ description : " A base object for all API entities."
44+ Action :
45+ title : " Action"
46+ allOf :
47+ - $ref : " #/definitions/Entity"
48+ - type : " object"
49+ required :
50+ - " action_type"
51+ discriminator : " action_type"
52+ properties :
53+ name :
54+ type : " string"
55+ description : " The name of the action."
56+ readOnly : true
57+ action_type :
58+ $ref : " #/definitions/ActionType"
59+ ActionType :
60+ type : " string"
61+ title : " ActionType"
62+ description : " Some enum"
63+ enum :
64+ - " value1"
65+ - " value2"
66+ x-swagger-router-model : " ActionTypeDto"
Original file line number Diff line number Diff line change @@ -106,10 +106,12 @@ public SwaggerParseResult deserialize(JsonNode rootNode) {
106106 public SwaggerParseResult deserialize (JsonNode rootNode , String path ) {
107107 SwaggerParseResult result = new SwaggerParseResult ();
108108 try {
109+
109110 ParseResult rootParse = new ParseResult ();
110111 OpenAPI api = parseRoot (rootNode , rootParse , path );
111112 result .setOpenAPI (api );
112113 result .setMessages (rootParse .getMessages ());
114+
113115 } catch (Exception e ) {
114116 result .setMessages (Arrays .asList (e .getMessage ()));
115117
You can’t perform that action at this time.
0 commit comments