Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absent type doesn't imply type object #2113 #2114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ root = true
# Indentation style
# Possible values - tab, space
indent_style = space
end_of_line = lf

# File character encoding
# Possible values - latin1, utf-8, utf-16be, utf-16le
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,6 @@ public Schema resolveSchema(Schema schema) {
Schema property = updated.get(key);

if (property.getProperties() != model.getProperties()) {
if (!hasSchemaType(property)) {
if (SpecVersion.V30.equals(property.getSpecVersion())) {
property.setType("object");
} else {
property.addType("object");
}
}
model.addProperties(key, property);
} else {
LOGGER.debug("not adding recursive properties, using generic object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,16 @@ public void testIssue1706() {
assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ObjectSchema);
}

@Test
public void testIssue2113() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);

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

@Test
public void selfReferenceTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,62 +165,62 @@ private void tearDownWireMockServer() {
public void test$idUrlExternal() throws Exception {
ParseOptions p = new ParseOptions();
p.setResolve(true);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").getAbsolutePath(), null, p);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-external/root.json").toURI().toASCIIString(), null, p);
compare("$id-uri-external", swaggerParseResult);
}

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

@Test
public void test$idUrlDirect() throws Exception {
ParseOptions p = new ParseOptions();
p.setResolve(true);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").getAbsolutePath(), null, p);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-uri-direct/root.json").toURI().toASCIIString(), null, p);
compare("$id-uri-direct", swaggerParseResult);
}
@Test
public void test$idUrlUnresolvable() throws Exception {
ParseOptions p = new ParseOptions();
p.setResolve(true);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").getAbsolutePath(), null, p);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(new File("src/test/resources/3.1.0/dereference/schema/$id-unresolvable/root.json").toURI().toASCIIString(), null, p);
compare("$id-unresolvable", swaggerParseResult);
}

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

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

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

public void compare(String dir, SwaggerParseResult result) throws Exception {
ObjectMapper mapper = Json31.mapper().copy();
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI());
String actual = mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(result.getOpenAPI()).replace("\r\n", "\n");
org.testng.Assert.assertEquals(actual,
FileUtils.readFileToString(new File("src/test/resources/3.1.0/dereference/schema/" + dir + "/dereferenced.json")));
}
Expand Down
29 changes: 29 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue_2113.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Issue X
servers:
- url: http://petstore.swagger.io/api
paths:
/foo:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
required: true
responses:
200:
description: ok
components:
schemas:
Foo:
type: object
allOf:
- $ref: "#/components/schemas/Goo"
Goo:
type: object
properties:
goo:
title: "Goo"