Skip to content
Discussion options

You must be logged in to vote

openapi_examples is a parameter of Body, it's not a part of JSON schema (json_schema_extra is supposed to be used to modify the JSON schema).

You can specify examples for request body

from typing import Annotated
from fastapi import Body, FastAPI
from fastapi.openapi.models import Example
from pydantic import BaseModel, Field

app = FastAPI()

class CreateRequest2(BaseModel):
    name: str = Field(..., description="Name of the created item")
    value: str = Field(..., description="Value of the created item")

@app.post("/2")
def create_item2(
    body: Annotated[
        CreateRequest2,
        Body(
            openapi_examples={
                "abc": Example(
                    summary=

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants