Allow setting validation attributes via #[schemars(...)]

This commit is contained in:
Graham Esau 2021-04-18 22:17:53 +01:00
parent c013052f59
commit 7914593d89
17 changed files with 607 additions and 99 deletions

View file

@ -22,7 +22,7 @@ error: duplicate serde attribute `deny_unknown_fields`
8 | #[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
| ^^^^^^^^^^^^^^^^^^^
error: unknown schemars container attribute `foo`
error: unknown schemars attribute `foo`
--> $DIR/invalid_attrs.rs:8:25
|
8 | #[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]

View file

@ -0,0 +1,9 @@
use schemars::JsonSchema;
#[derive(JsonSchema)]
pub struct Struct1(#[validate(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
#[derive(JsonSchema)]
pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
fn main() {}

View file

@ -0,0 +1,29 @@
error: expected validate regex attribute to be a string: `regex = "..."`
--> $DIR/invalid_validation_attrs.rs:4:39
|
4 | pub struct Struct1(#[validate(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
| ^
error: unknown schemars attribute `foo`
--> $DIR/invalid_validation_attrs.rs:7:42
|
7 | pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
| ^^^
error: expected schemars regex attribute to be a string: `regex = "..."`
--> $DIR/invalid_validation_attrs.rs:7:39
|
7 | pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
| ^
error: schemars attribute cannot contain both `equal` and `min`
--> $DIR/invalid_validation_attrs.rs:7:63
|
7 | pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
| ^^^^^^^^^
error: unknown item in schemars length attribute
--> $DIR/invalid_validation_attrs.rs:7:74
|
7 | pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
| ^^^