-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Set "default" on generated schemas #6
Comments
GREsau
added a commit
that referenced
this issue
Dec 8, 2019
Implemented in v0.6, now published to crates.io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Received via email:
JSON Schema "default" keyword reference: https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.2
Example 1
The generated schema for
MyStruct
should be:Note that we set
default
on the properties, not on the top-level schema forMyStruct
.Example 2
It gets more complicated when we use
#[serde(default)]
on fields as well as the struct, e.g.The generated schema for
MyStruct2
should be:Example 3
Note that the default for the
my_struct2
property has different property defaults (false/0) than the defaults in theMyStruct2
definition (true/6). This is because:{}
toMyStruct
results inMyStruct { my_int: 0, my_bool: false, my_struct2: MyStruct2 { my_int: 0, my_bool: false } }
{"my_struct2": {}}
results inMyStruct { my_int: 0, my_bool: false, my_struct2: MyStruct2 { my_int: 6, my_bool: true } }
The text was updated successfully, but these errors were encountered: