Skip to content

Commit

Permalink
remove support for "skip_serializing", "skip_deserializing" and "skip…
Browse files Browse the repository at this point in the history
…_serializing_if"
  • Loading branch information
NyxCode committed Jan 24, 2024
1 parent 4c5c194 commit 3bc5295
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ Supported serde attributes:
- `content`
- `untagged`
- `skip`
- `skip_serializing`
- `skip_deserializing`
- `skip_serializing_if = "Option::is_none"`
- `flatten`
- `default`

Note: `skip_serializing` and `skip_deserializing` are ignored. If you with to exclude a field
from the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` instead.

When ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.

### contributing
Expand Down
2 changes: 1 addition & 1 deletion example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ enum InlineComplexEnum {
#[serde(rename_all = "camelCase")]
#[ts(export)]
struct ComplexStruct {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub string_tree: Option<Rc<BTreeSet<String>>>,
}
3 changes: 0 additions & 3 deletions macros/src/attr/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ impl_parse! {
SerdeFieldAttr(input, out) {
"rename" => out.0.rename = Some(parse_assign_str(input)?),
"skip" => out.0.skip = true,
"skip_serializing" => out.0.skip = true,
"skip_deserializing" => out.0.skip = true,
"skip_serializing_if" => out.0.optional = parse_assign_str(input)? == *"Option::is_none",
"flatten" => out.0.flatten = true,
// parse #[serde(default)] to not emit a warning
"default" => {
Expand Down
2 changes: 0 additions & 2 deletions macros/src/attr/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@ impl_parse! {
"rename" => out.0.rename = Some(parse_assign_str(input)?),
"rename_all" => out.0.rename_all = Some(parse_assign_inflection(input)?),
"skip" => out.0.skip = true,
"skip_serializing" => out.0.skip = true,
"skip_deserializing" => out.0.skip = true,
}
}
6 changes: 3 additions & 3 deletions ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@
//! - `content`
//! - `untagged`
//! - `skip`
//! - `skip_serializing`
//! - `skip_deserializing`
//! - `skip_serializing_if = "Option::is_none"`
//! - `flatten`
//! - `default`
//!
//! Note: `skip_serializing` and `skip_deserializing` are ignored. If you with to exclude a field
//! from the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` instead.
//!
//! When ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.
//!
//! ## contributing
Expand Down
6 changes: 1 addition & 5 deletions ts-rs/tests/optional_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ use ts_rs::TS;
struct Optional {
#[ts(optional)]
a: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
b: Option<String>,
b: Option<String>
}

#[test]
fn test() {
#[cfg(not(feature = "serde-compat"))]
assert_eq!(Optional::inline(), "{ a?: number, b: string | null, }");
#[cfg(feature = "serde-compat")]
assert_eq!(Optional::inline(), "{ a?: number, b?: string, }")
}

0 comments on commit 3bc5295

Please sign in to comment.