Skip to content

Commit

Permalink
fix ResolverFully for schema without type
Browse files Browse the repository at this point in the history
Fixes #1433
  • Loading branch information
phiz71 committed Sep 30, 2020
1 parent 5f6732e commit 66436ff
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,15 @@ public Schema resolveSchema(Schema schema) {
for (String key : updated.keySet()) {
Schema property = updated.get(key);

if(property instanceof ObjectSchema) {
ObjectSchema op = (ObjectSchema) property;
if (op.getProperties() != model.getProperties()) {
if (property.getType() == null) {
property.setType("object");
}
model.addProperties(key, property);
} else {
LOGGER.debug("not adding recursive properties, using generic object");
ObjectSchema newSchema = new ObjectSchema();
model.addProperties(key, newSchema);
if (property.getProperties() != model.getProperties()) {
if (property.getType() == null) {
property.setType("object");
}
model.addProperties(key, property);
} else {
LOGGER.debug("not adding recursive properties, using generic object");
ObjectSchema newSchema = new ObjectSchema();
model.addProperties(key, newSchema);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.swagger.parser;

import io.swagger.util.Yaml;
import io.swagger.models.properties.Property;
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.PathItem;

import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;

Expand Down Expand Up @@ -561,6 +563,32 @@ public void testIssue1086() {
Schema score = schema.getProperties().get("score");
assertEquals(score.getMultipleOf().intValue(), 1);
}


@Test
public void testIssue1433_ResolveSchemaWithoutType() {
OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolveFully(true);

OpenAPI openAPI = openApiParser.readLocation("issue_1433-resolve-schema-without-type.yaml", null, options).getOpenAPI();
final Schema requestBodySchema = openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema();
assertNotNull(requestBodySchema);

final Map properties = requestBodySchema.getProperties();
assertEquals(2, properties.size());

final Object bar = properties.get("bar");
assertEquals(StringSchema.class, bar.getClass());

final Object input = properties.get("input");
assertEquals(Schema.class, input.getClass());

final Map inputProperties = ((Schema) input).getProperties();
assertNotNull(inputProperties);
assertEquals(1, inputProperties.size());

final Object baz = inputProperties.get("baz");
assertEquals(StringSchema.class, baz.getClass());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.0
info:
title: no type resolution
version: 1.0.0
paths:
/foo:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/FooInput'
responses:
'200':
description: subscription successfully created
components:
schemas:
FooInput:
properties:
bar:
type: string
input:
$ref: '#/components/schemas/BazInput'
BazInput:
properties:
baz:
type: string

0 comments on commit 66436ff

Please sign in to comment.