Skip to content

Can not find $ref in nested directory  #1292

@iamchating

Description

@iamchating

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions