Fastapi: [QUESTION] How to provide custom example value for single return

Created on 28 Apr 2020  路  6Comments  路  Source: tiangolo/fastapi

First check

  • [x] I used the GitHub search to find a similar issue and didn't find it.
  • [x] I searched the FastAPI documentation, with the integrated search.
  • [x] I already searched in Google "How to X in FastAPI" and didn't find any information.

Description

How can I provide a custom example value for the return value of routes? When the return is a Pydantic model, you can set the example keyword argument on a pydantic Field or add it to schema_extra in the Model config. However, when the return value is a simple type such as str or List[Optional[int]]` there seems to be no way to provide an example. Am I missing something, or is this a missing feature?

question

All 6 comments

@phy25 I am asking about responses not request parameters.

you can manually extend/alter the returned schema, but I'd think there would be a way to do this
https://fastapi.tiangolo.com/advanced/extending-openapi/

Hi, @retnikt !

You can add examples for in field responses. See this page

Thanks @Slyfoxy

Thanks for the help here everyone! :clap: :bow:

Thanks for reporting back and closing the issue @retnikt :+1:

Was this page helpful?
0 / 5 - 0 ratings