Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add examples to swagger #142

Open
shaunjl opened this issue Feb 2, 2024 · 1 comment
Open

How to add examples to swagger #142

shaunjl opened this issue Feb 2, 2024 · 1 comment
Labels

Comments

@shaunjl
Copy link

shaunjl commented Feb 2, 2024

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"
}
@luolingchun
Copy link
Owner

You can refer to the documentation here:

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

@github-actions github-actions bot added the Stale label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants