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.

Parser does not resolve $ref pointing to relative locations on classpath

See original GitHub issue

When parsing a schema file loaded from the classpath (either on file or in jar), the parser does not correctly resolve $ref elements pointing to other json or yaml files in relative path locations.

For example,

src/main/resources/
    |- schema/
        |- schema.yaml
        |- import/
            |- data_structures.yaml

schema.yaml

openapi: 3.0.2
info:
  title: Schema in sub-path
  version: 1-0
  description: 
paths:
  /test:
    post:
      operationId: doStuff
      requestBody:
        content:
          application/json:
            schema:
              $ref: 'import/data-structures.yaml#/Foo
      responses:
        '200':
          description: Successful result
          content:
            application/json:
              schema:
                $ref: 'import/data-structures.yaml#/Foo

data-structures.yaml

Foo:
  type: object
  (etc)

The parser should be able to resolve this relative $ref path when loading from the classpath, however it gives the following error message:

Unable to load RELATIVE ref: ./import/data-structures.yaml path: C:\schema

In debugging I observed two problems occurring:

  1. PathUtils fails to correctly identify the parent directory of schema files looked up on the classpath
  2. schema files located in jar files do not resolve to a parent directory, so ResolverCache needs an alternative way to read relative $ref elements from the classpath.

Attached is a test case demonstrating these issues ( as a zipped up maven build), a unified diff to fix the issues, and a test case fix

swagger-parser-bug-test.zip

swagger-parser-unified-diff.txt

PathUtilTest.java.txt

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ChubbyArsecommented, Aug 29, 2019

Thanks to all involved in this one - our issue has been resolved with 2.0.14.

0reactions
gracekarinacommented, Aug 19, 2019

Hi @ChubbyArse, yes, in release version all dependencies will be set to release version

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative $refs not being loaded when running as a jar?
It looks like the relative path resolution is looking for the referenced paths on the jar's path, not being discovered from inside the...
Read more >
How to really read text file from classpath in Java
From ClassLoader, all paths are "absolute" already - there's no context // from which they could be relative. Therefore you don't need a...
Read more >
Path | Android Developers
Same as cubicTo, but the coordinates are considered relative to the current point on this contour. If there is no previous point, then...
Read more >
Core Features - Spring
This section dives into the details of Spring Boot. Here you can learn about the key features that you may want to use...
Read more >
XMLCatalog Type - Apache Ant
The catalog entries are used both for Entity resolution and URI ... Create an <xmlcatalog> with a <dtd> element whose location attribute points...
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