Ignore bound
set in serde attrs
This commit is contained in:
parent
104dccca50
commit
4754a13fb3
1 changed files with 9 additions and 5 deletions
|
@ -20,6 +20,7 @@ pub(crate) static SERDE_KEYWORDS: &[&str] = &[
|
||||||
"flatten",
|
"flatten",
|
||||||
"remote",
|
"remote",
|
||||||
"transparent",
|
"transparent",
|
||||||
|
// Special case - `bound` is removed from serde attrs, so is only respected when present in schemars attr.
|
||||||
"bound",
|
"bound",
|
||||||
// Special cases - `with`/`serialize_with` are passed to serde but not copied from schemars attrs to serde attrs.
|
// Special cases - `with`/`serialize_with` are passed to serde but not copied from schemars attrs to serde attrs.
|
||||||
// This is because we want to preserve any serde attribute's `serialize_with` value to determine whether the field's
|
// This is because we want to preserve any serde attribute's `serialize_with` value to determine whether the field's
|
||||||
|
@ -94,7 +95,10 @@ fn process_attrs(ctxt: &Ctxt, attrs: &mut Vec<Attribute>) {
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if let Ok(i) = get_meta_ident(&ctxt, &meta) {
|
if let Ok(i) = get_meta_ident(&ctxt, &meta) {
|
||||||
if !schemars_meta_names.contains(&i) && SERDE_KEYWORDS.contains(&i.as_ref()) {
|
if !schemars_meta_names.contains(&i)
|
||||||
|
&& SERDE_KEYWORDS.contains(&i.as_ref())
|
||||||
|
&& i != "bound"
|
||||||
|
{
|
||||||
serde_meta.push(meta);
|
serde_meta.push(meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +170,10 @@ mod tests {
|
||||||
#[misc]
|
#[misc]
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
/// blah blah blah
|
/// blah blah blah
|
||||||
#[serde(skip_serializing_if = "some_fn")]
|
#[serde(skip_serializing_if = "some_fn", bound = "removed")]
|
||||||
field1: i32,
|
field1: i32,
|
||||||
#[serde(serialize_with = "se", deserialize_with = "de")]
|
#[serde(serialize_with = "se", deserialize_with = "de")]
|
||||||
#[schemars(with = "with")]
|
#[schemars(with = "with", bound = "bound")]
|
||||||
field2: i32,
|
field2: i32,
|
||||||
#[schemars(skip)]
|
#[schemars(skip)]
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
|
@ -184,7 +188,7 @@ mod tests {
|
||||||
#[doc = r" blah blah blah"]
|
#[doc = r" blah blah blah"]
|
||||||
#[serde(skip_serializing_if = "some_fn")]
|
#[serde(skip_serializing_if = "some_fn")]
|
||||||
field1: i32,
|
field1: i32,
|
||||||
#[schemars(with = "with")]
|
#[schemars(with = "with", bound = "bound")]
|
||||||
#[serde(serialize_with = "se")]
|
#[serde(serialize_with = "se")]
|
||||||
field2: i32,
|
field2: i32,
|
||||||
#[schemars(skip)]
|
#[schemars(skip)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue