Skip to content

Include generated examples#16

Open
bvanelli wants to merge 2 commits intobrokenloop:masterfrom
bvanelli:14-include-generate-examples
Open

Include generated examples#16
bvanelli wants to merge 2 commits intobrokenloop:masterfrom
bvanelli:14-include-generate-examples

Conversation

@bvanelli
Copy link
Copy Markdown

@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
Copy Markdown
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