Skip to content

Commit 21305cf

Browse files
committed
fixed bug: resolved issues in single file upload
1 parent 6d0bd82 commit 21305cf

File tree

3 files changed

+76
-18
lines changed

3 files changed

+76
-18
lines changed

ellar/common/params/args/request_model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ def build_body_field(self) -> None:
106106
and len(body_resolvers) == 1
107107
and not (
108108
body_resolvers[0].model_field.field_info.embed # type: ignore[attr-defined]
109-
and isinstance(
110-
body_resolvers[0].model_field.field_info, params.BodyFieldInfo
111-
)
112109
)
113110
):
114111
check_file_field(body_resolvers[0].model_field)

tests/test_routing/document_results.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
"content": {
1111
"multipart/form-data": {
1212
"schema": {
13-
"title": "Test",
14-
"type": "string",
15-
"format": "binary",
13+
"title": "Body",
14+
"allOf": [
15+
{
16+
"$ref": "#/components/schemas/body_form_upload_single_case_1__post"
17+
}
18+
],
1619
"include_in_schema": True,
1720
}
1821
}
@@ -174,14 +177,12 @@
174177
"content": {
175178
"multipart/form-data": {
176179
"schema": {
177-
"title": "Test1",
178-
"type": "array",
179-
"items": {
180-
"anyOf": [
181-
{"type": "string", "format": "binary"},
182-
{"type": "string"},
183-
]
184-
},
180+
"title": "Body",
181+
"allOf": [
182+
{
183+
"$ref": "#/components/schemas/body_form_upload_multiple_case_1_multiple_post"
184+
}
185+
],
185186
"include_in_schema": True,
186187
}
187188
}
@@ -276,6 +277,24 @@
276277
},
277278
},
278279
},
280+
"body_form_upload_multiple_case_1_multiple_post": {
281+
"title": "body_form_upload_multiple_case_1_multiple_post",
282+
"required": ["test1"],
283+
"type": "object",
284+
"properties": {
285+
"test1": {
286+
"title": "Test1",
287+
"type": "array",
288+
"items": {
289+
"anyOf": [
290+
{"type": "string", "format": "binary"},
291+
{"type": "string"},
292+
]
293+
},
294+
"include_in_schema": True,
295+
}
296+
},
297+
},
279298
"body_form_upload_multiple_case_2_mixed_optional_post": {
280299
"title": "body_form_upload_multiple_case_2_mixed_optional_post",
281300
"type": "object",
@@ -299,6 +318,19 @@
299318
},
300319
},
301320
},
321+
"body_form_upload_single_case_1__post": {
322+
"title": "body_form_upload_single_case_1__post",
323+
"required": ["test"],
324+
"type": "object",
325+
"properties": {
326+
"test": {
327+
"title": "Test",
328+
"type": "string",
329+
"format": "binary",
330+
"include_in_schema": True,
331+
}
332+
},
333+
},
302334
"body_form_upload_single_case_2_mixed_post": {
303335
"title": "body_form_upload_single_case_2_mixed_post",
304336
"required": ["test_alias", "test2"],

tests/test_routing/test_form_schema.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,44 @@ def test_schema():
9393
params = document["paths"]["/form-schema"]["post"]["requestBody"]
9494
assert params == {
9595
"content": {
96-
"application/x-www-form-urlencoded": {
96+
"application/form-data": {
9797
"schema": {
98-
"allOf": [{"$ref": "#/components/schemas/Filter"}],
98+
"allOf": [
99+
{
100+
"$ref": "#/components/schemas/body_form_params_schema_form_schema_post"
101+
}
102+
],
99103
"include_in_schema": True,
100-
"title": "Will Not Work For Schema With Many Field",
104+
"title": "Body",
101105
}
102106
}
107+
}
108+
}
109+
schema = document["components"]["schemas"][
110+
"body_form_params_schema_form_schema_post"
111+
]
112+
assert schema == {
113+
"title": "body_form_params_schema_form_schema_post",
114+
"type": "object",
115+
"properties": {
116+
"to": {
117+
"title": "To",
118+
"type": "string",
119+
"format": "date-time",
120+
"include_in_schema": True,
121+
},
122+
"from": {
123+
"title": "From",
124+
"type": "string",
125+
"format": "date-time",
126+
"include_in_schema": True,
127+
},
128+
"range": {
129+
"allOf": [{"$ref": "#/components/schemas/Range"}],
130+
"default": 20,
131+
"include_in_schema": True,
132+
},
103133
},
104-
"required": True,
105134
}
106135

107136

0 commit comments

Comments
 (0)