Regression in OpenAPI related checks during app.include_router(router)
#8380
-
First Check
Commit to Help
Example Codefrom typing import Union
from fastapi import FastAPI, APIRouter
from fastapi.responses import FileResponse
from pydantic import BaseModel
class Item(BaseModel):
id: str
value: str
responses = {
404: {"description": "Item not found"},
302: {"description": "The item was moved"},
403: {"description": "Not enough privileges"},
"5XX": {"description": "Server errors", "model": Item},
}
app = FastAPI(responses=responses)
router = APIRouter()
@router.get(
"/items/{item_id}",
response_model=Item,
)
async def read_item(item_id: str, img: Union[bool, None] = None):
if img:
return FileResponse("image.png", media_type="image/png")
else:
return {"id": "foo", "value": "there goes my hero"}
app.include_router(router) DescriptionIn approx 0.76.0 a regression was observed related to the OpenAPI responses no longer accepting patterns of the form 4XX 5XX etc.
Please refer to this PR #5145 which introduced the new code Operating SystemLinux Operating System DetailsNo response FastAPI Version0.81.0 Python Version3.8.13 Additional ContextI can't actually commit to a PR/monitoring this repo/such. I will likely sponsor the project soon as I love it, but I simply don't have that kind of time |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
A fix is ready here #5187 |
Beta Was this translation helpful? Give feedback.
-
Thanks, now just a question of who can approve+merge it |
Beta Was this translation helpful? Give feedback.
A fix is ready here #5187