Parser does not resolve $ref pointing to relative locations on classpath
See original GitHub issueWhen 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:
- PathUtils fails to correctly identify the parent directory of schema files looked up on the classpath
- 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks to all involved in this one - our issue has been resolved with 2.0.14.
Hi @ChubbyArse, yes, in release version all dependencies will be set to release version