openapi-generators / openapi-generators/openapi-python-client
Duplicate key in Enum when using both lowercase and uppercase strings
未关闭
还没有人认领这个 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 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