Incorrect `const` property validation
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện vấn đề với tài liệu OpenAPI được cung cấp và kiểm tra phần xác thực const được giới thiệu trong #1024. Theo dõi quá trình tạo test-service-client/test_service_client/models/test_model.py, đặc biệt là hàm _parse_foo cho schema Foo. Hoàn tất khi phần xác thực xem xét cả hai lựa chọn const thay vì trả về sau lựa chọn đầu tiên, và có một kiểm thử hồi quy bao phủ ví dụ này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
The const property validation introduced in #1024 is not correct when there are >= 2 non-none values.
In particular, the validation accepts only the first value
OpenAPI Spec File
--> Please focus on the Foo schema at the end
{
"openapi": "3.1.0",
"info": {
"title": "Test Service",
"version": "0.1.0"
},
"paths": {
"/test": {
"post": {
"summary": "Test",
"operationId": "test",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TestModel"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
},
"components": {
"schemas": {
"TestModel": {
"properties": {
"foo": {
"$ref": "#/components/schemas/Foo"
}
},
"type": "object",
"required": [
"foo"
],
"title": "TestModel"
},
"Foo": {
"oneOf": [
{
"const": 1
},
{
"const": 2
}
],
"title": "FooType"
}
}
}
}
Desktop (please complete the following information):
- OS: all
- Python Version: all
- openapi-python-client version: the latest code, after #1024
Additional context
The above schema generates the file test-service-client/test_service_client/models/test_model.py as follows:
class TestModel:
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
def _parse_foo(data: object) -> Union[Literal[1], Literal[2]]:
componentsschemas_foo_type_0 = cast(Literal[1], data)
if componentsschemas_foo_type_0 != 1:
raise ValueError(
f"/components/schemas/Foo_type_0 must match const 1, got '{componentsschemas_foo_type_0}'"
)
return componentsschemas_foo_type_0
# -----> ERROR HERE: the code below this line is never reached<------
componentsschemas_foo_type_1 = cast(Literal[2], data)
if componentsschemas_foo_type_1 != 2:
raise ValueError(
f"/components/schemas/Foo_type_1 must match const 2, got '{componentsschemas_foo_type_1}'"
)
return componentsschemas_foo_type_1
foo = _parse_foo(d.pop("foo"))
test_model = cls(
foo=foo,
)
test_model.additional_properties = d
return test_model
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
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.
Issue khác của openapi-generators/openapi-python-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
openapi-generators/openapi-python-client#1451 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
openapi-generators/openapi-python-client#1435 · 1 bình luận ·
Tất cả issue của openapi-generators/openapi-python-client
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·