Skip to content

Commit

Permalink
fix(schema): rename type_ to type in schema
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jul 17, 2024
1 parent 537e595 commit 2b04764
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
2 changes: 2 additions & 0 deletions data_model/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"type": "AssetDefinitionId"
},
{
"name": "type_",
"name": "type",
"type": "AssetType"
},
{
Expand Down Expand Up @@ -2492,7 +2492,7 @@
"type": "AssetDefinitionId"
},
{
"name": "type_",
"name": "type",
"type": "AssetType"
},
{
Expand Down
12 changes: 11 additions & 1 deletion schema/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ impl FromVariant for IntoSchemaVariant {
}
}

#[derive(FromField, Default)]
#[darling(default, attributes(serde))]
struct SerdeFieldOpts {
rename: Option<String>,
}

type IntoSchemaFields = darling::ast::Fields<IntoSchemaField>;

#[derive(Debug, Clone)]
Expand All @@ -140,7 +146,11 @@ struct IntoSchemaField {

impl FromField for IntoSchemaField {
fn from_field(field: &syn::Field) -> darling::Result<Self> {
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)?;

Expand Down

0 comments on commit 2b04764

Please sign in to comment.