Skip to content

Commit 74735b9

Browse files
authored
Merge pull request #1360 from swagger-api/issue-1359
apply flatten option for converted definitions
2 parents 9c7b041 + 5c3a4da commit 74735b9

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public SwaggerParseResult readLocation(String url, List<AuthorizationValue> auth
8888

8989
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(url, convert(auths), resolve);
9090

91-
return convert(result);
91+
return readResult(result, auths, options);
9292
}
9393

9494
@Override
@@ -102,6 +102,11 @@ public SwaggerParseResult readContents(String swaggerAsString, List<Authorizatio
102102
result.setSwagger(resolved);
103103
}
104104
}
105+
return readResult(result, auth, options);
106+
107+
}
108+
109+
private SwaggerParseResult readResult(SwaggerDeserializationResult result, List<AuthorizationValue> auth, ParseOptions options) {
105110
SwaggerParseResult out = convert(result);
106111
if (out != null && options != null && options.isFlatten()) {
107112
try {
@@ -118,7 +123,6 @@ public SwaggerParseResult readContents(String swaggerAsString, List<Authorizatio
118123
} catch (Exception ignore) {}
119124
}
120125
return out;
121-
122126
}
123127

124128
public List<io.swagger.models.auth.AuthorizationValue> convert(List<AuthorizationValue> auths) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.swagger.parser.test;
22

3+
import io.swagger.util.Yaml;
34
import io.swagger.v3.core.util.Json;
45
import io.swagger.v3.oas.models.OpenAPI;
56
import io.swagger.v3.oas.models.Operation;
@@ -850,4 +851,23 @@ public void testissue1261() throws Exception {
850851
assertEquals(schema.getAllOf().get(0).get$ref(),"#/components/schemas/Foo");
851852

852853
}
854+
855+
@Test()
856+
public void testInlineDefinitionProperty() throws Exception {
857+
SwaggerConverter converter = new SwaggerConverter();
858+
ParseOptions parseOptions = new ParseOptions();
859+
parseOptions.setResolve(true);
860+
parseOptions.setFlatten(true);
861+
SwaggerParseResult result = converter.readLocation("src/test/resources/issue-1359.yaml", null, parseOptions);
862+
OpenAPI oas = result.getOpenAPI();
863+
assertNotNull(oas);
864+
865+
Schema pet = oas.getComponents().getSchemas().get("Pet");
866+
Schema property = (Schema) pet.getProperties().get("categoryInline");
867+
assertEquals("#/components/schemas/Pet_categoryInline", property.get$ref());
868+
869+
Schema petCategoryInline = oas.getComponents().getSchemas().get("Pet_categoryInline");
870+
assertNotNull(petCategoryInline);
871+
872+
}
853873
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
swagger: '2.0'
2+
info:
3+
description: |
4+
This is a sample Petstore server. You can find
5+
out more about Swagger at
6+
[http://swagger.io](http://swagger.io) or on
7+
[irc.freenode.net, #swagger](http://swagger.io/irc/).
8+
version: 1.0.0
9+
title: Swagger Petstore
10+
termsOfService: http://swagger.io/terms/
11+
contact:
12+
13+
license:
14+
name: Apache 2.0
15+
url: http://www.apache.org/licenses/LICENSE-2.0.html
16+
host: petstore.swagger.io
17+
paths: {}
18+
definitions:
19+
Category:
20+
type: object
21+
properties:
22+
id:
23+
type: integer
24+
format: int64
25+
name:
26+
type: string
27+
xml:
28+
name: Category
29+
Pet:
30+
type: object
31+
required:
32+
- name
33+
- photoUrls
34+
properties:
35+
id:
36+
type: integer
37+
format: int64
38+
category:
39+
$ref: '#/definitions/Category'
40+
categoryInline:
41+
type: object
42+
properties:
43+
id:
44+
type: integer
45+
format: int64
46+
name:
47+
type: string
48+
name:
49+
type: string
50+
example: doggie
51+
status:
52+
type: string
53+
description: pet status in the store
54+
enum:
55+
- available
56+
- pending
57+
- sold
58+
xml:
59+
name: Pet

0 commit comments

Comments
 (0)