swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Can not find $ref in nested directory

Open iamchating opened this issue 4 years ago • 3 comments

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 avatar Jan 06 '20 04:01 iamchating

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.

iamchating avatar Jan 06 '20 07:01 iamchating

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

gracekarina avatar Mar 20 '20 01:03 gracekarina

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?

etteeee avatar Nov 23 '21 07:11 etteeee