openapi-generators / openapi-generators/openapi-python-client
Model named `Client` causes errors
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
Describe the bug
If a model of the Openapi App is called Client this name collides with the client.Client object in imports.
OpenAPI Spec File
{
"openapi": "3.1.0",
"info": {
"title": "FastAPI",
"version": "0.1.0"
},
"paths": {
"/client": {
"get": {
"summary": "Client",
"operationId": "client_client_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Client"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Client": {
"properties": {
"foo": {
"type": "string",
"title": "Foo"
},
"bar": {
"type": "integer",
"title": "Bar"
}
},
"type": "object",
"required": [
"foo",
"bar"
],
"title": "Client"
}
}
}
}
Desktop (please complete the following information):
- OS: [e.g. Ubuntu 22.04]
- Python Version: [e.g. 3.10.12]
- openapi-python-client version [e.g. 0.19.1]
Additional context
The generator outputs:
Generating fast-api-client
Error(s) encountered while generating, client was not created
ruff failed
fast_api_client/api/default/client_client_get.py:8:30: F811 Redefinition of unused `Client` from line 7
Found 16 errors (15 fixed, 1 remaining).
In the relevant code there are two imports:
from ...client import AuthenticatedClient, Client
from ...models.client import Client
As hinted by ruff' error message there are two imports that load a Client object but they are loading different objects.
If you ty to use the generated code:
from fast_api_client import Client
from fast_api_client.api.default import client_client_get
with Client(base_url="http://localhost:8000") as client:
data = client_client_get.sync(client=client)
print(data)
It will still work properly as the only Client type that is actually used at runtime is the one from models which is imported last (the Client from client is only used for type-hinting).
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện vấn đề bằng đặc tả OpenAPI được cung cấp, sau đó kiểm tra các import trong tệp được tạo fast_api_client/api/default/client_client_get.py. Bản sửa được hoàn tất khi các kiểu model và client được tạo không còn xung đột và ruff chạy qua mà không có lỗi F811.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100