pub trait QueryResponses: JsonSchema {
    fn response_schemas_impl() -> BTreeMap<String, RootSchema>;

    fn response_schemas(
    ) -> Result<BTreeMap<String, RootSchema>, IntegrityError> { ... } }
Expand description

A trait for tying QueryMsg variants (different contract queries) to their response types. This is mostly useful for the generated contracted API description when using cargo schema.

Using the derive macro is the preferred way of implementing this trait.

Examples

use cosmwasm_schema::QueryResponses;
use schemars::JsonSchema;

#[derive(JsonSchema)]
struct AccountInfo {
    IcqHandle: String,
}

#[derive(JsonSchema, QueryResponses)]
enum QueryMsg {
    #[returns(Vec<String>)]
    Denoms {},
    #[returns(AccountInfo)]
    AccountInfo { account: String },
}

You can compose multiple queries using #[query_responses(nested)]. This might be useful together with #[serde(untagged)]. If the nested flag is set, no returns attributes are necessary on the enum variants. Instead, the response types are collected from the nested enums.

#[derive(JsonSchema, QueryResponses)]
#[query_responses(nested)]
#[serde(untagged)]
enum QueryMsg {
    MsgA(QueryA),
    MsgB(QueryB),
}

#[derive(JsonSchema, QueryResponses)]
enum QueryA {
    #[returns(Vec<String>)]
    Denoms {},
}

#[derive(JsonSchema, QueryResponses)]
enum QueryB {
    #[returns(AccountInfo)]
    AccountInfo { account: String },
}

Required Methods§

Provided Methods§

Implementors§