Emit compilation errors for duplicate validation attributes
This commit is contained in:
parent
af69a8ea11
commit
605db3bba8
7 changed files with 230 additions and 90 deletions
|
@ -6,4 +6,30 @@ pub struct Struct1(#[validate(regex = 0, foo, length(min = 1, equal = 2, bar))]
|
|||
#[derive(JsonSchema)]
|
||||
pub struct Struct2(#[schemars(regex = 0, foo, length(min = 1, equal = 2, bar))] String);
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct3(
|
||||
#[validate(
|
||||
regex = "foo",
|
||||
contains = "bar",
|
||||
regex(path = "baz"),
|
||||
phone,
|
||||
email,
|
||||
url
|
||||
)]
|
||||
String,
|
||||
);
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct4(
|
||||
#[schemars(
|
||||
regex = "foo",
|
||||
contains = "bar",
|
||||
regex(path = "baz"),
|
||||
phone,
|
||||
email,
|
||||
url
|
||||
)]
|
||||
String,
|
||||
);
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -20,10 +20,40 @@ 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);
|
||||
| ^^^
|
||||
|
||||
error: schemars attribute cannot contain both `contains` and `regex`
|
||||
--> $DIR/invalid_validation_attrs.rs:26:9
|
||||
|
|
||||
26 | contains = "bar",
|
||||
| ^^^^^^^^
|
||||
|
||||
error: duplicate schemars attribute `regex`
|
||||
--> $DIR/invalid_validation_attrs.rs:27:9
|
||||
|
|
||||
27 | regex(path = "baz"),
|
||||
| ^^^^^
|
||||
|
||||
error: schemars attribute cannot contain both `phone` and `email`
|
||||
--> $DIR/invalid_validation_attrs.rs:29:9
|
||||
|
|
||||
29 | email,
|
||||
| ^^^^^
|
||||
|
||||
error: schemars attribute cannot contain both `phone` and `url`
|
||||
--> $DIR/invalid_validation_attrs.rs:30:9
|
||||
|
|
||||
30 | url
|
||||
| ^^^
|
||||
|
||||
error[E0425]: cannot find value `foo` in this scope
|
||||
--> $DIR/invalid_validation_attrs.rs:12:17
|
||||
|
|
||||
12 | regex = "foo",
|
||||
| ^^^^^ not found in this scope
|
||||
|
|
|
@ -4,4 +4,4 @@ error: JsonSchema_repr: missing #[repr(...)] attribute
|
|||
3 | #[derive(JsonSchema_repr)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
= note: this error originates in the derive macro `JsonSchema_repr` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
|
|
@ -4,4 +4,4 @@ error: This argument to `schema_for!` is not a type - did you mean to use `schem
|
|||
4 | let _schema = schema_for!(123);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
= note: this error originates in the macro `schema_for` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
|
|
@ -62,12 +62,14 @@ pub struct Struct2 {
|
|||
min_max: f32,
|
||||
#[schemars(range(min = "MIN", max = "MAX"))]
|
||||
min_max2: f32,
|
||||
#[validate(regex = "overridden")]
|
||||
#[schemars(regex = "STARTS_WITH_HELLO")]
|
||||
regex_str1: String,
|
||||
#[schemars(regex(path = "STARTS_WITH_HELLO"))]
|
||||
regex_str2: String,
|
||||
#[schemars(regex(pattern = r"^\d+$"))]
|
||||
regex_str3: String,
|
||||
#[validate(regex = "overridden")]
|
||||
#[schemars(contains = "substring...")]
|
||||
contains_str1: String,
|
||||
#[schemars(contains(pattern = "substring..."))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue