[Bug]: allOf in a request body silently drops fields for x-www-form-urlencoded requests
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
- 76/100
Hướng nghiên cứu
Start at iter_all_of_schemas in openapi_core/validation/schemas/validators.py and reproduce the form-body example with OpenAPI.from_dict and MockRequest. Verify that the allOf fields are retained and cast as expected, with no silent loss; add a regression test covering the x-www-form-urlencoded request.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Actual Behavior
If a form request body (application/x-www-form-urlencoded) uses allOf, and one of the allOf parts has a field that isn't a string (a boolean, integer,
or object), that whole allOf part gets dropped. Every field in it disappears from the result, even the string ones.
There's no error. result.errors is empty, so it looks like the request succeeded. The fields just silently go missing. A log.warning("invalid allOf schema found") is printed.
In the example below, the result is {'name': 'widget'}. Both enabled (a boolean) and label (a string) are gone, because they're in the same allOf part as the boolean.
Expected Behavior
The result should be {'name': 'widget', 'enabled': True, 'label': 'hello'}.
If I write the same fields as one plain object instead of using allOf, it works correctly and enabled is cast to True:
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"enabled": {"type": "boolean"},
"label": {"type": "string"},
},
}
# -> {'name': 'widget', 'enabled': True, 'label': 'hello'}
allOf should give the same result. And valid data should never be dropped
without an error.
Steps to Reproduce
Run this (only openapi_core is needed):
from openapi_core import OpenAPI
from openapi_core.testing import MockRequest
spec = OpenAPI.from_dict({
"openapi": "3.0.1",
"info": {"title": "repro", "version": "1.0.0"},
"paths": {"/items": {"post": {
"requestBody": {"content": {"application/x-www-form-urlencoded": {"schema": {
"allOf": [
{"$ref": "#/components/schemas/Flags"},
{"type": "object", "properties": {"name": {"type": "string"}}},
]
}}}},
"responses": {"200": {"description": "ok"}},
}}},
"components": {"schemas": {"Flags": {
"type": "object",
"properties": {
"enabled": {"type": "boolean"},
"label": {"type": "string"},
},
}}},
})
request = MockRequest(
host_url="http://example.com", method="post", path="/items",
data=b"name=widget&label=hello&enabled=true",
content_type="application/x-www-form-urlencoded",
)
result = spec.unmarshal_request(request)
print(result.body) # {'name': 'widget'}
print(result.errors) # []
Output:
invalid allOf schema found
{'name': 'widget'}
[]
OpenAPI Core Version
0.23.1
OpenAPI Core Integration
none (openapi_core.testing.MockRequest); first seen with Django
Affected Area(s)
unmarshalling, schema
References
This looks related to the older "allOf is treated as type: any" reports (#147, #149), but here the effect is different: valid data is silently dropped,
instead of just a confusing error message. It only happens for form bodies, where values arrive as strings.
It seems to come from iter_all_of_schemas in openapi_core/validation/schemas/validators.py. Each allOf part is checked against the raw value and skipped if it doesn't match. For form bodies the values are still strings at that point, so a part with enabled: {type: boolean} fails against the string "true", gets skipped, and its fields are never read.
Anything else we need to know?
No response
Would you like to implement a fix?
Yes
- Ngôn ngữ chính
- Python
- Star
- 368
- Fork
- 140
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 python-openapi/openapi-core
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python-openapi/openapi-core#1188 · 2 bình luận ·
-
kind/bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
python-openapi/openapi-core#1225 · 2 bình luận ·
-
[Bug]: Query parameter validation fails to match empty string when listed as a valid enum value Đang mởkind/bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
python-openapi/openapi-core#1210 ·
-
kind/bug kind/bug/confirmed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
python-openapi/openapi-core#1180 · 3 bình luận ·
-
kind/enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 32/100
python-openapi/openapi-core#1142 ·
Tất cả issue của python-openapi/openapi-core
Issue tương tự
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
simonw/sqlite-utils#872 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100