swagger-api / swagger-api/swagger-parser

Swagger 2 Relative path references are not getting resolved

Open
#1,206 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

While using java Swagger2 parser, the relative references are not getting resolved, if the references are in some other folder.

Is there a way to define what should be the root path from where the references should be resolved.

Eg. If a file located in https://example.com/content/test/api/swagger/test.yaml has a reference, $ref: '../some-other-folder/message.yaml#/definitions/MessageArray'

and the file is located in https://example.com/content/test/api/some-other-folder/message.yaml

the parser is not able to resolve the relative path and throws the error.

Is there a way to resolve a relative path with a given base path, eg user could provide an option to always resolve the relative paths using https://example.com/content/test/api/ and the content of relative path is appended to the give url, thus forming the location https://example.com/content/test/api/some-other-folder/message.yaml ?

This works in OpenAPIV3Parser.

Thanks

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

The issue names no files or tests. Start by locating the Java Swagger 2 parser's relative-reference resolution entry point and compare it with OpenAPIV3Parser; verify completion with a regression case covering a sibling-folder $ref and a supplied base URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
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.