diff --git a/CHANGELOG.md b/CHANGELOG.md index b3083b8..05a3596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## Unreleased + +#### 🚀 Updates + +- Added support for `#[serde(deny_unknown_fields)]` to struct and enum containers. +- Added support for `#[serde(rename_all_fields)]` to enum containers. +- Added support for `#[serde(untagged)]` to enum variants. + +#### ⚙️ Internal + +- Updated dependencies. + ## 0.17.3 #### 🐞 Fixes diff --git a/Cargo.lock b/Cargo.lock index 7728610..df4876c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -174,7 +174,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", "syn_derive", ] @@ -373,7 +373,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -384,7 +384,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -596,7 +596,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -809,9 +809,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -950,7 +950,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1079,7 +1079,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1250,9 +1250,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1362,9 +1362,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.5" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", @@ -1400,7 +1400,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "windows-registry", ] [[package]] @@ -1493,9 +1493,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.35.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", "borsh", @@ -1677,7 +1677,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1752,29 +1752,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.208" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.208" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.125" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "indexmap", "itoa", @@ -1849,7 +1849,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -1991,9 +1991,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.74" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -2009,7 +2009,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2017,6 +2017,9 @@ name = "sync_wrapper" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "tap" @@ -2094,7 +2097,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2231,7 +2234,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", ] [[package]] @@ -2385,7 +2388,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -2419,7 +2422,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2458,6 +2461,36 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -2615,16 +2648,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index b7e64cb..271c8b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,18 +4,18 @@ members = ["crates/*"] [workspace.dependencies] chrono = "0.4.38" -indexmap = "2.4.0" +indexmap = "2.5.0" miette = "7.2.0" regex = "1.10.6" relative-path = "1.9.3" -reqwest = { version = "0.12.5", default-features = false } +reqwest = { version = "0.12.7", default-features = false } rpkl = "0.3.1" -rust_decimal = "1.35.0" +rust_decimal = "1.36.0" semver = "1.0.23" -serde = { version = "1.0.208", features = ["derive"] } -serde_json = "1.0.125" +serde = { version = "1.0.209", features = ["derive"] } +serde_json = "1.0.127" serde_yaml = "0.9.34" -starbase_sandbox = "0.7.2" +starbase_sandbox = "0.7.0" toml = "0.8.19" tracing = "0.1.40" url = "2.5.2" diff --git a/crates/macros/Cargo.toml b/crates/macros/Cargo.toml index 89e6230..1f8d089 100644 --- a/crates/macros/Cargo.toml +++ b/crates/macros/Cargo.toml @@ -17,8 +17,8 @@ proc-macro = true convert_case = "0.6.0" darling = "0.20.10" proc-macro2 = "1.0.86" -quote = "1.0.36" -syn = { version = "2.0.74", features = ["full"] } +quote = "1.0.37" +syn = { version = "2.0.77", features = ["full"] } [features] default = [] diff --git a/crates/macros/src/common/field.rs b/crates/macros/src/common/field.rs index 5f14aae..92c885d 100644 --- a/crates/macros/src/common/field.rs +++ b/crates/macros/src/common/field.rs @@ -20,6 +20,9 @@ pub struct FieldSerdeArgs { pub skip: bool, pub skip_deserializing: bool, pub skip_serializing: bool, + + // variant + pub untagged: bool, } impl FieldSerdeArgs { diff --git a/crates/macros/src/common/macros.rs b/crates/macros/src/common/macros.rs index 9c071a1..4a95963 100644 --- a/crates/macros/src/common/macros.rs +++ b/crates/macros/src/common/macros.rs @@ -10,10 +10,12 @@ use syn::{Attribute, Data, DeriveInput, ExprPath, Fields}; #[darling(default, allow_unknown_fields, attributes(serde))] pub struct ContainerSerdeArgs { pub default: bool, + pub deny_unknown_fields: bool, // struct pub rename: Option, pub rename_all: Option, + pub rename_all_fields: Option, // enum pub content: Option, @@ -39,6 +41,7 @@ pub struct MacroArgs { // serde pub rename: Option, pub rename_all: Option, + pub rename_all_fields: Option, pub serde: SerdeMeta, } @@ -113,7 +116,10 @@ impl<'l> Macro<'l> { } }, Data::Enum(data) => { - base_casing_format + args.rename_all_fields + .as_deref() + .or(serde_args.rename_all_fields.as_deref()) + .or(base_casing_format) .unwrap_or("kebab-case") .clone_into(&mut casing_format); @@ -183,7 +189,7 @@ impl<'l> Macro<'l> { Container::NamedStruct { .. } => { meta.push(quote! { default }); - if !self.args.allow_unknown_fields { + if self.serde_args.deny_unknown_fields || !self.args.allow_unknown_fields { meta.push(quote! { deny_unknown_fields }); } } diff --git a/crates/macros/src/common/variant.rs b/crates/macros/src/common/variant.rs index 58b3acb..3c19897 100644 --- a/crates/macros/src/common/variant.rs +++ b/crates/macros/src/common/variant.rs @@ -35,6 +35,7 @@ pub struct VariantArgs { pub skip: bool, pub skip_deserializing: bool, pub skip_serializing: bool, + pub untagged: bool, } pub struct Variant<'l> { @@ -135,7 +136,9 @@ impl<'l> Variant<'l> { &self.tagged_format }; - let untagged = matches!(tagged_format, TaggedFormat::Untagged); + let untagged = matches!(tagged_format, TaggedFormat::Untagged) + || self.args.untagged + || self.serde_args.untagged; let partial = self.is_nested(); let inner = match &self.value.fields { diff --git a/crates/macros/src/config_enum/mod.rs b/crates/macros/src/config_enum/mod.rs index 723c66f..7be807b 100644 --- a/crates/macros/src/config_enum/mod.rs +++ b/crates/macros/src/config_enum/mod.rs @@ -17,6 +17,7 @@ pub struct ConfigEnumArgs { // serde rename: Option, rename_all: Option, + rename_all_fields: Option, } // #[derive(ConfigEnum)] @@ -40,8 +41,10 @@ pub fn macro_impl(item: TokenStream) -> TokenStream { .unwrap_or(enum_name.to_string()); let casing_format = args - .rename_all + .rename_all_fields .as_deref() + .or(args.rename_all.as_deref()) + .or(serde_args.rename_all_fields.as_deref()) .or(serde_args.rename_all.as_deref()) .unwrap_or("kebab-case"); diff --git a/crates/types/src/schema.rs b/crates/types/src/schema.rs index b96e304..0cc8371 100644 --- a/crates/types/src/schema.rs +++ b/crates/types/src/schema.rs @@ -190,6 +190,7 @@ impl From for SchemaType { impl Schematic for Schema {} +#[cfg(feature = "serde")] fn is_false(value: &bool) -> bool { !value }