OpenAPITools / OpenAPITools/openapi-generator
[BUG] Schema $ref with same name is not producing models properly
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?
- [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
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 OpenAPI files in the linked Gist and reproduce the issue using the documented Java CLI command with the Python generator. Inspect how the generator resolves cross-file $ref entries and writes models under /tmp/python/openapi_client/model/. Done means all same-named schemas are handled without references pointing to the wrong model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100