OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Rust] Enum duplicates for negative and positive integers
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
5.4.0-SNAPSHOT (Git SHA 8a3b434d54de4639295a34c332707678d4f44038)
OpenAPI declaration file content or url
Using code from equivalent bug for PHP: https://github.com/OpenAPITools/openapi-generator/issues/7441
https://gist.github.com/victorlap/44e351b72f5d9f26f0ac1943b4c6cf22
Generation Details
java -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --input-spec spec.json --generator-name rust --output issue7441
Steps to reproduce
Run the above command on the spec that is linked in the gist.
Check file issue7441/src/models/sales_order_billingaddress.rs and see duplicate const declaration:
pub enum CustomForm {
#[serde(rename = "-1049")]
_1049,
#[serde(rename = "1049")]
_1049,
}
Related issues/PRs
PHP: https://github.com/OpenAPITools/openapi-generator/issues/7441
Suggest a fix
This may be a language-independent problem. Adding code at https://github.com/OpenAPITools/openapi-generator/blob/8a3b434d54de4639295a34c332707678d4f44038/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L5914 to check if toEnumVarName(enumName, dataType) is present in the name field of an existing entry in enumVars and adding a disambiguating suffix if so, may work.
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
Reproduce the issue with the linked gist and the provided openapi-generator command, then inspect DefaultCodegen.java around the referenced enum variable generation code. Compare the generated issue7441/src/models/sales_order_billingaddress.rs output with the expected distinct Rust enum variant names; completion means the negative and positive values no longer produce duplicate declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, rust
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100