swagger-api / swagger-api/swagger-parser

[Bug]: allOf reference not resolved fully

Open
#2,270 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

Description

Setting resolveFully(true) does not resolve $ref pointers inside allOf schemas. The $ref remains as a pointer.

This is while Parsing OpenAPI 3.0.x specs. In case it's relevant, the allOf I'm trying to parse contains a $ref AND a raw schema as the 2nd element.

Affected Version

  • 2.1.22 (latest)

Steps to Reproduce

Full reproducible example here: https://github.com/julianmclain/swagger-parser-allOf-resolution

Set ParseOptions.setResolve(true) and setResolveFully(true) and parse a spec with a schema using allOf:

String spec = """
    {
      "openapi": "3.0.3",
      "info": { "title": "Test", "version": "1.0" },
      "paths": {},
      "components": {
        "schemas": {
          "SObject": {
            "type": "object",
            "properties": {
              "attributes": { "type": "object" }
            }
          },
          "Contact": {
            "allOf": [
              { "$ref": "#/components/schemas/SObject" },
              {
                "type": "object",
                "properties": {
                  "FirstName": { "type": "string" }
                }
              }
            ]
          }
        }
      }
    }
    """;

ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);

SwaggerParseResult result = new OpenAPIV3Parser().readContents(spec, null, options);
Schema<?> contact = result.getOpenAPI().getComponents().getSchemas().get("Contact");

System.out.println(Json.pretty(contact.getAllOf()));

Expected Behavior

The $ref is resolved to the referenced schema content, i.e.

[ {
  "type" : "object",
  "properties" : {
    "attributes" : {
      "type" : "object"
    }
  }
}, {
  "type" : "object",
  "properties" : {
    "FirstName" : {
      "type" : "string"
    }
  }
} ]

Actual Behavior

The reference to "#/components/schemas/SObject"` is unresolved:

[ {
  "$ref" : "#/components/schemas/SObject"
}, {
  "type" : "object",
  "properties" : {
    "FirstName" : {
      "type" : "string"
    }
  }
} ]

Environment

  • Java version: 21
  • Build tool: Gradle 9.0
  • OS: macOS

Additional Context

There were related issues, but they were marked resolved so I'm not sure if they're relevant: #1157, #1161, #1538

Checklist

  • I have searched the existing issues and this is not a duplicate.
  • I have provided sufficient information for maintainers to reproduce the issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenAPIV3Parser and ParseOptions behavior shown in the issue, then reproduce the case from the linked repository using the provided OpenAPI 3.0.3 document. Trace why resolveFully(true) leaves the $ref inside Contact's allOf unresolved; done means the referenced SObject schema is expanded while the raw second allOf schema remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.