question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative $refs aren't relative to the file in which they are declared.

See original GitHub issue

Description

Relative $ref declarations don’t resolve relative to their containing file.

For example

main.yaml
  - models
    - model1.yaml
  - common
    - shared.yaml

Assume a reference in model1.yaml like $ref: '../common/shared.yaml#/definitions/MyObj'

This will fail via an Unable to load RELATIVE ref: ... error (via the codegen).

The ResolverCache resolves these references relative to a parentDirectory file that is final:

https://github.com/swagger-api/swagger-parser/blob/64a5ea7402183fc4cd8a1b58602045952311e0da/modules/swagger-parser/src/main/java/io/swagger/parser/ResolverCache.java#L113

Wouldn’t the parentDirectory need to be variable - i.e., be set to the directory containing the file where the $ref is declared?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
CluEleSsUKcommented, May 21, 2019

I’m experiencing this same issue with version 2.3.1, but neitherupgrading the swagger parser to 1.0.34 nor 1.0.35-SNAPSHOT fixes it for me, however 1.0.44 does! Sorry to necro this, but might be useful to others

1reaction
sottycommented, Apr 16, 2018

I could use 1.0.34 to parse a graph of mutually referencing models successfully Kevin took it one step further with the code generation, but had to use 1.0.35-SNAPSHOT

We did not have the time to isolate which commit(s) did fix the problem

Thanks for your assistance!

On Mon, Apr 16, 2018 at 2:43 PM, Kevin Peterson notifications@github.com wrote:

I used 1.0.35-SNAPSHOT and that seemed to take care of the problem. Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/swagger-api/swagger-parser/issues/671#issuecomment-381725153, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0OnIb-WPxegf3xoLcrrk7yp2VdgXBks5tpPRFgaJpZM4TFt5S .

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript can't resolve non-relative path in import
I 'm fairly certain (based on the solution that worked for me) that TypeScript treats it as an absolute path from the 'compilerOptions.baseUrl'...
Read more >
Using Relative URIs
What the Relative URI Pattern gives you then, is the ability for you system to work with different base addresses without being modified....
Read more >
FDOT 'Save Relative Path' for references and any changes ...
My understanding is both usages of 'relative path' are not referring to 'save ... Relative Path is the only way to see the...
Read more >
Using relative paths for Windows shortcuts - Super User
You can use this utility: Relative. It basically creates a shortcut to "explorer.exe" with the parameter of your relative path with a right...
Read more >
Documentation - Module Resolution - TypeScript
A relative import is resolved relative to the importing file and cannot resolve to an ambient module declaration. You should use relative imports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found