Skip to content

Commit 2a85399

Browse files
Willem Salembierfrantuma
authored andcommitted
Absent type doesn't imply type object #2113
1 parent 3a4ad2e commit 2a85399

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ root = true
88
# Indentation style
99
# Possible values - tab, space
1010
indent_style = space
11+
end_of_line = lf
1112

1213
# File character encoding
1314
# Possible values - latin1, utf-8, utf-16be, utf-16le

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,6 @@ public Schema resolveSchema(Schema schema) {
493493
Schema property = updated.get(key);
494494

495495
if (property.getProperties() != model.getProperties()) {
496-
if (!hasSchemaType(property)) {
497-
if (SpecVersion.V30.equals(property.getSpecVersion())) {
498-
property.setType("object");
499-
} else {
500-
property.addType("object");
501-
}
502-
}
503496
model.addProperties(key, property);
504497
} else {
505498
LOGGER.debug("not adding recursive properties, using generic object");

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,16 @@ public void testIssue1706() {
783783
assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ObjectSchema);
784784
}
785785

786+
@Test
787+
public void testIssue2113() {
788+
ParseOptions options = new ParseOptions();
789+
options.setResolve(true);
790+
options.setResolveFully(true);
786791

792+
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue_2113.yaml", auths, options).getOpenAPI();
793+
ObjectSchema schema = (ObjectSchema) openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema();
794+
assertNull(schema.getProperties().get("goo").getType());
795+
}
787796

788797
@Test
789798
public void selfReferenceTest() {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV31ParserSchemaTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,62 +165,62 @@ private void tearDownWireMockServer() {
165165
public void test$idUrlExternal() throws Exception {
166166
ParseOptions p = new ParseOptions();
167167
p.setResolve(true);
168-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").getAbsolutePath(), null, p);
168+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").toURI().toASCIIString(), null, p);
169169
compare("$id-uri-external", swaggerParseResult);
170170
}
171171

172172
@Test
173173
public void test$idUrlEnclosing() throws Exception {
174174
ParseOptions p = new ParseOptions();
175175
p.setResolve(true);
176-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-enclosing/root.json").getAbsolutePath(), null, p);
176+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-enclosing/root.json").toURI().toASCIIString(), null, p);
177177
compare("$id-uri-enclosing", swaggerParseResult);
178178
}
179179

180180
@Test
181181
public void test$idUrlDirect() throws Exception {
182182
ParseOptions p = new ParseOptions();
183183
p.setResolve(true);
184-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").getAbsolutePath(), null, p);
184+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").toURI().toASCIIString(), null, p);
185185
compare("$id-uri-direct", swaggerParseResult);
186186
}
187187
@Test
188188
public void test$idUrlUnresolvable() throws Exception {
189189
ParseOptions p = new ParseOptions();
190190
p.setResolve(true);
191-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").getAbsolutePath(), null, p);
191+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").toURI().toASCIIString(), null, p);
192192
compare("$id-unresolvable", swaggerParseResult);
193193
}
194194

195195
@Test
196196
public void testAnchorExt() throws Exception {
197197
ParseOptions p = new ParseOptions();
198198
p.setResolve(true);
199-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-external/root.json").getAbsolutePath(), null, p);
199+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-external/root.json").toURI().toASCIIString(), null, p);
200200
compare("$anchor-external", swaggerParseResult);
201201
}
202202

203203
@Test
204204
public void testAnchorInt() throws Exception {
205205
ParseOptions p = new ParseOptions();
206206
p.setResolve(true);
207-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-internal/root.json").getAbsolutePath(), null, p);
207+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-internal/root.json").toURI().toASCIIString(), null, p);
208208
compare("$anchor-internal", swaggerParseResult);
209209
}
210210

211211
@Test
212212
public void testAnchorUnresolve() throws Exception {
213213
ParseOptions p = new ParseOptions();
214214
p.setResolve(true);
215-
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-not-found/root.json").getAbsolutePath(), null, p);
215+
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$anchor-not-found/root.json").toURI().toASCIIString(), null, p);
216216
compare("$anchor-not-found", swaggerParseResult);
217217
}
218218

219219
public void compare(String dir, SwaggerParseResult result) throws Exception {
220220
ObjectMapper mapper = Json31.mapper().copy();
221221
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
222222
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
223-
String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI());
223+
String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI()).replace("\r\n", "\n");
224224
org.testng.Assert.assertEquals(actual,
225225
FileUtils.readFileToString(new File("src/test/resources/3.1.0/dereference/schema/" + dir + "/dereferenced.json")));
226226
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Issue X
5+
servers:
6+
- url: http://petstore.swagger.io/api
7+
paths:
8+
/foo:
9+
post:
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/Foo'
15+
required: true
16+
responses:
17+
200:
18+
description: ok
19+
components:
20+
schemas:
21+
Foo:
22+
type: object
23+
allOf:
24+
- $ref: "#/components/schemas/Goo"
25+
Goo:
26+
type: object
27+
properties:
28+
goo:
29+
title: "Goo"

0 commit comments

Comments
 (0)