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

Fix QueryResponse path in generate_api #1534

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to

## [Unreleased]

### Fixed

- cosmwasm-schema: Fix type fully qualified path to symbol `QueryResponses` in
macro `cosmwasm_schema::generate_api!` ([#1527]).

[#1527]: https://github.com/CosmWasm/cosmwasm/issues/1527

## [1.1.8] - 2022-11-22

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions packages/schema-derive/src/generate_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Parse for Options {
let ty = ty.unwrap_type();
(
quote! {Some(::cosmwasm_schema::schema_for!(#ty))},
quote! { Some(<#ty as QueryResponses>::response_schemas().unwrap()) },
quote! { Some(<#ty as ::cosmwasm_schema::QueryResponses>::response_schemas().unwrap()) },
)
}
None => (quote! { None }, quote! { None }),
Expand Down Expand Up @@ -272,7 +272,7 @@ mod tests {
query: Some(::cosmwasm_schema::schema_for!(QueryMsg)),
migrate: Some(::cosmwasm_schema::schema_for!(MigrateMsg)),
sudo: Some(::cosmwasm_schema::schema_for!(SudoMsg)),
responses: Some(<QueryMsg as QueryResponses>::response_schemas().unwrap()),
responses: Some(<QueryMsg as ::cosmwasm_schema::QueryResponses>::response_schemas().unwrap()),
}
}
);
Expand Down
26 changes: 26 additions & 0 deletions packages/schema/tests/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ fn test_basic_structure() {
);
}

// Test to reproduce https://github.com/CosmWasm/cosmwasm/issues/1527
#[test]
fn generate_api_works_when_only_types_are_imported() {
mod my_api_generator {
// Note super::QueryResponses is not imported in that case.
use super::generate_api;
use super::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg};

pub fn generate() {
let _api_str = generate_api! {
name: "test",
version: "0.1.0",
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
sudo: SudoMsg,
migrate: MigrateMsg,
}
.render()
.to_string()
.unwrap();
}
}
my_api_generator::generate();
}

#[test]
fn test_query_responses() {
let api_str = generate_api! {
Expand Down