OpenAPITools / OpenAPITools/openapi-generator
[BUG] generator cannot handle cross referenced schema $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)?
-
What's the version of OpenAPI Generator used?
-
Have you search for related issues/PRs?
-
What's the actual output vs expected output?
there should be no warning/error like this
o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Pet'.Please make sure that your schema is correct!
see more detail below.
- [Optional] Bounty to sponsor the fix (example)
Description
the repro is in the https://github.com/dyno/openapi-ref-issue
cross referenced schema reports error in code generator, (make generate-client)
but shows no problem in swagger-ui-watcher.
openapi-generator version
docker run openapitools/openapi-generator-cli --version
openapi-generator-cli 5.0.0-SNAPSHOT
commit : 0cb4c43
built : 2020-08-04T04:27:51Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
https://github.com/dyno/openapi-ref-issue
https://github.com/dyno/openapi-ref-issue/blob/master/openapi.yaml
openapi.yaml
schemas/
├── Cat.yaml
├── Dog.yaml
└── Pet.yaml
Generation Details
make generate-client
Steps to reproduce
as above.
[main] INFO o.o.c.languages.AbstractJavaCodegen - Invoker Package Name, originally not set, is now derived from api package name: openapi.internal
[main] INFO o.o.c.languages.AbstractJavaCodegen - Processing operation null
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./schemas/Pet.yaml#/Pet
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Pet'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:475)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:850)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
at org.openapitools.codegen.DefaultCodegen.getAllOfDescendants(DefaultCodegen.java:2817)
at org.openapitools.codegen.DefaultCodegen.createDiscriminator(DefaultCodegen.java:2871)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:2232)
at org.openapitools.codegen.languages.AbstractJavaCodegen.fromModel(AbstractJavaCodegen.java:1018)
at org.openapitools.codegen.languages.JavaClientCodegen.fromModel(JavaClientCodegen.java:717)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1127)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:470)
... 4 more
Related issues/PRs
Suggest a fix
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
Start with the dyno/openapi-ref-issue reproduction, especially openapi.yaml and the schemas/Pet.yaml, Cat.yaml, and Dog.yaml files, then run make generate-client. Trace the warning in ModelUtils and the failure through DefaultCodegen.getAllOfDescendants and DefaultGenerator.generateModels. Done means the cross-referenced schemas generate successfully without the reported warning or exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100