Skip to content

[Bug]: Ref resolution gets confused #2213

@jimshowalter

Description

@jimshowalter

Description

Ref resolution gets confused.

Affected Version

2.1.30

We have no idea when this showed up, because we only started using swagger-parser a few weeks ago. The code generator we were using previously didn't have this problem.

Steps to Reproduce

Unzip the attached schema.

Compile this and run it in a debugger:

public class RefBug {

  public static void main(String[] args) {
    File apiJson = new File(<fill this in with a path to the api.json file from the unzipped zip>);
    ParseOptions parseOptions = new ParseOptions();
    parseOptions.setResolveResponses(true);
    parseOptions.setValidateExternalRefs(true);
    parseOptions.setResolveFully(true);
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readLocation(apiJson.getAbsolutePath(), null, parseOptions);
    for (String error : result.getMessages()) {
      System.out.println(apiJson + ": " + error); // <<< Stop here in a debugger.
    }
  }
}

You will get an error about "Could not find /ref-bug/schemas/v2/m1/models/models/task.json on the classpath

The models/models isn't correct.

Also, there's a warning about task.json when the schema is viewed in IntelliJ. See screenshot.

Expected Behavior

It should resolve the file.

Actual Behavior

It can't find the file.

Environment

Java 21

Gradle 8.14.3

MacOS Sequoia 15.5 and RedHat RHEL 9.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions