APIFlask app returns different errors with status code but why spec doesn't have that?

69 Views Asked by At

I have an APIFlask app and a GET endpoint. Everything works fine and I have the API spec api.yaml. I can see the responses - enter image description here

There are some error responses. But I am looking for some 500 response that I raised in the code -

if not identity:
    abort(403)

Is there any configuration to have those manual error responses?

1

There are 1 best solutions below

1
Grey Li On BEST ANSWER

It can't detect the error code you returned in your view function. It does add some status code for your endpoint automatically (401, 422, 404) based on the decorator you used. For other error responses, you have to use the doc decorator to add manually:

@app.get('/')
@app.doc(responses=[403])
def hello():
    abort(403)

Refer to the docs for more details: https://apiflask.com/openapi/#alternative-operation-responses