How to disable the default 422 doc
See original GitHub issueFastAPI has a default response doc for 422, but my response format is :
{
'code': 0,
'msg': 'hello',
'data': <object>
}
and code
contains any error code and msg
contains any error info. I don’t need the default 422 response doc.
I found the code in fastapi/openapi/utils
http422 = str(HTTP_422_UNPROCESSABLE_ENTITY)
if (all_route_params or route.body_field) and not any(
[
status in operation["responses"]
for status in [http422, "4XX", "default"]
]
):
operation["responses"][http422] = {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {"$ref": REF_PREFIX + "HTTPValidationError"}
}
},
}
if "ValidationError" not in definitions:
definitions.update(
{
"ValidationError": validation_error_definition,
"HTTPValidationError": validation_error_response_definition,
}
)
I think many application will need this feature. Can you set an optional switch or else that I can disable the default 422 doc? @tiangolo thanks.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13 (4 by maintainers)
Top Results From Across the Web
422 Unprocessable Entity - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type ...
Read more >Why does Swagger show "422 Validation Error" under the ...
When I visit the auto-generated swagger docs (http://127.0.0.1:8000/docs), my delete endpoint shows 422 Validation Error under Responses.
Read more >Disable and replace TLS 1.0 in ADFS - Windows Server
Events ID 422 is logged on AD FS proxies: Unable to retrieve proxy configuration from the Federation Service. Proxies cannot forward traffic to ......
Read more >Handling Errors - FastAPI
And it also includes a default exception handler for it. ... HTTP_422_UNPROCESSABLE_ENTITY, content=jsonable_encoder({"detail": exc.errors(), ...
Read more >Instructions for Birth Certificate Order Form
To request this document in another format, call 1-800-525-0127. ... DOH 422-182 July 2021 ... **If you are not one of the listed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My newest solution:
Hope this is useful. @vanntile @kounelios13
@kounelios13 I think you misunderstood what @DionVitor meant. I have probably a similar problem. I need to return the validation error with a different status code, but 422 is still in the OpenAPI if I override the ValidationError in FastAPI
exception_handlers
. Any tips how to remove the entry for 422 in the OpenAPI?