Skip to content

Commit ffb3a78

Browse files
committed
fix ResolverFully for schema without type
Fixes #1433
1 parent 5f6732e commit ffb3a78

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,15 @@ public Schema resolveSchema(Schema schema) {
395395
for (String key : updated.keySet()) {
396396
Schema property = updated.get(key);
397397

398-
if(property instanceof ObjectSchema) {
399-
ObjectSchema op = (ObjectSchema) property;
400-
if (op.getProperties() != model.getProperties()) {
401-
if (property.getType() == null) {
402-
property.setType("object");
403-
}
404-
model.addProperties(key, property);
405-
} else {
406-
LOGGER.debug("not adding recursive properties, using generic object");
407-
ObjectSchema newSchema = new ObjectSchema();
408-
model.addProperties(key, newSchema);
398+
if (property.getProperties() != model.getProperties()) {
399+
if (property.getType() == null) {
400+
property.setType("object");
409401
}
402+
model.addProperties(key, property);
403+
} else {
404+
LOGGER.debug("not adding recursive properties, using generic object");
405+
ObjectSchema newSchema = new ObjectSchema();
406+
model.addProperties(key, newSchema);
410407
}
411408

412409
}

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.swagger.parser;
22

3-
import io.swagger.util.Yaml;
43
import io.swagger.v3.oas.models.Components;
54
import io.swagger.v3.oas.models.OpenAPI;
65
import io.swagger.v3.oas.models.media.ArraySchema;
76
import io.swagger.v3.oas.models.media.ObjectSchema;
87
import io.swagger.v3.oas.models.media.Schema;
98
import io.swagger.v3.oas.models.PathItem;
109

10+
import io.swagger.v3.oas.models.media.StringSchema;
1111
import io.swagger.v3.oas.models.parameters.Parameter;
1212
import io.swagger.v3.oas.models.parameters.RequestBody;
1313

@@ -561,6 +561,32 @@ public void testIssue1086() {
561561
Schema score = schema.getProperties().get("score");
562562
assertEquals(score.getMultipleOf().intValue(), 1);
563563
}
564-
564+
565+
@Test
566+
public void testIssue1433_ResolveSchemaWithoutType() {
567+
OpenAPIParser openApiParser = new OpenAPIParser();
568+
ParseOptions options = new ParseOptions();
569+
options.setResolveFully(true);
570+
571+
OpenAPI openAPI = openApiParser.readLocation("issue_1433-resolve-schema-without-type.yaml", null, options).getOpenAPI();
572+
final Schema requestBodySchema = openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema();
573+
assertNotNull(requestBodySchema);
574+
575+
final Map properties = requestBodySchema.getProperties();
576+
assertEquals(properties.size(), 2);
577+
578+
final Object bar = properties.get("bar");
579+
assertEquals(bar.getClass(), StringSchema.class);
580+
581+
final Object input = properties.get("input");
582+
assertEquals(input.getClass(), Schema.class);
583+
584+
final Map inputProperties = ((Schema) input).getProperties();
585+
assertNotNull(inputProperties);
586+
assertEquals(inputProperties.size(),1);
587+
588+
final Object baz = inputProperties.get("baz");
589+
assertEquals(baz.getClass(), StringSchema.class);
590+
}
565591
}
566592

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
openapi: 3.0.0
2+
info:
3+
title: no type resolution
4+
version: 1.0.0
5+
paths:
6+
/foo:
7+
post:
8+
requestBody:
9+
required: true
10+
content:
11+
application/json:
12+
schema:
13+
$ref: '#/components/schemas/FooInput'
14+
responses:
15+
'200':
16+
description: subscription successfully created
17+
components:
18+
schemas:
19+
FooInput:
20+
properties:
21+
bar:
22+
type: string
23+
input:
24+
$ref: '#/components/schemas/BazInput'
25+
BazInput:
26+
properties:
27+
baz:
28+
type: string

0 commit comments

Comments
 (0)