Simon-Huang-1
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
7 additions and
5 deletions
-
fastapi/openapi/utils.py
|
|
|
@ -417,11 +417,13 @@ def get_openapi_path( |
|
|
|
openapi_response["description"] = description |
|
|
|
http422 = "422" |
|
|
|
all_route_params = get_flat_params(route.dependant) |
|
|
|
requires_validation_error = bool(all_route_params or route.body_field) |
|
|
|
has_validation_response = any( |
|
|
|
status in operation["responses"] for status in ("422", "4XX", "default") |
|
|
|
) |
|
|
|
if requires_validation_error and not has_validation_response: |
|
|
|
if ( |
|
|
|
(all_route_params or route.body_field) # May raise validation error |
|
|
|
and not any( # Doesn't have a defined validation error response already |
|
|
|
status in operation["responses"] |
|
|
|
for status in [http422, "4XX", "default"] |
|
|
|
) |
|
|
|
): |
|
|
|
operation["responses"][http422] = { |
|
|
|
"description": "Validation Error", |
|
|
|
"content": { |
|
|
|
|