swagger-api / swagger-api/swagger-parser

Schema's loaded from other than requested file don't store location

Open
#2,057 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

setResolve(true) tells OpenAPIV3Parser to load specs from external locations and put them in the model.

  ParseOptions parseOptions = new ParseOptions();
  parseOptions.setResolve(true);
  OpenAPI openApiModel = new OpenAPIV3Parser().read(inputFile, null, parseOptions);

It is desirable to distinguish schemas loaded from external locations from the ones defined locally. For example:

  • errors.yaml may define shared error types.
  • api1.yaml and api2.yaml (that reference errors.yaml) may define two different APIs.
    Code generation for errors.yaml should only be done once.

On the other hand, api3.yaml may reference another file.yaml that must be resolved and included in the generated code for api3 unlike errors.yaml.

Proposal: store original reference in $originalRef next to $ref in SchemaProcessor.

This change will let code generators add custom logic for shared vs not schemas.

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 in modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java at the referenced processing logic, then trace how external schema references are resolved into the model. Done means the original external reference is retained next to $ref so consumers can distinguish shared schemas from schemas that should be included.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.