swagger-api / swagger-api/swagger-codegen

Incorrect handling of external references?

Open
#8,389 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I have an OpenAPI 3.0 API file that references external JSON schemas, as seen below:

  /voterReg:
    post:
      externalDocs:
        description: NIST VRI Documentation
        url: https://pages.nist.gov/VoterRecordsInterchange/
      operationId: VoterRegPost
      requestBody:
        description: A VRI Records Request object
        required: true
        content:
          'application/json':
            schema: 
              $ref: "../NIST_VRI_voter_records_interchange.json#/definitions/VRI.VoterRecordsRequest"

This external schema is dereferenced correctly. However, NIST_voter_records_interchange.json references an external schema as well, addr.json, which is not.

	"$ref": "addr.json#/definitions/addr.GeneralAddressClass_type"

For some reason, swagger-codegen expects a file that is the concatenation of the two:

java.lang.RuntimeException: Could not find ../schemas/NIST_VRI_voter_records_interchange.jsonaddr.json on the classpath
        at io.swagger.v3.parser.util.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:31)
        at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:153)
        at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:116)
        at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:47)
(snipped)
Swagger-codegen version

3.0.0-SNAPSHOT

Swagger declaration file content or url

See gist

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i vri.yaml -l php -o ./

Steps to reproduce

Occurs with any language target

Related issues/PRs
Suggest a fix/enhancement

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

Reproduce the nested-reference case from the linked gist with the Java CLI command, then trace the reported path through RefUtils.readExternalRef, ResolverCache.loadRef, and ExternalRefProcessor.processRefToExternalSchema. Done means an external schema referenced from another external schema resolves as its own file instead of producing a concatenated path error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.