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

Duplicate key in Enum when using both lowercase and uppercase strings

Aperta
#1,030 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
2k
Fork
293
Merge medio
34m
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da openapi_python_client/parser/properties/enum_property.py, in particolare da values_from_list, usando lo schema fornito con i valori enum txt e TXT per riprodurre l’errore. Il lavoro è completato quando questi valori enum distinti per maiuscole e minuscole vengono accettati senza un errore di chiave duplicata e il comportamento è coperto da un test appropriato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
openapi, python
Ambito
api, tooling
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.