openapi-generator: [BUG] Schema $ref with same name is not producing models properly
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?
- [Optional] Bounty to sponsor the fix (example)
Description
My schema definition are spread across multiple files and they are cross reference(using $ref). In these files there is one schema with same name. I have 5 such instances
When i run code generator, Only 2 models are produced. Rest are ignored. Some of the $ref are pointing to wrong model.
Here is example given below
openapi-generator version
4.0.0-beta
OpenAPI declaration file content or url
https://gist.github.com/vinodchitrali/c5cd3be1c8d6fb0d2fb6bcf6a530ad94
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./api/openapi.yaml -g python -o /tmp/python/ --api-package api --model-package model --additional-properties projectName=python
Steps to reproduce
- Copy the Yaml files from https://gist.github.com/vinodchitrali/c5cd3be1c8d6fb0d2fb6bcf6a530ad94
- java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./api/openapi.yaml -g python -o /tmp/python/ --api-package api --model-package model --additional-properties projectName=python
- Check files generated in /tmp/python/openapi_client/model/
Related issues/PRs
Suggest a fix
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 22 (6 by maintainers)
Commits related to this issue
- Add test case to reproduce the issue https://github.com/OpenAPITools/openapi-generator/issues/2729 — committed to ackintosh/swagger-parser by ackintosh 5 years ago
@jmini , I know and you are doing a great job!. But the specific fix for this issue related to $ref was only released on version 2.0.12.
I could see that the latest released version of your branch is based on version 2.0.11, though…
@jmini , I have already filed issue. https://github.com/swagger-api/swagger-parser/issues/1089
I see some issue in the following code.
https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java#L87
In above code,
possiblyConflictingDefinitionNameremains same through out the loop. IfpossiblyConflictingDefinitionName = "model"then the outcome of the loop is alwaystryName = "model_2". I am hitting same issue.So above code should be
Can some one help me to validate this code ? Also help to build
org.openapitools.swagger.parser(2.0.11-OpenAPITools.org-1)@jmini , I see that u have done recent pom update for 2.0.11. Can check above code and help to build swagger parser for OpenAPI tools