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

Add Schema.from_dict for generating schemas from dicts #1322

Merged
merged 2 commits into from Aug 11, 2019
Merged

Conversation

sloria
Copy link
Member

@sloria sloria commented Jul 21, 2019

close #1312

@sloria sloria requested a review from deckar01 July 21, 2019 22:40
@sloria sloria requested a review from lafrech July 31, 2019 13:42
Copy link
Member

@lafrech lafrech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Maybe another argument could be added to pass meta options in the call to from_dict but it can be added later on if someone needs it.

@sloria
Copy link
Member Author

sloria commented Aug 11, 2019

I wanted to keep the API surface to a minimum here. If a user needs to customize Meta, they can declare a class.

@sloria sloria changed the title [WIP] Add Schema.from_dict for generating schemas from dicts Add Schema.from_dict for generating schemas from dicts Aug 11, 2019
@sloria sloria added this to the 3.0 milestone Aug 11, 2019
@sloria sloria merged commit 8cf1fb8 into dev Aug 11, 2019
@sloria sloria deleted the from_dict branch August 11, 2019 21:28
@lafrech
Copy link
Member

lafrech commented Oct 2, 2019

Note: from_dict only generates fields for top-level fields in the dict. It does not create Nested fields automatically: https://stackoverflow.com/questions/58190523/how-to-use-schema-from-dict-for-nested-dictionaries.

@sloria
Copy link
Member Author

sloria commented Oct 2, 2019

It was not the intention to automagically create Nested and List fields for dicts and lists. I don't think it's necessary nor intuitive, but I'm not closed off to the idea if others think it's the way to go.

@hardikkat24
Copy link

@sloria Wouldn't it be great for fields.Nested() to accept both dictionary and Schema? Thanks!

@sloria
Copy link
Member Author

sloria commented Apr 2, 2021

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 a way to generate a Schema from a dictionary
3 participants