Duplicate Key Error during parser/properties/enum
Describe the bug GitHub OpenAPI Descriptor parsing
It seems we can not parse the GitHub OpenAPI since in the SCIM emu we have twice the value ( add and Add )
values = EnumProperty.values_from_list(value_list)
File "/home/adelisle/.local/lib/python3.8/site-packages/openapi_python_client/parser/properties/enum_property.py", line 61, in values_from_list
raise ValueError(f"Duplicate key {key} in Enum")
ValueError: Duplicate key ADD in Enum
To Reproduce
Steps to reproduce the behavior:
openapi-python-client generate --url https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json\?_sm_au_\=iHVj504RWD4Fn7kPLVN2jKsTtN4QF
Expected behavior I would have thought GitHub Open API would have been parsable.
OpenAPI Spec File https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json?sm_au=iHVj504RWD4Fn7kPLVN2jKsTtN4QF
You can lookup for "ADD"
Desktop (please complete the following information):
- OS: WSL2 Ubuntu 20.04
- Python Version: 3.8.10
- openapi-python-client version 0.11.1
Additional context Line forcing KEY in uppercase. https://github.com/openapi-generators/openapi-python-client/blob/199a8f926e841e5a5f79a9052115d8069bcab281/openapi_python_client/parser/properties/enum_property.py#L57
It might be the proper behavior, I am just wondering, why GitHub Spec is not parsable.
Well technically the values of an enum are case sensitive, the idiomatic way to represent an enum in Python is just to use the all caps representation of it. It hasn't come up until now where two words were spelled the same but with different casing being a unique value.
Maybe in the case where we detect this, we simply abort the auto-renaming and instead use the less-Pythonic as-is name. So in this case it would generate something like this:
class Operaions(str, Enum):
add = "add"
Add = "Add"
...
That would unfortunately mean that adding a new enum variant could cause breaking changes in the generated client—but it's better than disallowing this feature since it's used in a popular API (GitHub).
Any plan to include this fix into the next release ?
Any plan to include this fix into the next release ?
Unfortunately, I don't have much time to dedicate to this project right now—the little bit of open source time I have is focused elsewhere. If someone contributes this as a PR it'll happen sooner—but I'm having trouble even keeping up with the PRs that are open 😓.