From a3e0f211694df59ddaf3c2645a0ce93f700c13c8 Mon Sep 17 00:00:00 2001 From: NyxCode Date: Thu, 25 Jan 2024 17:41:56 +0100 Subject: [PATCH] Remove support for "skip_serializing", "skip_deserializing" and "skip_serializing_if" (#204) * remove support for "skip_serializing", "skip_deserializing" and "skip_serializing_if" * add changelog * fix typo --- CHANGELOG.md | 5 +++++ README.md | 6 +++--- example/src/lib.rs | 2 +- macros/src/attr/field.rs | 3 --- macros/src/attr/variant.rs | 2 -- ts-rs/src/lib.rs | 6 +++--- ts-rs/tests/optional_field.rs | 6 +----- 7 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..fce6d7a25 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# master + +- Remove support for "skip_serializing", "skip_serializing_if" and "skip_deserializing". + - Initially supporting these by skipping a field was a mistake. If a user wishes to skip a field, they can still + annotate it with `#[ts(skip)]` \ No newline at end of file diff --git a/README.md b/README.md index af2291ec3..158a86c60 100644 --- a/README.md +++ b/README.md @@ -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 wish 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 diff --git a/example/src/lib.rs b/example/src/lib.rs index dfdbd8155..81e847acc 100644 --- a/example/src/lib.rs +++ b/example/src/lib.rs @@ -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>>, } diff --git a/macros/src/attr/field.rs b/macros/src/attr/field.rs index 0c91b1c99..aab124add 100644 --- a/macros/src/attr/field.rs +++ b/macros/src/attr/field.rs @@ -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" => { diff --git a/macros/src/attr/variant.rs b/macros/src/attr/variant.rs index 1f490db45..74a3c282e 100644 --- a/macros/src/attr/variant.rs +++ b/macros/src/attr/variant.rs @@ -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, } } diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 464e44cb5..66dd45199 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -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 wish 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 diff --git a/ts-rs/tests/optional_field.rs b/ts-rs/tests/optional_field.rs index 807e9daf1..4912584e5 100644 --- a/ts-rs/tests/optional_field.rs +++ b/ts-rs/tests/optional_field.rs @@ -7,14 +7,10 @@ use ts_rs::TS; struct Optional { #[ts(optional)] a: Option, - #[serde(skip_serializing_if = "Option::is_none")] - b: Option, + b: Option } #[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, }") }