Skip to content

Make export_schema_with_title argument immutable #908

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

Merged
merged 1 commit into from
Apr 28, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions contracts/ibc-reflect/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BalancesResponse>),
&schema_for!(AcknowledgementMsg<BalancesResponse>),
&out_dir,
"AcknowledgementMsgBalances",
);
export_schema_with_title(
&mut schema_for!(AcknowledgementMsg<DispatchResponse>),
&schema_for!(AcknowledgementMsg<DispatchResponse>),
&out_dir,
"AcknowledgementMsgDispatch",
);
export_schema_with_title(
&mut schema_for!(AcknowledgementMsg<WhoAmIResponse>),
&schema_for!(AcknowledgementMsg<WhoAmIResponse>),
&out_dir,
"AcknowledgementMsgWhoAmI",
);
Expand Down
12 changes: 6 additions & 6 deletions packages/schema/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes it easier to change between the two.

// 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/std/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}