Allow regex(path = ...)
value to be a non-string expression (#328)
This commit is contained in:
parent
dc1245bbd8
commit
66f17fff0e
5 changed files with 64 additions and 69 deletions
|
@ -1,10 +1,14 @@
|
|||
use schemars::JsonSchema;
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct1(#[validate(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
|
||||
// FIXME validation attrs like `email` should be disallowed non structs/enums/variants
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
|
||||
#[validate(email)]
|
||||
pub struct Struct1(#[validate(regex, foo, length(min = 1, equal = 2, bar))] String);
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(email)]
|
||||
pub struct Struct2(#[schemars(regex, foo, length(min = 1, equal = 2, bar))] String);
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct3(
|
||||
|
|
|
@ -1,59 +1,53 @@
|
|||
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);
|
||||
| ^^^
|
||||
--> tests/ui/invalid_validation_attrs.rs:11:38
|
||||
|
|
||||
11 | pub struct Struct2(#[schemars(regex, 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: could not parse `regex` item in schemars attribute
|
||||
--> tests/ui/invalid_validation_attrs.rs:11:31
|
||||
|
|
||||
11 | pub struct Struct2(#[schemars(regex, 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);
|
||||
| ^^^^^
|
||||
--> tests/ui/invalid_validation_attrs.rs:11:59
|
||||
|
|
||||
11 | pub struct Struct2(#[schemars(regex, 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);
|
||||
| ^^^
|
||||
--> tests/ui/invalid_validation_attrs.rs:11:70
|
||||
|
|
||||
11 | pub struct Struct2(#[schemars(regex, foo, length(min = 1, equal = 2, bar))] String);
|
||||
| ^^^
|
||||
|
||||
error: schemars attribute cannot contain both `contains` and `regex`
|
||||
--> $DIR/invalid_validation_attrs.rs:26:9
|
||||
--> tests/ui/invalid_validation_attrs.rs:30:9
|
||||
|
|
||||
26 | contains = "bar",
|
||||
30 | contains = "bar",
|
||||
| ^^^^^^^^
|
||||
|
||||
error: duplicate schemars attribute `regex`
|
||||
--> $DIR/invalid_validation_attrs.rs:27:9
|
||||
--> tests/ui/invalid_validation_attrs.rs:31:9
|
||||
|
|
||||
27 | regex(path = "baz"),
|
||||
31 | regex(path = "baz"),
|
||||
| ^^^^^
|
||||
|
||||
error: schemars attribute cannot contain both `phone` and `email`
|
||||
--> $DIR/invalid_validation_attrs.rs:29:9
|
||||
--> tests/ui/invalid_validation_attrs.rs:33:9
|
||||
|
|
||||
29 | email,
|
||||
33 | email,
|
||||
| ^^^^^
|
||||
|
||||
error: schemars attribute cannot contain both `phone` and `url`
|
||||
--> $DIR/invalid_validation_attrs.rs:30:9
|
||||
--> tests/ui/invalid_validation_attrs.rs:34:9
|
||||
|
|
||||
30 | url
|
||||
34 | url
|
||||
| ^^^
|
||||
|
||||
error[E0425]: cannot find value `foo` in this scope
|
||||
--> $DIR/invalid_validation_attrs.rs:12:17
|
||||
--> tests/ui/invalid_validation_attrs.rs:16:17
|
||||
|
|
||||
12 | regex = "foo",
|
||||
16 | regex = "foo",
|
||||
| ^^^^^ not found in this scope
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct Struct {
|
|||
min_max: f32,
|
||||
#[validate(range(min = "MIN", max = "MAX"))]
|
||||
min_max2: f32,
|
||||
#[validate(regex = "STARTS_WITH_HELLO")]
|
||||
#[validate(regex = &*STARTS_WITH_HELLO)]
|
||||
regex_str1: String,
|
||||
#[validate(regex(path = "STARTS_WITH_HELLO", code = "foo"))]
|
||||
regex_str2: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue