OpenAPITools / OpenAPITools/openapi-generator
Support for enum variable incase of reusable enum class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When an enum is defined as schema it generates new model which can be reused. But when the variable of this class is defined at other places they are treated as nonprimitivetype and isEnum is false hence they can't be handled as enum variables.
openapi-generator version
openapi-generator v3.3.3
OpenAPI declaration file content or url
test yaml spec:
https://hastebin.com/ibororudof.bash
Command line used for generation
java -DskipFormModel=true -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate
-i modules/openapi-generator/src/test/resources/3_0/pet_oas3.yaml
-l c -o out/oas3debug
Steps to reproduce
Generate client for C/C++/Python/Java has same result on each generator.
Related issues/PRs
Suggest a fix/enhancement
I tried playing around a bit, I was able to get around it but not sure if it was the correct way.
In DefaultCodegen.java, I added extra variable allDefinitions to addVars function. In main addVars function I check if $ref and if present then if getEnum is not null then i set isEnum to true.
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 linked test YAML and the generation command, then inspect DefaultCodegen.java, especially addVars and its handling of $ref values. Reproduce the output for C, C++, Python, or Java and trace why reusable enum references retain isEnum=false. Done means referenced enum variables are identified consistently across the affected generators and covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, java, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100