Skip to content
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

Update to syn 2.0, and serde_derive_internals 0.29 #269

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ dyn-clone = "1.0"

chrono = { version = "0.4", default-features = false, optional = true }
indexmap = { version = "1.2", features = ["serde-1"], optional = true }
indexmap2 = { version = "2.0", features = ["serde"], optional = true, package = "indexmap" }
indexmap2 = { version = "2.0", features = [
"serde",
], optional = true, package = "indexmap" }
either = { version = "1.3", default-features = false, optional = true }
uuid08 = { version = "0.8", default-features = false, optional = true, package = "uuid" }
uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" }
Expand Down
24 changes: 12 additions & 12 deletions schemars/tests/ui/invalid_validation_attrs.stderr
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
error: expected validate regex attribute to be a string: `regex = "..."`
--> $DIR/invalid_validation_attrs.rs:4:39
--> tests/ui/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
--> tests/ui/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
--> tests/ui/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
error: schemars attribute cannot contain both `min` and `equal`
--> tests/ui/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
--> tests/ui/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
error: schemars attribute cannot contain both `regex` and `contains`
--> tests/ui/invalid_validation_attrs.rs:26:9
|
26 | contains = "bar",
| ^^^^^^^^

error: duplicate schemars attribute `regex`
--> $DIR/invalid_validation_attrs.rs:27:9
--> tests/ui/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
--> tests/ui/invalid_validation_attrs.rs:29:9
|
29 | email,
| ^^^^^

error: schemars attribute cannot contain both `phone` and `url`
--> $DIR/invalid_validation_attrs.rs:30:9
--> tests/ui/invalid_validation_attrs.rs:30:9
|
30 | url
| ^^^

error[E0425]: cannot find value `foo` in this scope
--> $DIR/invalid_validation_attrs.rs:12:17
--> tests/ui/invalid_validation_attrs.rs:12:17
|
12 | regex = "foo",
| ^^^^^ not found in this scope
2 changes: 1 addition & 1 deletion schemars/tests/validate_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Struct<'a> {
#[schemars(inner(length(min = 5, max = 100)))]
array_str_length: [&'a str; 2],
#[schemars(inner(contains(pattern = "substring...")))]
slice_str_contains: &'a[&'a str],
slice_str_contains: &'a [&'a str],
#[schemars(inner(regex = "STARTS_WITH_HELLO"))]
vec_str_regex: Vec<String>,
#[schemars(inner(length(min = 1, max = 100)))]
Expand Down
4 changes: 2 additions & 2 deletions schemars_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["extra-traits"] }
serde_derive_internals = "0.26.0"
syn = { version = "2.0", features = ["extra-traits"] }
serde_derive_internals = "0.29.0"

[dev-dependencies]
pretty_assertions = "1.2.1"
8 changes: 4 additions & 4 deletions schemars_derive/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Field<'a> {
}

impl<'a> Container<'a> {
pub fn from_ast(item: &'a syn::DeriveInput) -> Result<Container<'a>, Vec<syn::Error>> {
pub fn from_ast(item: &'a syn::DeriveInput) -> Result<Container<'a>, syn::Error> {
let ctxt = Ctxt::new();
let result = serde_ast::Container::from_ast(&ctxt, item, Derive::Deserialize)
.ok_or(())
Expand All @@ -48,7 +48,7 @@ impl<'a> Container<'a> {
.map(|_| result.expect("from_ast set no errors on Ctxt, so should have returned Ok"))
}

pub fn name(&self) -> String {
pub fn name(&self) -> &str {
self.serde_attrs.name().deserialize_name()
}

Expand All @@ -64,7 +64,7 @@ impl<'a> Container<'a> {
}

impl<'a> Variant<'a> {
pub fn name(&self) -> String {
pub fn name(&self) -> &str {
self.serde_attrs.name().deserialize_name()
}

Expand All @@ -74,7 +74,7 @@ impl<'a> Variant<'a> {
}

impl<'a> Field<'a> {
pub fn name(&self) -> String {
pub fn name(&self) -> &str {
self.serde_attrs.name().deserialize_name()
}
}
18 changes: 10 additions & 8 deletions schemars_derive/src/attr/doc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syn::{Attribute, Lit::Str, Meta::NameValue, MetaNameValue};
use syn::Attribute;

pub fn get_title_and_desc_from_doc(attrs: &[Attribute]) -> (Option<String>, Option<String>) {
let doc = match get_doc(attrs) {
Expand Down Expand Up @@ -35,16 +35,18 @@ fn get_doc(attrs: &[Attribute]) -> Option<String> {
let attrs = attrs
.iter()
.filter_map(|attr| {
if !attr.path.is_ident("doc") {
if !attr.path().is_ident("doc") {
return None;
}

let meta = attr.parse_meta().ok()?;
if let NameValue(MetaNameValue { lit: Str(s), .. }) = meta {
return Some(s.value());
}

None
let syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(litstr),
..
}) = &attr.meta.require_name_value().ok()?.value
else {
return None;
};
Some(litstr.value())
})
.collect::<Vec<_>>();

Expand Down
Loading
Loading