From e94cd8376880fc3a22509967ff3161eba5615a3d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 28 Apr 2021 18:33:12 +0200 Subject: [PATCH] Make export_schema_with_title argument immutable --- CHANGELOG.md | 2 ++ contracts/ibc-reflect/examples/schema.rs | 6 +++--- packages/schema/src/export.rs | 12 ++++++------ packages/std/examples/schema.rs | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82c97d1cc..f5b2ce5e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,6 +196,8 @@ and this project adheres to `StakingQuery::Validator`, `ValidatorResponse` and `QuerierWrapper::query_validator` to allow querying a single validator. ([#879]) +- cosmwasm-schema: Make first argument non-mutable in `export_schema_with_title` + for consistency with `export_schema`. [#696]: https://github.com/CosmWasm/cosmwasm/issues/696 [#697]: https://github.com/CosmWasm/cosmwasm/issues/697 diff --git a/contracts/ibc-reflect/examples/schema.rs b/contracts/ibc-reflect/examples/schema.rs index 52f762cdba..419c7a6038 100644 --- a/contracts/ibc-reflect/examples/schema.rs +++ b/contracts/ibc-reflect/examples/schema.rs @@ -18,17 +18,17 @@ fn main() { export_schema(&schema_for!(QueryMsg), &out_dir); export_schema(&schema_for!(PacketMsg), &out_dir); export_schema_with_title( - &mut schema_for!(AcknowledgementMsg), + &schema_for!(AcknowledgementMsg), &out_dir, "AcknowledgementMsgBalances", ); export_schema_with_title( - &mut schema_for!(AcknowledgementMsg), + &schema_for!(AcknowledgementMsg), &out_dir, "AcknowledgementMsgDispatch", ); export_schema_with_title( - &mut schema_for!(AcknowledgementMsg), + &schema_for!(AcknowledgementMsg), &out_dir, "AcknowledgementMsgWhoAmI", ); diff --git a/packages/schema/src/export.rs b/packages/schema/src/export.rs index 5273d727e6..e11ea66ce4 100644 --- a/packages/schema/src/export.rs +++ b/packages/schema/src/export.rs @@ -20,13 +20,13 @@ pub fn export_schema(schema: &RootSchema, out_dir: &Path) { // use this if you want to override the auto-detected name of the object. // very useful when creating an alias for a type-alias. -pub fn export_schema_with_title(schema: &mut RootSchema, out_dir: &Path, title: &str) { - // set the title explicitly on the schemas metadata - let metadata = &mut schema.schema.metadata; - if let Some(data) = metadata { - data.title = Some(title.to_string()); +pub fn export_schema_with_title(schema: &RootSchema, out_dir: &Path, title: &str) { + let mut schema = schema.clone(); + // set the title explicitly on the schema's metadata + if let Some(metadata) = &mut schema.schema.metadata { + metadata.title = Some(title.to_string()); } - write_schema(schema, out_dir, &title); + write_schema(&schema, out_dir, &title); } /// Writes schema to file. Overwrites existing file. diff --git a/packages/std/examples/schema.rs b/packages/std/examples/schema.rs index a698b2a8f4..2d251a5c83 100644 --- a/packages/std/examples/schema.rs +++ b/packages/std/examples/schema.rs @@ -11,5 +11,5 @@ fn main() { remove_schemas(&out_dir).unwrap(); export_schema(&schema_for!(Timestamp), &out_dir); - export_schema_with_title(&mut schema_for!(CosmosMsg), &out_dir, "CosmosMsg"); + export_schema_with_title(&schema_for!(CosmosMsg), &out_dir, "CosmosMsg"); }