response_model - filter output
Core# response_model strips fields not in UserOut
# even if the handler returns a UserIn object
@app.post("/users", response_model=UserOut, status_code=201)
async def create_user(user: UserIn):
return user # password auto-stripped by response_model
# Strip None and unset fields
@app.get(
"/items/{id}",
response_model=Item,
response_model_exclude_none=True,
response_model_exclude_unset=True,
response_model_exclude={"internal_id"}, # remove specific fields
response_model_include={"name", "price"}, # or include only these
)
async def get_item(id: int): ...