5

For example, I don't want to expose the correct regex for a string in the FastAPI Swagger docs. How to achieve that?

Swagger Validation Error: Swagger Validation Error

I have actually achieved it using the following way:

@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc: RequestValidationError):
    return PlainTextResponse(
        str("the string does not match the correct regex"), status_code=422
    )

BUT it works only when I call the endpoint from Postman, but in Swagger, FastAPI seems to throw the validation error even before hitting the endpoint.

I have tried lots of things but nothing seem to work.

1
  • You might find this answer helpful. Commented Nov 19, 2022 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.