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" (#204)

* remove support for "skip_serializing", "skip_deserializing" and "skip_serializing_if"

* add changelog

* fix typo
  • Loading branch information
NyxCode authored Jan 25, 2024
1 parent d6b862f commit a3e0f21
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)]`
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 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
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 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
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 a3e0f21

Please sign in to comment.