@@ -55,7 +55,8 @@ def _do_decorator(
55
55
servers : Optional [List [Server ]] = None ,
56
56
openapi_extensions : Optional [Dict [str , Any ]] = None ,
57
57
doc_ui : bool = True ,
58
- method : str = HTTPMethod .GET
58
+ method : str = HTTPMethod .GET ,
59
+ validation_error_status : str = "422"
59
60
) -> Tuple [Type [BaseModel ], Type [BaseModel ], Type [BaseModel ], Type [BaseModel ], Type [BaseModel ], Type [BaseModel ]]:
60
61
raise NotImplementedError
61
62
@@ -71,8 +72,9 @@ def create_view_func(
71
72
query ,
72
73
form ,
73
74
body ,
75
+ validation_error_status = "422" ,
74
76
view_class = None ,
75
- view_kwargs = None
77
+ view_kwargs = None ,
76
78
):
77
79
is_coroutine_function = iscoroutinefunction (func )
78
80
if is_coroutine_function :
@@ -85,10 +87,11 @@ async def view_func(**kwargs) -> Response:
85
87
query = query ,
86
88
form = form ,
87
89
body = body ,
90
+ validation_error_status = validation_error_status ,
88
91
path_kwargs = kwargs
89
92
)
90
93
if isinstance (func_kwargs , Response ):
91
- # 422
94
+ # validation_error_status from OpenAPI Initialization
92
95
return func_kwargs
93
96
# handle async request
94
97
if view_class :
@@ -112,10 +115,11 @@ def view_func(**kwargs) -> Response:
112
115
query = query ,
113
116
form = form ,
114
117
body = body ,
115
- path_kwargs = kwargs
118
+ path_kwargs = kwargs ,
119
+ validation_error_status = validation_error_status
116
120
)
117
121
if isinstance (result , Response ):
118
- # 422
122
+ # validation_error_status from OpenAPI initialization
119
123
return result
120
124
# handle request
121
125
if view_class :
@@ -153,6 +157,7 @@ def get(
153
157
servers : Optional [List [Server ]] = None ,
154
158
openapi_extensions : Optional [Dict [str , Any ]] = None ,
155
159
doc_ui : bool = True ,
160
+ validation_error_status : str = "422" ,
156
161
** options : Any
157
162
) -> Callable :
158
163
"""
@@ -176,6 +181,8 @@ def get(
176
181
openapi_extensions: Allows extensions to the OpenAPI Schema.
177
182
doc_ui: Add openapi document UI (swagger, rapidoc and redoc).
178
183
Default to True.
184
+ validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
185
+ Defaults to 422
179
186
"""
180
187
181
188
if extra_form is not None :
@@ -210,10 +217,11 @@ def decorator(func) -> Callable:
210
217
servers = servers ,
211
218
openapi_extensions = openapi_extensions ,
212
219
doc_ui = doc_ui ,
213
- method = HTTPMethod .GET
220
+ method = HTTPMethod .GET ,
221
+ validation_error_status = validation_error_status
214
222
)
215
223
216
- view_func = self .create_view_func (func , header , cookie , path , query , form , body )
224
+ view_func = self .create_view_func (func , header , cookie , path , query , form , body , validation_error_status )
217
225
options .update ({"methods" : [HTTPMethod .GET ]})
218
226
self .add_url_rule (rule , view_func = view_func , ** options )
219
227
@@ -239,6 +247,7 @@ def post(
239
247
servers : Optional [List [Server ]] = None ,
240
248
openapi_extensions : Optional [Dict [str , Any ]] = None ,
241
249
doc_ui : bool = True ,
250
+ validation_error_status : str = "422" ,
242
251
** options : Any
243
252
) -> Callable :
244
253
"""
@@ -261,6 +270,8 @@ def post(
261
270
servers: An alternative server array to service this operation.
262
271
openapi_extensions: Allows extensions to the OpenAPI Schema.
263
272
doc_ui: Declares this operation to be shown.
273
+ validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
274
+ Defaults to 422
264
275
"""
265
276
if extra_form is not None :
266
277
warnings .warn (
@@ -294,10 +305,11 @@ def decorator(func) -> Callable:
294
305
servers = servers ,
295
306
openapi_extensions = openapi_extensions ,
296
307
doc_ui = doc_ui ,
297
- method = HTTPMethod .POST
308
+ method = HTTPMethod .POST ,
309
+ validation_error_status = validation_error_status
298
310
)
299
311
300
- view_func = self .create_view_func (func , header , cookie , path , query , form , body )
312
+ view_func = self .create_view_func (func , header , cookie , path , query , form , body , validation_error_status )
301
313
options .update ({"methods" : [HTTPMethod .POST ]})
302
314
self .add_url_rule (rule , view_func = view_func , ** options )
303
315
@@ -323,6 +335,7 @@ def put(
323
335
servers : Optional [List [Server ]] = None ,
324
336
openapi_extensions : Optional [Dict [str , Any ]] = None ,
325
337
doc_ui : bool = True ,
338
+ validation_error_status : str = "422" ,
326
339
** options : Any
327
340
) -> Callable :
328
341
"""
@@ -345,6 +358,8 @@ def put(
345
358
servers: An alternative server array to service this operation.
346
359
openapi_extensions: Allows extensions to the OpenAPI Schema.
347
360
doc_ui: Declares this operation to be shown.
361
+ validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
362
+ Defaults to 422
348
363
"""
349
364
if extra_form is not None :
350
365
warnings .warn (
@@ -378,10 +393,11 @@ def decorator(func) -> Callable:
378
393
servers = servers ,
379
394
openapi_extensions = openapi_extensions ,
380
395
doc_ui = doc_ui ,
381
- method = HTTPMethod .PUT
396
+ method = HTTPMethod .PUT ,
397
+ validation_error_status = validation_error_status
382
398
)
383
399
384
- view_func = self .create_view_func (func , header , cookie , path , query , form , body )
400
+ view_func = self .create_view_func (func , header , cookie , path , query , form , body , validation_error_status )
385
401
options .update ({"methods" : [HTTPMethod .PUT ]})
386
402
self .add_url_rule (rule , view_func = view_func , ** options )
387
403
@@ -406,6 +422,7 @@ def delete(
406
422
security : Optional [List [Dict [str , List [Any ]]]] = None ,
407
423
servers : Optional [List [Server ]] = None ,
408
424
openapi_extensions : Optional [Dict [str , Any ]] = None ,
425
+ validation_error_status : str = "422" ,
409
426
doc_ui : bool = True ,
410
427
** options : Any
411
428
) -> Callable :
@@ -429,6 +446,8 @@ def delete(
429
446
servers: An alternative server array to service this operation.
430
447
openapi_extensions: Allows extensions to the OpenAPI Schema.
431
448
doc_ui: Declares this operation to be shown.
449
+ validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
450
+ Defaults to 422
432
451
"""
433
452
if extra_form is not None :
434
453
warnings .warn (
@@ -462,10 +481,11 @@ def decorator(func) -> Callable:
462
481
servers = servers ,
463
482
openapi_extensions = openapi_extensions ,
464
483
doc_ui = doc_ui ,
465
- method = HTTPMethod .DELETE
484
+ method = HTTPMethod .DELETE ,
485
+ validation_error_status = validation_error_status
466
486
)
467
487
468
- view_func = self .create_view_func (func , header , cookie , path , query , form , body )
488
+ view_func = self .create_view_func (func , header , cookie , path , query , form , body , validation_error_status )
469
489
options .update ({"methods" : [HTTPMethod .DELETE ]})
470
490
self .add_url_rule (rule , view_func = view_func , ** options )
471
491
@@ -491,6 +511,7 @@ def patch(
491
511
servers : Optional [List [Server ]] = None ,
492
512
openapi_extensions : Optional [Dict [str , Any ]] = None ,
493
513
doc_ui : bool = True ,
514
+ validation_error_status : str = "422" ,
494
515
** options : Any
495
516
) -> Callable :
496
517
"""
@@ -513,6 +534,8 @@ def patch(
513
534
servers: An alternative server array to service this operation.
514
535
openapi_extensions: Allows extensions to the OpenAPI Schema.
515
536
doc_ui: Declares this operation to be shown.
537
+ validation_error_status: HTTP Status of the response given when a validation error is detected by pydantic.
538
+ Defaults to 422
516
539
"""
517
540
if extra_form is not None :
518
541
warnings .warn (
@@ -546,10 +569,12 @@ def decorator(func) -> Callable:
546
569
servers = servers ,
547
570
openapi_extensions = openapi_extensions ,
548
571
doc_ui = doc_ui ,
549
- method = HTTPMethod .PATCH
572
+ method = HTTPMethod .PATCH ,
573
+ validation_error_status = validation_error_status
550
574
)
551
575
552
- view_func = self .create_view_func (func , header , cookie , path , query , form , body )
576
+ view_func = self .create_view_func (func , header , cookie , path , query , form , body ,
577
+ validation_error_status = validation_error_status )
553
578
options .update ({"methods" : [HTTPMethod .PATCH ]})
554
579
self .add_url_rule (rule , view_func = view_func , ** options )
555
580
0 commit comments