Skip to content

Commit

Permalink
fix(router): correct JSON schema to generate the contract schema from (
Browse files Browse the repository at this point in the history
  • Loading branch information
cgorenflo authored May 1, 2024
1 parent 2cbdfe1 commit 01f9705
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/axelar-wasm-std/src/flagset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ where

impl<T> JsonSchema for FlagSet<T>
where
T: flagset::Flags + Serialize,
T: flagset::Flags + Serialize + JsonSchema,
<T as flagset::Flags>::Type: Serialize,
{
fn schema_name() -> String {
"FlagSet".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
gen.root_schema_for::<FlagSet<T>>().schema.into()
gen.subschema_for::<T>()
}
}
24 changes: 23 additions & 1 deletion packages/router-api/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey};
use error_stack::Report;
use error_stack::ResultExt;
use flagset::flags;
use schemars::gen::SchemaGenerator;
use schemars::schema::Schema;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
Expand Down Expand Up @@ -245,7 +247,7 @@ impl AsRef<str> for ChainName {

flags! {
#[repr(u8)]
#[derive(Deserialize, Serialize, Hash, JsonSchema)]
#[derive(Deserialize, Serialize, Hash)]
pub enum GatewayDirection: u8 {
None = 0,
Incoming = 1,
Expand All @@ -254,6 +256,16 @@ flags! {
}
}

impl JsonSchema for GatewayDirection {
fn schema_name() -> String {
"GatewayDirection".to_string()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
gen.subschema_for::<u8>()
}
}

#[cw_serde]
pub struct Gateway {
pub address: Addr,
Expand Down Expand Up @@ -378,6 +390,16 @@ mod tests {
assert!(!chain_name.eq(&"Ethereum-1".to_string()));
}

#[test]
fn json_schema_for_gateway_direction_flag_set_does_not_panic() {
let gen = &mut SchemaGenerator::default();
// check it doesn't panic
let _ = FlagSet::<GatewayDirection>::json_schema(gen);

// make sure it's the same as the underlying type
assert_eq!(GatewayDirection::json_schema(gen), u8::json_schema(gen));
}

fn dummy_message() -> Message {
Message {
cc_id: CrossChainId {
Expand Down

0 comments on commit 01f9705

Please sign in to comment.