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 @@ -133,6 +133,19 @@ public void resolveFully(OpenAPI openAPI) {
resolvePath(pathItem);
}
}

// Resolve component schemas that are not reachable through any path, so that
// e.g. a $ref inside an allOf of an otherwise-unreferenced component schema is
// still fully resolved. resolveSchema caches its results, so component schemas
// already resolved while walking the paths are returned as-is (no double resolution).
if (schemas != null) {
for (String schemaName : new ArrayList<>(schemas.keySet())) {
Schema resolved = resolveSchema(schemas.get(schemaName));
if (resolved != null) {
schemas.put(schemaName, resolved);
}
}
}
}

public void resolvePath(PathItem pathItem){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.swagger.v3.parser.test;

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class Issue2270Test {

@Test
public void shouldResolveRefInsideAllOfOfUnreferencedComponentSchema() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
// Keep the allOf structure so we can assert the inner $ref itself was resolved.
options.setResolveCombinators(false);

SwaggerParseResult result = new OpenAPIV3Parser().readLocation("issue-2270/openapi.yaml", null, options);

assertNotNull(result.getOpenAPI());
Schema<?> contact = result.getOpenAPI().getComponents().getSchemas().get("Contact");
assertNotNull(contact);

List<Schema> allOf = contact.getAllOf();
assertNotNull(allOf);

// The first allOf member is a $ref to SObject and, although Contact is not reachable
// through any path, resolveFully(true) must still resolve it: the $ref must be gone
// and the referenced schema's properties must be inlined.
Schema<?> firstMember = allOf.get(0);
assertNull("$ref inside allOf of an unreferenced component schema was not resolved",
firstMember.get$ref());
assertNotNull(firstMember.getProperties());
assertTrue(firstMember.getProperties().containsKey("id"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.1
info:
title: issue-2270
version: 1.0.0
paths: {}
components:
schemas:
SObject:
type: object
properties:
id:
type: string
Contact:
allOf:
- $ref: '#/components/schemas/SObject'
- type: object
properties:
name:
type: string