openapi-generators / openapi-generators/openapi-python-client

Duplicate key in Enum when using both lowercase and uppercase strings

Ouverte
#1,030 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
2k
Forks
293
Merge moyen
34 min
PR mergées (30 j)
1

Description

Describe the bug

enums are case-sensitive in OpenAPI spec[1] but the openapi generator does not treat them that way. When I try to use both lowercase and uppercase values in enum like so:

components:
  schemas:
    DocumentType:
      type: string
      enum: [txt, TXT]

I get this error:

Traceback (most recent call last):

  File "/Users/xxx/.local/bin/openapi-python-client", line 8, in <module>
    sys.exit(app())
             ^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/cli.py", line 175, in update
    errors = update_existing_client(
             ^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/__init__.py", line 336, in update_existing_client
    project = _get_project_for_url_or_path(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/__init__.py", line 295, in _get_project_for_url_or_path
    openapi = GeneratorData.from_dict(data_dict, config=config)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/openapi.py", line 503, in from_dict
    schemas = build_schemas(components=openapi.components.schemas, schemas=schemas, config=config)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/__init__.py", line 386, in build_schemas
    schemas = _create_schemas(components=components, schemas=schemas, config=config)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/__init__.py", line 307, in _create_schemas
    schemas_or_err = update_schemas_with_data(ref_path=ref_path, data=data, schemas=schemas, config=config)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/schemas.py", line 114, in update_schemas_with_data
    prop, schemas = property_from_data(
                    ^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/__init__.py", line 178, in property_from_data
    return EnumProperty.build(
           ^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/enum_property.py", line 124, in build
    values = EnumProperty.values_from_list(value_list)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/xxx/.local/pipx/venvs/openapi-python-client/lib/python3.12/site-packages/openapi_python_client/parser/properties/enum_property.py", line 203, in values_from_list
    raise ValueError(f"Duplicate key {key} in Enum")

ValueError: Duplicate key TXT in Enum

OpenAPI Spec File

see above

Desktop (please complete the following information):

  • OS: macOS 15.x
  • Python Version: 3.12
  • openapi-python-client version 0.19.1

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par openapi_python_client/parser/properties/enum_property.py, en particulier values_from_list, en utilisant le schéma fourni avec les valeurs d’énumération txt et TXT pour reproduire l’erreur. Le travail est terminé lorsque ces valeurs d’énumération qui ne diffèrent que par la casse sont acceptées sans erreur de clé en double et que le comportement est couvert par un test approprié.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
openapi, python
Domaine
api, tooling
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.