swagger-api / swagger-api/swagger-parser
Can not find $ref in nested directory
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Version: 2.0.16
The yaml project is in a structure as follows
petstore.yml at root
and pet.yml and def.yml in a sub directory named /pet
and pet.yml $ref an object definition in def.yml
the redoc parses the project correctly, but swagger-parser gives an error
java.lang.RuntimeException: Unable to load RELATIVE ref: ./def.yml path: /private/tmp/yaml
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.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:56)
at io.swagger.v3.parser.processors.SchemaProcessor.processReferenceSchema(SchemaProcessor.java:202)
at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:37)
at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:52)
at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:67)
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:66)
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 ./def.yml 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)
It seems that the swagger-parser assumes that all the yaml files are in the flattened root directory (classpath), but in this case, the pets.yml is in ./pet dir and $ref def.yml also in ./pet
The test case file is attached as below
yaml.zip
Contributor 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
Start with the attached yaml.zip reproduction and trace relative-reference loading through RefUtils.java, ResolverCache.java, and ExternalRefProcessor.java. Run the parser against the root petstore.yml and verify that the nested pet.yml reference to ./def.yml resolves successfully without the reported classpath error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100