OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Regression "-Unable to load RELATIVE ref:"
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
This is a regression of the bug described here: https://github.com/swagger-api/swagger-parser/issues/505
Its working in 5.0.0 but is broken in 5.0.1 and also in the latest version 5.2.1
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./openapi/model.yaml#/components/responses/FooResponse
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: 17
Errors:
-Unable to load RELATIVE ref: openapi/openapi/model.yaml path: /home/$user/$project
Warnings:
-Unable to load RELATIVE ref: openapi/openapi/model.yaml path: /home/$user/$project
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:541)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:568)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:424)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
├── openapi
│ ├── model.yaml
└── openapi.yaml
...
$ref: ./openapi/model.yaml#/components/parameters/XXX
...
openapi-generator version
Broken versions probably everything > 5.0.0
I tested:
- 5.0.0 (working)
- 5.0.1 (not working)
- 5.2.1 (not working)
Generation Details
npx openapi-generator-cli generate \
-i openapi.yaml \
-g typescript-axios \
-o ${OUTDIR} \
--additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true
Related issues/PRs
Here are all pull-requests between 5.0.0 and 5.0.1
https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Amerged+is%3Apr+milestone%3A5.0.1++
Suggest a fix
It could temporary be fixed by dereferencing everything into a single file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the regression with openapi.yaml, openapi/model.yaml, and the provided npx openapi-generator-cli command, comparing 5.0.0 with later versions. Start at CodegenConfigurator.java and the ModelUtils warning shown in the stack trace, then trace relative-reference loading. Done means the supplied relative $ref works again without the Unable to load RELATIVE ref error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100