Skip to content

Commit

Permalink
fix(schema): rename type_ to type in schema (#4855)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic authored Jul 17, 2024
1 parent d971c1a commit 8557265
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def asset_definitions(self) -> Dict[str, str]:

asset_definitions = {}
for asset_def in asset_defs:
type_ = asset_def.get("type_")
type_ = asset_def.get("type")
if type_:
asset_definitions[asset_def["id"]] = type_
return asset_definitions
Expand Down
4 changes: 2 additions & 2 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"Register": {
"AssetDefinition": {
"id": "rose#wonderland",
"type_": "Numeric",
"type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
Expand Down Expand Up @@ -112,7 +112,7 @@
"Register": {
"AssetDefinition": {
"id": "cabbage#garden_of_live_flowers",
"type_": "Numeric",
"type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
Expand Down
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
22 changes: 11 additions & 11 deletions data_model/derive/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,29 @@ pub fn impl_id_eq_ord_hash(emitter: &mut Emitter, input: &syn::DeriveInput) -> T
quote! {
#identifiable_derive

impl #impl_generics ::core::cmp::PartialOrd for #name #ty_generics #where_clause where Self: crate::Identifiable {
impl #impl_generics ::core::cmp::PartialOrd for #name #ty_generics #where_clause where Self: Identifiable {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl #impl_generics ::core::cmp::Ord for #name #ty_generics #where_clause where Self: crate::Identifiable {
impl #impl_generics ::core::cmp::Ord for #name #ty_generics #where_clause where Self: Identifiable {
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
<Self as crate::Identifiable>::id(self).cmp(<Self as crate::Identifiable>::id(other))
<Self as Identifiable>::id(self).cmp(<Self as Identifiable>::id(other))
}
}

impl #impl_generics ::core::cmp::Eq for #name #ty_generics #where_clause where Self: crate::Identifiable {}
impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause where Self: crate::Identifiable {
impl #impl_generics ::core::cmp::Eq for #name #ty_generics #where_clause where Self: Identifiable {}
impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause where Self: Identifiable {
fn eq(&self, other: &Self) -> bool {
<Self as crate::Identifiable>::id(self) == <Self as crate::Identifiable>::id(other)
<Self as Identifiable>::id(self) == <Self as Identifiable>::id(other)
}
}

impl #impl_generics ::core::hash::Hash for #name #ty_generics #where_clause where Self: crate::Identifiable {
impl #impl_generics ::core::hash::Hash for #name #ty_generics #where_clause where Self: Identifiable {
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
<Self as crate::Identifiable>::id(self).hash(state)
<Self as Identifiable>::id(self).hash(state)
}
}
}
Expand All @@ -119,7 +119,7 @@ fn derive_identifiable(emitter: &mut Emitter, input: &IdDeriveInput) -> TokenStr
let (id_type, id_expr) = get_id_type(emitter, input);

quote! {
impl #impl_generics crate::Identifiable for #name #ty_generics #where_clause {
impl #impl_generics Identifiable for #name #ty_generics #where_clause {
type Id = #id_type;

#[inline]
Expand All @@ -142,8 +142,8 @@ fn get_id_type(emitter: &mut Emitter, input: &IdDeriveInput) -> (syn::Type, syn:
}
IdAttr::Transparent => {
return (
parse_quote! {<#ty as crate::Identifiable>::Id},
parse_quote! {crate::Identifiable::id(&self.#field_name)},
parse_quote! {<#ty as Identifiable>::Id},
parse_quote! {Identifiable::id(&self.#field_name)},
);
}
IdAttr::Missing => {
Expand Down
3 changes: 2 additions & 1 deletion data_model/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use serde_with::{DeserializeFromStr, SerializeDisplay};

pub use self::model::*;
use crate::{
domain::prelude::*, metadata::Metadata, HasMetadata, ParseError, PublicKey, Registered,
domain::prelude::*, metadata::Metadata, HasMetadata, Identifiable, ParseError, PublicKey,
Registered,
};

#[model]
Expand Down
6 changes: 4 additions & 2 deletions data_model/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use serde_with::{DeserializeFromStr, SerializeDisplay};

pub use self::model::*;
use crate::{
account::prelude::*, domain::prelude::*, ipfs::IpfsPath, metadata::Metadata, HasMetadata, Name,
ParseError, Registered,
account::prelude::*, domain::prelude::*, ipfs::IpfsPath, metadata::Metadata, HasMetadata,
Identifiable, Name, ParseError, Registered,
};

/// [`AssetTotalQuantityMap`] provides an API to work with collection of key([`AssetDefinitionId`])-value([`AssetValue`])
Expand Down 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: 3 additions & 1 deletion data_model/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};

pub use self::model::*;
use crate::{ipfs::IpfsPath, metadata::Metadata, prelude::*, HasMetadata, Name, Registered};
use crate::{
ipfs::IpfsPath, metadata::Metadata, prelude::*, HasMetadata, Identifiable, Name, Registered,
};

#[model]
mod model {
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iroha_primitives::json::JsonString;
use nonzero_ext::nonzero;

pub use self::model::*;
use crate::name::Name;
use crate::{name::Name, Identifiable};

/// Collection of [`CustomParameter`]s
pub(crate) type CustomParameters = btree_map::BTreeMap<CustomParameterId, CustomParameter>;
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroha_data_model_derive::model;
use iroha_primitives::addr::SocketAddr;

pub use self::model::*;
use crate::{PublicKey, Registered};
use crate::{Identifiable, PublicKey, Registered};

#[model]
mod model {
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iroha_data_model_derive::model;
pub use self::model::*;
use crate::{
permission::{Permission, Permissions},
Name, Registered,
Identifiable, Name, Registered,
};

#[model]
Expand Down
4 changes: 3 additions & 1 deletion data_model/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};

pub use self::model::*;
use crate::{events::prelude::*, metadata::Metadata, transaction::Executable, Name, Registered};
use crate::{
events::prelude::*, metadata::Metadata, transaction::Executable, Identifiable, Name, Registered,
};

#[model]
mod model {
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 8557265

Please sign in to comment.