flask-openapi3 icon indicating copy to clipboard operation
flask-openapi3 copied to clipboard

How to add examples to swagger

Open shaunjl opened this issue 1 year ago • 1 comments

Hi! I'm trying to find out how to properly create swagger examples. I have tried a number of different things but I haven't gotten it to work and I don't see any mention of this anywhere in here.

code

Here you can see I am attempting to add the kwarg examples to my pydantic Field. Screenshot 2024-02-02 at 11 28 12 AM

Field(..., examples='John Doe')

I see that the pydantic FieldInfo object annotates this argument as a list (here) examples: list[Any] | None and tried that in various ways to no avail:

  • examples=[{'test': 'John Doe'}]
  • examples=[{'test': {'value': 'John Doe'}}]

result

And here you can see that in swagger it does add the field key to the example but not the value.

What I see

{
  "driver_fullname": "string"
}

Screenshot 2024-02-02 at 11 28 21 AM Screenshot 2024-02-02 at 11 28 38 AM

What I expected

{
  "driver_fullname": "John Doe"
}

shaunjl avatar Feb 02 '24 17:02 shaunjl

You can refer to the documentation here:

https://luolingchun.github.io/flask-openapi3/v3.x/Usage/Model_Config/

luolingchun avatar Feb 03 '24 03:02 luolingchun