Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,7 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
}
}

} else {
} else if (result.isInferSchemaType()) {
// may have an enum where type can be inferred
JsonNode enumNode = node.get("enum");
if (enumNode != null && enumNode.isArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,59 @@ public void test31Issue1821() {
assertEquals(id.getTypes().iterator().next(), "string");
}

@Test(description = "Test Issue 1964 with inferSchemaType disabled")
public void test31Issue1964InferSchemaTypeDisabled() {
ParseOptions options = new ParseOptions();
options.setInferSchemaType(false);

String yaml = "openapi: 3.1.0\n" +
"info:\n" +
" version: 1.0.0\n" +
" title: Example\n" +
"paths:\n" +
" /somePath:\n" +
" get:\n" +
" operationId: getSomePath\n" +
" responses:\n" +
" '200':\n" +
" description: OK\n" +
" content:\n" +
" application/json:\n" +
" schema: {}\n" +
"components:\n" +
" schemas:\n" +
" ArrayContainsValue:\n" +
" type: array\n" +
" contains:\n" +
" enum:\n" +
" - 1\n" +
" AdditionalpropertiesBeingFalseDoesNotAllowOtherProperties:\n" +
" $schema: https://json-schema.org/draft/2020-12/schema\n" +
" properties:\n" +
" foo: {}\n" +
" bar: {}\n" +
" patternProperties:\n" +
" ^v: {}\n" +
" additionalProperties: false\n";

SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, options);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);
assertTrue(result.getMessages().isEmpty(), String.valueOf(result.getMessages()));

Schema arrayContainsValue = openAPI.getComponents().getSchemas().get("ArrayContainsValue");
assertNotNull(arrayContainsValue.getContains());
assertNull(arrayContainsValue.getContains().getType());
assertNull(arrayContainsValue.getContains().getTypes());

Schema objectWithoutExplicitType = openAPI.getComponents().getSchemas()
.get("AdditionalpropertiesBeingFalseDoesNotAllowOtherProperties");
assertTrue(objectWithoutExplicitType.getAdditionalProperties() instanceof Schema);
assertFalse(((Schema) objectWithoutExplicitType.getAdditionalProperties()).getBooleanSchemaValue());
assertNull(objectWithoutExplicitType.getType());
assertNull(objectWithoutExplicitType.getTypes());
}

@Test(description = "Test safe resolving")
public void test31SafeURLResolving() {
ParseOptions parseOptions = new ParseOptions();
Expand Down