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

Remove support for "skip_serializing", "skip_deserializing" and "skip_serializing_if" #204

Merged
merged 3 commits into from
Jan 25, 2024
Merged
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
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, }")
}
Loading