Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support import alias in cosmwasm-schema #1502

Open
j0nl1 opened this issue Nov 22, 2022 · 6 comments · May be fixed by #2206
Open

Support import alias in cosmwasm-schema #1502

j0nl1 opened this issue Nov 22, 2022 · 6 comments · May be fixed by #2206

Comments

@j0nl1
Copy link

j0nl1 commented Nov 22, 2022

Currently now cosmwasm-schema doesn't support import alias, it uses the same ref name for different aliases.

pub use cw20_stake::msg::ExecuteMsg as StakeExecuteMsg;
pub use cw_proposal_single::msg::ExecuteMsg as ProposalExecuteMsg;

Ex:

{
  "type": "object",
  "required": [
    "stake_actions"
  ],
  "properties": {
    "stake_actions": {
      "$ref": "#/definitions/ExecuteMsg"
    }
  },
  "additionalProperties": false
},
{
  "type": "object",
  "required": [
    "proposal_actions"
  ],
  "properties": {
    "proposal_actions": {
      "type": "object",
      "required": [
        "msg",
        "prop_module_addr"
      ],
      "properties": {
        "msg": {
          "$ref": "#/definitions/ExecuteMsg"
        },
        "prop_module_addr": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
@webmaster128
Copy link
Member

Thank you! Could you also share the code that generates the JSON Schema, i.e. uses the StakeExecuteMsg and ProposalExecuteMsg?

@j0nl1
Copy link
Author

j0nl1 commented Nov 22, 2022

yes, absolutely. they are used in a struct which is used for IBC handling in different contracts.

Repository

#[cw_serde]
pub enum RemoteTunnelPacketMsg {
    /// A special case where the Factory is the only one who can call this
    MintGovec {
        wallet_addr: String,
    },
    GovecActions(GovecExecuteMsg),
    StakeActions(StakeExecuteMsg),
    ProposalActions {
        prop_module_addr: String,
        msg: ProposalExecuteMsg,
    },
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn ibc_packet_receive(
    deps: DepsMut,
    _env: Env,
    msg: IbcPacketReceiveMsg,
) -> Result<IbcReceiveResponse, ContractError> {
    (|| {
        let packet = msg.packet;

        is_authorised_src(deps.as_ref(), packet.src, packet.dest)?;

        let packet_msg: PacketMsg =
            from_binary(&packet.data).map_err(|_| IbcError::InvalidPacketMsg)?;

        let remote_ibc_msg: RemoteTunnelPacketMsg =
            from_binary(&packet_msg.msg).map_err(|_| IbcError::InvalidInnerMsg)?;

        match remote_ibc_msg {
            RemoteTunnelPacketMsg::MintGovec { wallet_addr } => {
                receive_mint_govec(deps, wallet_addr)
            }
            RemoteTunnelPacketMsg::GovecActions(msg) => {
                receive_govec_actions(deps, packet_msg.sender, msg)
            }
            RemoteTunnelPacketMsg::StakeActions(msg) => {
                receive_stake_actions(deps, packet_msg.sender, msg)
            }
            RemoteTunnelPacketMsg::ProposalActions {
                prop_module_addr,
                msg,
            } => receive_proposal_actions(packet_msg.sender, prop_module_addr, msg),
        }
    })()
    .or_else(|e| {
        Ok(IbcReceiveResponse::new().set_ack(StdAck::fail(format!("IBC Packet Error: {}", e))))
    })
}
"RemoteTunnelPacketMsg": {
        "description": "The IBC Packet Msg allowed dispatched by remote-tunnel",
        "oneOf": [
          {
            "description": "A special case where the Factory is the only one who can call this",
            "type": "object",
            "required": [
              "mint_govec"
            ],
            "properties": {
              "mint_govec": {
                "type": "object",
                "required": [
                  "wallet_addr"
                ],
                "properties": {
                  "wallet_addr": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "required": [
              "govec_actions"
            ],
            "properties": {
              "govec_actions": {
                "$ref": "#/definitions/GovecExecuteMsg"
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "required": [
              "stake_actions"
            ],
            "properties": {
              "stake_actions": {
                "$ref": "#/definitions/ExecuteMsg"
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "required": [
              "proposal_actions"
            ],
            "properties": {
              "proposal_actions": {
                "type": "object",
                "required": [
                  "msg",
                  "prop_module_addr"
                ],
                "properties": {
                  "msg": {
                    "$ref": "#/definitions/ExecuteMsg"
                  },
                  "prop_module_addr": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          }
        ]
      }

@uint
Copy link
Contributor

uint commented Nov 23, 2022

I took a look and I don't see an easy way to do this. schemars doesn't seem to have anything to allow renaming the type/ref. Maybe we should open an issue/PR in https://github.com/GREsau/schemars.

@uint
Copy link
Contributor

uint commented Nov 23, 2022

This should help once it's merged: GREsau/schemars#178 GREsau/schemars#177

@webmaster128
Copy link
Member

@aumetra could you have a look into this and ensure the new schema generator supports this request well?

@aumetra
Copy link
Member

aumetra commented Aug 27, 2024

could you have a look into this and ensure the new schema generator supports this request well?

Yep, will add a test case. The new format is already using the internal TypeId type, meaning it will already have distinct values. But better test that property.

@aumetra aumetra linked a pull request Sep 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants