You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Duplicate Key Error during parser/properties/enum #587
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.
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:
classOperaions(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 ?
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 😓.
Activity
dbanty commentedon Feb 17, 2022
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:
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).
wadinj commentedon Jul 25, 2022
Any plan to include this fix into the next release ?
dbanty commentedon Aug 8, 2022
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 😓.
emosenkis commentedon Sep 2, 2024
Another potential solution is #1114
Release 0.21.6 (#1139)
Release 0.21.6 (openapi-generators#1139)