OpenAPITools / OpenAPITools/openapi-generator
[BUG] Enum not generated properly, if there is a class + property with the same name
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
openapi-generator version
6.2.1, don't know whether it is a regression. I am a new user.
OpenAPI declaration file content or url
Gist: https://gist.github.com/felixscheinost/dfdd51e75f665e676d79b70f9acea7e4
Generation Details
yarn init
yarn add -D @openapitools/openapi-generator-cli
yarn run openapi-generator-cli generate -i swagger-bug.json -g kotlin -o /tmp/test
Steps to reproduce
-
Generate using above steps.
-
ApiErrorGroup.ktis NOT a enum, as it should be. is an empty data class instead.
Changes to schema which change the bug:
-
Renaming
ApiError#group=>ApiError#group2, in this case a empty data classApiErrorGroup2is created, which also won't compile. But the enumApiErrorGroupis generated correctly. -
Removing the unnecessary
oneOf. Yeah, theoneOfis unnecessary here but the schema is generated by another party which we don't have control over. It should also be valid so valid code should be generated regardless.
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 by reproducing the issue with the provided gist and the openapi-generator-cli Kotlin command. Inspect the generated ApiErrorGroup.kt and the related ApiError and enum output; done means the class/property name collision produces a valid enum and compiling generated Kotlin code, including with the unnecessary oneOf present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100