Skip to content

Commit

Permalink
Merge pull request #2310 from CosmWasm/aw/fix-additional-properties
Browse files Browse the repository at this point in the history
Only set unset `additionalProperties` fields to `false`
  • Loading branch information
chipshort authored Jan 6, 2025
2 parents 7c035e2 + a0f2cdf commit c9220c2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ and this project adheres to
- cosmwasm-vm: Automatically derive cache version from function hashes and the
Wasmer version ([#2250])

## Fixed

- cosmwasm-schema: The schema export now doesn't overwrite existing
`additionalProperties` values anymore ([#2310])

[#2118]: https://github.com/CosmWasm/cosmwasm/pull/2118
[#2211]: https://github.com/CosmWasm/cosmwasm/issues/2211
[#2246]: https://github.com/CosmWasm/cosmwasm/pull/2246
[#2247]: https://github.com/CosmWasm/cosmwasm/pull/2247
[#2255]: https://github.com/CosmWasm/cosmwasm/pull/2255
[#2260]: https://github.com/CosmWasm/cosmwasm/pull/2260
[#2250]: https://github.com/CosmWasm/cosmwasm/pull/2250
[#2310]: https://github.com/CosmWasm/cosmwasm/pull/2310

## [2.1.3] - 2024-08-08

Expand Down
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ thiserror = "1.0.26"

[dev-dependencies]
anyhow = "1.0.57"
insta = { version = "1.41.1", features = ["json"] }
semver = "1"
tempfile = "3"
4 changes: 4 additions & 0 deletions packages/schema/src/schema_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ macro_rules! schema_for {
$crate::schemars::visit::visit_schema_object(self, schema);

if let Some(ref mut validation) = schema.object {
if validation.additional_properties.is_some() {
return;
}

validation.additional_properties = Some(Box::new(false.into()));
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/schema/tests/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ pub struct MigrateMsg {
pub cap: u128,
}

#[cw_serde]
pub struct MapMsg {
btree: std::collections::BTreeMap<String, u32>,
hash: std::collections::HashMap<String, u32>,
}

#[test]
fn assert_maps_generate_correctly() {
let schema = cosmwasm_schema::schema_for!(MapMsg);
insta::assert_json_snapshot!(schema);
}

#[test]
fn unknown_fields_explicitly_allowed() {
let json = serde_json::json!({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: packages/schema/tests/idl.rs
expression: schema
---
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MapMsg",
"type": "object",
"required": [
"btree",
"hash"
],
"properties": {
"btree": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"hash": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"additionalProperties": false
}

0 comments on commit c9220c2

Please sign in to comment.