[BUG][JAVA] Relative references to different directories always followed from the main openapi.yaml
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] What's the version of OpenAPI Generator used?
- [x] Have you search for related issues/PRs?
- [x] 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?).
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
OpenAPI-Generator is relying on Swagger-Parser. If they have an issue (which seems to be the case), then there is nothing we can do.
You need to work on a solution for the issue in the Upstream project, then we can see how to integrate it.
I see. As you can see, I already linked an issue on their side. Thanks anyway!
Could it be that this issue is resolved in Swagger-Parser now (https://github.com/swagger-api/swagger-parser/pull/1343), and updating the pom to refer to swagger-parser-version 2.0.18 would import that fix here.
@jhellingman it looks like swagger-api/swagger-parser#1343 has been merged on March, 20th while 2.0.18 has been released on February, 23rd. Are you sure that that version would include that fix?
Not sure, but in that case we may have to wait for 2.0.19.
Having the same problem myself. Seems like 2.0.19 is out, should that fix this issue if it's added to openapi-generator?
Any update on this? I'm still experiencing this issue with version 5.0.1
5.2.0 same problem :(
Any news on this issue?
Hi, Any news on this topic. I ran into the same problems in 5.4.0. Is there any progress or features planned for this problem ?
Also ran into this issue on 6.0.1 using the java-camel generator.
Hi, Is there some news ? I'm still experienced that in 7.3.0...