Skip to content
Discussion options

You must be logged in to vote

Hi!

It's not possible to exclude when the response is a list, also I recommend data filtering.

See the tip

This should work as expected:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class ItemBase(BaseModel):
    name: str
    description: str

class CreateItem(ItemBase):
    price: float

class ShowItem(ItemBase):
    pass


@app.post("/items/", response_model=list[ShowItem])
async def create_item(item: CreateItem):
    return [item]

Replies: 3 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 ermal-abiti
Comment options

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