Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not find $ref in nested directory #1292

Open
iamchating opened this issue Jan 6, 2020 · 3 comments
Open

Can not find $ref in nested directory #1292

iamchating opened this issue Jan 6, 2020 · 3 comments

Comments

@iamchating
Copy link

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

@iamchating iamchating changed the title Can not find $ref in a sub directory Can not find $ref in nested directory Jan 6, 2020
@iamchating
Copy link
Author

The same issue as #1223, but in the v2 branch, the implementation is totally different and can not be easily fixed. I have looked into the code and maybe a major change is needed.

@gracekarina
Copy link
Contributor

Hi @iamchating, thanks for reporting this issue, the PR above was merge with a fix, please let me know it goes!.

@etteeee
Copy link

etteeee commented Nov 23, 2021

Hi @iamchating, thanks for reporting this issue, the PR above was merge with a fix, please let me know it goes!.

the PR only fixed v3 branch, what about v2 branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants