You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the FastAPI documentation, with the integrated search.
I already searched in Google "How to X in FastAPI" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI.
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromfastapiimportFastAPI, BodyfromtypingimportAnnotatedfrompydanticimportBaseModelapp=FastAPI()
classItem(BaseModel):
name: strprice: floatdescription: str|None=None@app.post("/items/{item_id}")asyncdefcreate_item(
item_id: int,
item: Annotated[
Item,
Body(
# embed=True,openapi_examples={
"normal": {
"summary": "A normal example",
"description": "A **normal** item works correctly.",
"value": {
"name": "Foo",
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
},
"converted": {
"summary": "An example with converted data",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
"value": {
"name": "Bar",
"price": "35.4",
},
},
"invalid": {
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
},
},
),
],
):
return {"item_id": item_id, "item": item}
Description
When I tried to embed the JSON in the Body with embed=True property I cannot use openapi_examples section in the SwaggerUI. Is it the expected behavior?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
When I tried to embed the JSON in the Body with embed=True property I cannot use openapi_examples section in the SwaggerUI. Is it the expected behavior?
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.104.1
Pydantic Version
2.4.2
Python Version
3.10.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions