Skip to content

Commit

Permalink
new: More serde integration. (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Aug 31, 2024
1 parent e60c868 commit 0cdd6d3
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 53 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
105 changes: 64 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 3 additions & 0 deletions crates/macros/src/common/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub struct FieldSerdeArgs {
pub skip: bool,
pub skip_deserializing: bool,
pub skip_serializing: bool,

// variant
pub untagged: bool,
}

impl FieldSerdeArgs {
Expand Down
10 changes: 8 additions & 2 deletions crates/macros/src/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub rename_all: Option<String>,
pub rename_all_fields: Option<String>,

// enum
pub content: Option<String>,
Expand All @@ -39,6 +41,7 @@ pub struct MacroArgs {
// serde
pub rename: Option<String>,
pub rename_all: Option<String>,
pub rename_all_fields: Option<String>,
pub serde: SerdeMeta,
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 });
}
}
Expand Down
Loading

0 comments on commit 0cdd6d3

Please sign in to comment.