swagger-api / swagger-api/swagger-parser
$ref path broken.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
My file structure:
docs
openapi.yaml
paths
activity
activity.yaml
Inside the activity.yaml, I have this as a reference but it doesn't work:
$ref: '../../openapi.yaml#/components/parameters/Fields'
In contrast, this does actually work:
$ref: '../openapi.yaml#/components/parameters/Fields'
or
$ref: 'openapi.yaml#/components/parameters/Fields'
Which doesn't make any sense.
Here is the error I get when using $ref: '../../openapi.yaml#/components/parameters/Fields:
Error
[main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while reading: java.lang.RuntimeException: Unable to load RELATIVE ref: ../../openapi.yaml path: C:\Users\nitwe\Documents\Programmieren\Directus\SDK-Generator at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:239) at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:119) at io.swagger.v3.parser.processors.ParameterProcessor.processParameters(ParameterProcessor.java:86) at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:39) at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:83) at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49) at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:67) at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16) at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:452) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:498) at org.openapitools.codegen.cmd.Generate.run(Generate.java:415) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61) Caused by: java.lang.RuntimeException: Could not find ../../openapi.yaml on the classpath at io.swagger.v3.parser.util.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:31) at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:233) ... 11 common frames omittedContributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied docs/paths/activity/activity.yaml layout and the failing ../../openapi.yaml reference. Start in io.swagger.v3.parser.util.RefUtils.readExternalRef and follow ResolverCache.loadRef and ClasspathHelper.loadFileFromClasspath to determine how the base path is chosen. Done means the relative reference resolves correctly without breaking the working reference forms, with regression coverage added where the parser tests this behavior.
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
- 30/100