diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c075e7a60..18937cc7ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/schema-derive/src/generate_api.rs b/packages/schema-derive/src/generate_api.rs index f3f8bbcaa8..b275ca561e 100644 --- a/packages/schema-derive/src/generate_api.rs +++ b/packages/schema-derive/src/generate_api.rs @@ -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 }), @@ -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(::response_schemas().unwrap()), + responses: Some(::response_schemas().unwrap()), } } ); diff --git a/packages/schema/tests/idl.rs b/packages/schema/tests/idl.rs index 5f1f8b036d..d6f00d4f57 100644 --- a/packages/schema/tests/idl.rs +++ b/packages/schema/tests/idl.rs @@ -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! {