swagger-api / swagger-api/swagger-parser

swagger-parser not resolving file references

Open
#963 1 comment 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

Dependencies:

161       <dependency>
162         <groupId>io.swagger</groupId>
163         <artifactId>swagger-compat-spec-parser</artifactId>
164         <version>1.0.40</version>
165       </dependency>
166       <dependency>
167         <groupId>io.swagger</groupId>
168         <artifactId>swagger-models</artifactId>
169         <version>1.5.21</version>
170       </dependency>
171       <dependency>
172         <groupId>io.swagger</groupId>
173         <artifactId>swagger-parser</artifactId>
174         <version>1.0.40</version>
175       </dependency>

Excerpt from main.yaml yaml spec:

definitions:
  $ref: './definitions.yaml'

definitions.yaml is in the same directory as main.yaml and looks like:

ErrorResponse:
  type: object
  required:
    - code
    - message
  properties:
    code:
      description: The HTTP error status code
      type: integer
      format: int32
    message:
      description: The reason for the error
      type: string
    fields:
      description: An array of strings for specific reasons for the error
      type: array
      items:
        type: string

I have some simple code that parses the spec and the messages indicates my definitions ref is not good and the swagger object has no definitions:

319             SwaggerDeserializationResult dsr = new SwaggerParser().readWithInfo(path, null, true);
320             
321             dsr.getMessages().forEach(e -> LOG.info("Message: " + e));
322             spec = dsr.getSwagger();
323             spec.getPaths().forEach((k,v) -> LOG.info("Key: " + k + " and Value: " + v));
324             spec.getDefinitions().forEach((k,v) -> LOG.info("Key: " + k + " and Value: " + v));

Messages:

[INFO] Message: attribute definitions.$ref is not of type `object`

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 main.yaml and definitions.yaml examples, then inspect the readWithInfo(path, null, true) call and its reported message. Trace how the parser handles the definitions.$ref entry and compare the resulting Swagger definitions with the referenced file. Done means the local file reference resolves without the type message and the definitions are available on the parsed Swagger object.

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
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.