-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Read #[validate(...)] attributes #78
Conversation
This is great, thank you! Are there plans to support tuple/newtype structs as well? Also, would it be possible to support inline patterns with the |
Yep!
Yeah I'd like to do that - the validator crate that these attributes are based off of doesn't support inline patterns, although I did open a feature request for it recently: Keats/validator#149 |
Is it important for the feature be added to the |
Fixes #12
This PR makes
#[derive(JsonSchema)]
consume#[validate(...)]
attributes that would typically be set when using the validator crate. In particular, it accepts:#[validate(email)]
/#[validate(phone)]
/#[validate(url)]
- sets the schema'sformat
to "email"/"phone"/"uri" respectively#[validate(length(min = 1, max = 100)]
/#[validate(length(equal = 100)]
- for string schemas, sets theminLength
/maxLength
properties. For Array schemas, sets theminItems
/maxItems
properties.#[validate(range(min = 1, max = 100)]
- for numbers schemas, sets theminimum
/maximum
properties#[validate(regex = "path::to::regex"])
- for string schemas, sets thepattern
property#[validate(contains = "str"])
- for string schemas, sets the regex-escaped value to thepattern
property (unless regex is also used). For object schemas, adds the value to the "required" property#[validate(required)]
/#[validate(required_nested)]
creates a schema as though the field was not anOption
These attributes are only consumed on structs with named fields - not on tuple structs or newtype structs.
This PR does NOT handle these attributes available in the validator crate: