Model import shadows HTTP `Client` import when a schema is named `Client`
还没有人认领这个 Issue。
评估
调研方向
从 endpoint_module.py.jinja 和 endpoint.relative_imports 背后的逻辑开始,然后根据 issue 生成最小的 OpenAPI 规范。检查生成的 api/client/update_client.py 中的 imports,以及 _parse_response 和 _build_response 的注解。当名为 Client 的 schema 不再导致 HTTP Client 引用被遮蔽时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When an OpenAPI spec contains a schema named Client, the generated endpoint modules import both the HTTP Client class and the Client model class under the same name. The model import silently shadows the HTTP client import, making Client in type annotations refer to the wrong class.
endpoint_module.py.jinja unconditionally emits:
from ...client import AuthenticatedClient, Client
Then endpoint.relative_imports adds model imports. When a model is also named Client, the result is:
from ...client import AuthenticatedClient, Client # HTTP client
from ...models.client import Client # model — shadows the line above
This causes Client in _parse_response and _build_response type annotations to resolve to the model instead of the HTTP client class.
OpenAPI Spec File
Minimal reproduction:
openapi: "3.0.3"
info:
title: Minimal repro
version: "1.0"
paths:
/api/clients/{id}:
patch:
operationId: update_client
tags:
- client
parameters:
- name: id
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Client"
components:
schemas:
Client:
type: object
properties:
name:
type: string
In the generated api/client/update_client.py, line 6 imports Client from ...client and line 10 re-imports Client from ...models.client, shadowing it.
Desktop (please complete the following information):
- OS: macOS 15 (ARM64)
- Python Version: 3.13
- openapi-python-client version: 0.27.1 (also verified on 0.28.3)
Additional context
We worked around this by using custom templates.
- 主要语言
- Python
- 星标
- 2k
- 派生
- 293
- 平均合并
- 34 分钟
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openapi-generators/openapi-python-client 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 3/5 1-2 天 新手友好度 72/100
openapi-generators/openapi-python-client#1451 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 52/100
-
难度 3/5 1-2 天 新手友好度 64/100
openapi-generators/openapi-python-client#1435 · 1 条评论 ·
查看 openapi-generators/openapi-python-client 的全部 Issue
相似的 Issue
-
bug confirmed issue
难度 2/5 1-3 小时 新手友好度 75/100
open-webui/open-webui#30750 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
good first issue
难度 1/5 1 小时以内 新手友好度 90/100