FastAPI - how to declare example data for built-in type parameters

Viewed 32

I'm using FastAPI v0.82.0 and making a POST method like below,

@app.post('my_func1/add')
def func_add(id: str = Body(description='this is an id'), 
             content: str = Body(description='this is a content'))
    ...

With this, I can see {"id": "string", "content": "string"} on example value field in docs.

However, I'd like to declare an example data into each parameter id and content, not with the value "string".

I know how to add an example data when the type of parameter is my own class, but have no idea when parameter is built-in type.

Body has example and examples attribute, so I tried

id: str = Body(description='this is an id', example='ex_id') and id: str = Body(description='this is an id', examples={'normal': 'ex_id'}). This didn't work.

Is there any way to add example data to parameters of built-in types and show it in docs?

0 Answers
Related