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 @@ -529,7 +529,11 @@ private Schema resolveSchemaImpl(Schema schema) {
for (String key : updated.keySet()) {
Schema property = updated.get(key);

if (property.getProperties() != model.getProperties()) {
if (schemasInProgress.contains(property) || property.getProperties() == model.getProperties()) {
LOGGER.debug("not adding recursive properties, using generic object");
ObjectSchema newSchema = new ObjectSchema();
model.addProperties(key, newSchema);
} else {
if (!hasSchemaType(property) && parseOptions.isExplicitObjectSchema()) {
if (SpecVersion.V30.equals(property.getSpecVersion())) {
property.setType("object");
Expand All @@ -538,10 +542,6 @@ private Schema resolveSchemaImpl(Schema schema) {
}
}
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
Expand Up @@ -1492,6 +1492,28 @@ public void recursiveResolvingIssue1751RecursiveArrayItems() {
}
}

@Test
public void recursiveResolvingAllOfSelfRecursionOas31() {
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("issue_2297_allof_self_recursion.yaml", null, parseOptions);
assertNotNull(openAPI, "OpenAPI should be parsed successfully");
assertNotNull(openAPI.getComponents(), "Components should not be null");
Schema node = openAPI.getComponents().getSchemas().get("Node");
assertNotNull(node, "Node schema should be present");
assertNotNull(node.getProperties(), "Node should have properties");
assertNotNull(node.getProperties().get("child"),
"Node should contain the self-referencing property");
try {
String serialized = Json.mapper().writeValueAsString(openAPI);
assertNotNull(serialized, "Serialized output should not be null");
}
catch (Exception e) {
fail("Recursive loop found for self-reference combined with allOf: " + e.getMessage());
}
}

@Test
public void recursiveIssue984() {
ParseOptions parseOptions = new ParseOptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.1.0
info:
title: allOf self recursion regression
version: 1.0.0
paths:
/node:
get:
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
components:
schemas:
Node:
type: object
allOf:
- type: object
properties:
value:
type: number
properties:
child:
$ref: '#/components/schemas/Node'