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

Include generated examples #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bvanelli
Copy link

@bvanelli bvanelli commented Feb 9, 2023

It it's extremely nice to load examples when building an API, since the OpenAPI specification is going to contain an example value from the actual response. If you are building a validator for an actual object, you know more or less how the data should look like. Here are the relevant docs for this feature: https://fastapi.tiangolo.com/tutorial/schema-extra-example/

This MR adds another customizer to include the examples when generating the model. Here is a preview:

jsontopydantic

Of course, when presented with multiple options, it will pick the first:

image

Closes #14

Suggested and implemented during a Hackergarten: https://www.meetup.com/pt-BR/hackergarten-stuttgart/, thanks everyone who participated 😃

@bvanelli
Copy link
Author

@brokenloop what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to create example
1 participant