OpenAPITools / OpenAPITools/openapi-generator
[BUG] Wrong generation when using a prefix under a specific circumstance
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have detected an issue when using a prefix and at the same time the OAS is using that same prefix for the name of some components. For example, If I am using a prefix myprefix and one component has the next name myprefix_Component, the models gets wrongly generated on the import paths.
In our case it is happening because the backend has two types with the same name and OAS is adding a prefix to differentiate them.
openapi-generator version
I am using 4.3.1, I have tried also moving to 5.1.0 and also using the latest version as suggested on the above instructions.
OpenAPI declaration file content or url
I have created a OAS file that can reproduce the issue using a vegetables example.
https://gist.github.com/PabloFNK/a4179cad463e54bc050b813ceb60ad95#file-test-json
Generation Details
I have added on the same Gist all the relevant files. You can see here the command I am using to generate: https://gist.github.com/PabloFNK/a4179cad463e54bc050b813ceb60ad95#file-generate-types-sh
Steps to reproduce
Just execute the above generation details using the OAS spec test.json to reproduce the results specified on that Gist. As you can see in there that prefixVegetables.ts is importing ./vegetable.ts when it should be ./prefixVegetable.ts.
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
Run the generation command from generate-types.sh with the linked test.json specification and compare prefixVegetables.ts with the expected prefixVegetable.ts import. Trace the TypeScript generator's model naming and import-path handling; done means the generated import uses the prefixed model without breaking other component names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100