Custom RequestValidationError but Swagger not update the schema
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request, exc):
errors = exc.errors()
custom_error = []
for error in errors:
custom_error.append(error['msg'])
return JSONResponse(status_code=422, content=jsonable_encoder({'detail': custom_error}))
Description
After I custom the RequestValidationError above, the swagger’s schema is still the original one.
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.79.0
Python Version
3.9.13
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Custom exception handling not updating OpenAPI status code
Hi, I'm trying to override the 422 status code to a 400 across every endpoint on my app, but it keeps showing as...
Read more >Displaying of FastAPI validation errors to end users
Use it to display form validation messages; Generate forms themselves from api description if it's possible. python · swagger · openapi ...
Read more >Handling Errors - FastAPI
Override request validation exceptions¶. When a request contains invalid data, FastAPI internally raises a RequestValidationError . And it also includes a ...
Read more >Fix Swagger Validator errors in Power Platform connectors
The Swagger Validator tool validates the connector files you submit in the GitHub open-source repository and the ISV portal.
Read more >Using OpenAPI and Swagger UI - Quarkus
If you do not like the default endpoint location /q/openapi , you can change it by adding the following configuration to your application.properties...
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
It’s described here in the docs . You can add a 422 response in the
responses
parameter of the decorator and that will override the default.@iudeen is correct, adding a handler does not automagically add that to the generated
openapi.json
. You would have to add those to the endpoints themselves in order for them to show up in the spec, otherwise it will use the default definition: