Description
Discussed in #3540
Originally posted by MCR2019 December 19, 2023
Really excited about the quite new powertools openAPI spec generation so thank to all those who've worked on it and those working on it now :)
I'm trying to get it working for an endpoint and following the documentation on how to specify responses here:
Customizing API Operations docs
Specifically I'd like to add custom reponses which the documentation shows as:
@app.get(
"/todos/<todo_id>",
summary="Retrieves a todo item",
description="Loads a todo item identified by the `todo_id`",
response_description="The todo object",
responses={
200: {"description": "Todo item found"},
404: {
"description": "Item not found",
},
},
tags=["Todos"],
)
def get_todo_title(todo_id: int) -> str:
todo = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
todo.raise_for_status()
I'd really like to be able to specify the content/schema of the response, maybe as a Pydantic Model which would then generate the response schema in the openAPI spec. (in the same way that the function response type is used).
At the moment I'm only able to get it to work with a basic string which doesn't represent the actual return type/structure.
Is there any more info on what the intention is for how this should be used with a fuller example?
I'm aware that this functionality is quite new so I'm not sure if this is something already on the to do list?
Any info would be great, and thanks again!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status