Skip to content

Duplicate Key Error during parser/properties/enum #587

Closed

Description

@AlexandreODelisle

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.

It might be the proper behavior, I am just wondering, why GitHub Spec is not parsable.

Activity

  1. dbanty commented on Feb 17, 2022

    @dbanty
    Collaborator

    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).

  2. added this to the 0.11.2 milestone on Feb 17, 2022
  3. modified the milestones: 0.11.2, 0.12.0 on May 1, 2022
  4. wadinj commented on Jul 25, 2022

    @wadinj

    Any plan to include this fix into the next release ?

  5. dbanty commented on Aug 8, 2022

    @dbanty
    Collaborator

    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 😓.

  6. emosenkis commented on Sep 2, 2024

    @emosenkis
    Contributor

    Another potential solution is #1114

  7. added a commit that references this issue on Oct 20, 2024
    4c019d9
  8. added a commit that references this issue on May 13, 2025
    f8918ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions