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

Duplicate key in Enum when using both lowercase and uppercase strings

未關閉
#1,030 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Python
星號
2k
分支
293
平均合併
34 分鐘
30 天內合併 PR
1

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 openapi_python_client/parser/properties/enum_property.py 開始,特別是 values_from_list,並使用提供的包含 enum 值 txt 和 TXT 的 schema 來重現錯誤。當這些僅大小寫不同的 enum 值能夠在不產生重複鍵錯誤的情況下被接受,且該行為由適當的測試涵蓋時,工作即完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
openapi, python
領域
api, tooling
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。