Skip to content

Conversation

@stuarteberg
Copy link
Contributor

The FAQ explains that one could (in theory) write a schema in which default values aren't valid under their own schema, and then goes on to present some example code that would allow such a use-case.

Fair enough, but I think most users would rather have an example that actually does validate the defaults. Plus, if the default values are added to the instance before validation, then entire objects can be provided with default contents, even if the object was missing from the instance entirely. (The updated FAQ text in this PR provides an example.)

@stuarteberg
Copy link
Contributor Author

In case it's helpful, you can view a pretty version of the new doc text here:
http://stuarteberg.github.io/jsonschema/faq.html#why-doesn-t-my-schema-that-has-a-default-property-actually-set-the-default-on-my-instance

 - Slight tweak to the code to enable validation (and recursive default population) of default properties.
 - Provided a hint regarding recursive population of default object properties.
@stuarteberg stuarteberg force-pushed the fix-docs-faq-default-property branch from 419244a to ea8ffcb Compare October 28, 2015 03:01
@Julian
Copy link
Member

Julian commented Oct 28, 2015

Cool, thanks! Doc improvements are very much appreciated. I haven't read through this yet, but FWIW, I really don't recommend doing default setting during validation at all -- I forget whether that's mentioned in that part of the FAQ.

But I'll have a read through, thanks again!

@stuarteberg
Copy link
Contributor Author

FWIW, I really don't recommend doing default setting during validation at all

Indeed, your text mentions that, and I didn't change it (I only added text). I know default-setting isn't great for all use-cases, but I still really appreciate that you gave an example in the FAQ. My only problem with the example code was that it didn't work with nested objects out-of-the-box. By swapping a few lines, now it does.

@Julian
Copy link
Member

Julian commented Nov 1, 2015

Cool, looks good, appreciated.

Julian added a commit that referenced this pull request Nov 1, 2015
docs: faq: Updates to extend_with_default() example
@Julian Julian merged commit 3eb5de8 into python-jsonschema:master Nov 1, 2015
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.

2 participants