From 2b04764c0508f2449c7ee95cd1c79178340047d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Ver=C5=A1i=C4=87?= Date: Wed, 17 Jul 2024 11:10:47 +0200 Subject: [PATCH] fix(schema): rename `type_` to `type` in schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marin Veršić --- core/src/block.rs | 2 +- data_model/src/asset.rs | 2 ++ docs/source/references/schema.json | 4 ++-- schema/derive/src/lib.rs | 12 +++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/block.rs b/core/src/block.rs index 6ed87ce18cc..4a9fc6e1630 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -428,7 +428,7 @@ mod valid { if let Err(error) = Self::validate_header(&block, topology, genesis_account, state_block) { - return WithEvents::new(Err((block, error.into()))); + return WithEvents::new(Err((block, error))); } if let Err(error) = diff --git a/data_model/src/asset.rs b/data_model/src/asset.rs index fcdeb50f63b..81772340b3e 100644 --- a/data_model/src/asset.rs +++ b/data_model/src/asset.rs @@ -114,6 +114,7 @@ mod model { pub id: AssetDefinitionId, /// Type of [`AssetValue`] #[getset(get_copy = "pub")] + #[serde(rename = "type")] pub type_: AssetType, /// Is the asset mintable #[getset(get_copy = "pub")] @@ -162,6 +163,7 @@ mod model { /// The identification associated with the asset definition builder. pub id: AssetDefinitionId, /// The type value associated with the asset definition builder. + #[serde(rename = "type")] pub type_: AssetType, /// The mintablility associated with the asset definition builder. pub mintable: Mintable, diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 41442085923..e6a73f5bedc 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -244,7 +244,7 @@ "type": "AssetDefinitionId" }, { - "name": "type_", + "name": "type", "type": "AssetType" }, { @@ -2492,7 +2492,7 @@ "type": "AssetDefinitionId" }, { - "name": "type_", + "name": "type", "type": "AssetType" }, { diff --git a/schema/derive/src/lib.rs b/schema/derive/src/lib.rs index ee32e9bcf8c..9ca142f5073 100644 --- a/schema/derive/src/lib.rs +++ b/schema/derive/src/lib.rs @@ -129,6 +129,12 @@ impl FromVariant for IntoSchemaVariant { } } +#[derive(FromField, Default)] +#[darling(default, attributes(serde))] +struct SerdeFieldOpts { + rename: Option, +} + type IntoSchemaFields = darling::ast::Fields; #[derive(Debug, Clone)] @@ -140,7 +146,11 @@ struct IntoSchemaField { impl FromField for IntoSchemaField { fn from_field(field: &syn::Field) -> darling::Result { - let ident = field.ident.clone(); + let SerdeFieldOpts { rename } = SerdeFieldOpts::from_field(field).unwrap_or_default(); + + let ident = rename + .map(|rename| syn::Ident::new(&rename, Span::call_site())) + .or_else(|| field.ident.clone()); let ty = field.ty.clone(); let codec_attrs = CodecAttributes::from_attributes(&field.attrs)?;