Describe the bug
When configuring response_model, and/or typing the return value, or setting different response model for some http code, the openapi.json (and therefore /docs and /redoc) does not contain the correct schema nor the correct example.
To Reproduce
Given the following snippet:
from typing import Literal
from fastapi import FastAPI
from fastapi_cloudevents.cloudevent_response import StructuredCloudEventResponse
from fastapi_cloudevents import CloudEvent
app = FastAPI()
class Item(CloudEvent):
type: Literal["my.type.v1"]
name: str
price: float
class Error(CloudEvent):
message: str
@app.post(
"/items/",
response_class=StructuredCloudEventResponse,
response_model=Item,
responses={429: {"model": Error}},
)
async def create_item(item: Item) -> Item:
return item
@app.get("/items/",
response_class=StructuredCloudEventResponse,
response_model=Item,
responses={429: {"model": Error}},
)
async def read_items() -> Item:
return Item(name="Portal Gun", price=42.0, type="my.type.v1"),
- start fastapi with
uvicorn --port 9999 utils.test:app --reload for instance (if the file is utils/test.py)
- load
localhost:9999/docs
Expected behavior
the response model both for 200 and 409 are correctly documented
Actual behaviour
The response models are some generic json, and aren't CloudEvent instances. See screenshot.
Screenshots
System Details (please complete the following information):
- Python Version: 3.12.11
- OS: Linux
- FastAPI Version: 0.116.1
Thanks!
Describe the bug
When configuring response_model, and/or typing the return value, or setting different response model for some http code, the openapi.json (and therefore /docs and /redoc) does not contain the correct schema nor the correct example.
To Reproduce
Given the following snippet:
uvicorn --port 9999 utils.test:app --reloadfor instance (if the file isutils/test.py)localhost:9999/docsExpected behavior
the response model both for 200 and 409 are correctly documented
Actual behaviour
The response models are some generic json, and aren't CloudEvent instances. See screenshot.
Screenshots
System Details (please complete the following information):
Thanks!