OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.75k stars 6.56k forks source link

[BUG] [Rust] Enum duplicates for negative and positive integers #11207

Open jongiddy opened 2 years ago

jongiddy commented 2 years ago

Bug Report Checklist

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.

jongiddy commented 2 years ago

This also occurs with strings with other symbols, for example:

"enum": ["red", "red*", "green", "blue"]