[BUG][JAVA] Relative references to different directories always followed from the main openapi.yaml
Created by: lorthirk
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
I have a spec with multiple references to external files and directories. It looks like that all the
references are treated as relative to the main openapi.yaml
instead of being treated as related to the actual file who holds the reference
openapi-generator version
4.1.1 (installed from Brew)
OpenAPI declaration file content or url
https://github.com/lorthirk/kapua-openapi
Command line used for generation
openapi-generator generate -c openapi-generator.config.json -i openapi.yaml -g java
content of openapi-generator.config.json:
{
"invokerPackage": "org.eclipse.kapua.app.rest.client",
"apiPackage": "org.eclipse.kapua.app.rest.client.api",
"modelPackage": "org.eclipse.kapua.app.rest.client.model",
"groupId": "org.eclipse.kapua",
"artifactId": "kapua-rest-client-java",
"library": "jersey2",
"dateLibrary": "java8"
}
Steps to reproduce
launch openapi-generator
as described above
Command output:
[main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while reading:
java.lang.RuntimeException: Unable to load RELATIVE ref: ./accessInfo.yaml path: /Users/claudio.mezzasalma/dev/git/lorthirk/kapua-openapi
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:400)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:448)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:399)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.RuntimeException: Could not find ./accessInfo.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)
... 14 common frames omitted
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoListResult
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoListResult
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ../openapi.yaml#/components/responses/subjectUnauthorized
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ../openapi.yaml#/components/responses/kapuaError
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ../openapi.yaml#/components/parameters/scopeId
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoCreator
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoCreator
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoListResult
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./accessInfo.yaml#/components/schemas/accessInfoListResult
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ../openapi.yaml#/components/responses/subjectUnauthorized
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ../openapi.yaml#/components/responses/kapuaError
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 1, Warning count: 10
Errors:
-Unable to load RELATIVE ref: ./accessInfo.yaml path: /Users/claudio.mezzasalma/dev/git/lorthirk/kapua-openapi
Warnings:
-Unable to load RELATIVE ref: ./accessInfo.yaml path: /Users/claudio.mezzasalma/dev/git/lorthirk/kapua-openapi
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:419)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:448)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:399)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Related issues/PRs
#2412 seems similar swagger-api/swagger-parser#1074
Suggest a fix
I guess the references should always be resolved starting from the file who holds the $ref
... Unfortunately I don't know exactly where in the code the references are resolved (in swagger-parser
maybe?).