Kludex / fastapi-responses

Find HTTPExceptions and turn them into documented responses! :tada:
https://github.com/Kludex/fastapi-responses
MIT License
90 stars 11 forks source link

fastapi.status int constants are not recognized #11

Open Phanabani opened 2 years ago

Phanabani commented 2 years ago

Hi there!

Thanks for this library, it looks like exactly what I need!

In my project, I'm using fastapi.status constants to make it clearer what the status codes are doing. Unfortunately, this library doesn't recognize those constants, only int literals.

It looks like @prawalgangwar started work on this in #10, and this could potentially be fixed by the proposed AST migration in #8, but I figured I'd make an issue here to make it known that this would be helpful!

Kludex commented 2 years ago

I'm planning to change the implementation by the end of August.

Thanks for reporting this. 🙏

Phanabani commented 2 years ago

That sounds great, thank you! 😊

Here is a minimal example in case it can help you in the future:

from fastapi import FastAPI, HTTPException, status
from fastapi_responses import custom_openapi

app = FastAPI(title="Test fastapi_responses with status constants")
app.openapi = custom_openapi(app)

@app.get("/uses_int")
def uses_int():
    if True:
        raise HTTPException(404, "ERROR MESSAGE HERE")
    return "Hi there"

@app.get("/uses_status_constant")
def uses_status_constant():
    if True:
        raise HTTPException(status.HTTP_404_NOT_FOUND, "ERROR MESSAGE HERE")
    return "Hi there"