First Check
Commit to Help
Example Code
from 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)
Description
In approx 0.76.0 a regression was observed related to the OpenAPI responses no longer accepting patterns of the form 4XX 5XX etc.
>>> app.include_router(router)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/venv/lib/python3.8/site-packages/fastapi/applications.py", line 420, in include_router
self.router.include_router(
File "/tmp/venv/lib/python3.8/site-packages/fastapi/routing.py", line 738, in include_router
self.add_api_route(
File "/tmp/venv/lib/python3.8/site-packages/fastapi/routing.py", line 565, in add_api_route
route = route_class(
File "/tmp/venv/lib/python3.8/site-packages/fastapi/routing.py", line 422, in __init__
assert is_body_allowed_for_status_code(
File "/tmp/venv/lib/python3.8/site-packages/fastapi/utils.py", line 24, in is_body_allowed_for_status_code
current_status_code = int(status_code)
ValueError: invalid literal for int() with base 10: '5XX'
Please refer to this PR #5145 which introduced the new code
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.81.0
Python Version
3.8.13
Additional Context
I 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
First Check
Commit to Help
Example Code
Description
In 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 System
Linux
Operating System Details
No response
FastAPI Version
0.81.0
Python Version
3.8.13
Additional Context
I 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