Skip to content

Commit c9220c2

Browse files
authored
Merge pull request #2310 from CosmWasm/aw/fix-additional-properties
Only set unset `additionalProperties` fields to `false`
2 parents 7c035e2 + a0f2cdf commit c9220c2

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,19 @@ and this project adheres to
6666
- cosmwasm-vm: Automatically derive cache version from function hashes and the
6767
Wasmer version ([#2250])
6868

69+
## Fixed
70+
71+
- cosmwasm-schema: The schema export now doesn't overwrite existing
72+
`additionalProperties` values anymore ([#2310])
73+
6974
[#2118]: https://github.com/CosmWasm/cosmwasm/pull/2118
7075
[#2211]: https://github.com/CosmWasm/cosmwasm/issues/2211
7176
[#2246]: https://github.com/CosmWasm/cosmwasm/pull/2246
7277
[#2247]: https://github.com/CosmWasm/cosmwasm/pull/2247
7378
[#2255]: https://github.com/CosmWasm/cosmwasm/pull/2255
7479
[#2260]: https://github.com/CosmWasm/cosmwasm/pull/2260
7580
[#2250]: https://github.com/CosmWasm/cosmwasm/pull/2250
81+
[#2310]: https://github.com/CosmWasm/cosmwasm/pull/2310
7682

7783
## [2.1.3] - 2024-08-08
7884

Cargo.lock

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/schema/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ thiserror = "1.0.26"
1919

2020
[dev-dependencies]
2121
anyhow = "1.0.57"
22+
insta = { version = "1.41.1", features = ["json"] }
2223
semver = "1"
2324
tempfile = "3"

packages/schema/src/schema_for.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ macro_rules! schema_for {
3030
$crate::schemars::visit::visit_schema_object(self, schema);
3131

3232
if let Some(ref mut validation) = schema.object {
33+
if validation.additional_properties.is_some() {
34+
return;
35+
}
36+
3337
validation.additional_properties = Some(Box::new(false.into()));
3438
}
3539
}

packages/schema/tests/idl.rs

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ pub struct MigrateMsg {
3232
pub cap: u128,
3333
}
3434

35+
#[cw_serde]
36+
pub struct MapMsg {
37+
btree: std::collections::BTreeMap<String, u32>,
38+
hash: std::collections::HashMap<String, u32>,
39+
}
40+
41+
#[test]
42+
fn assert_maps_generate_correctly() {
43+
let schema = cosmwasm_schema::schema_for!(MapMsg);
44+
insta::assert_json_snapshot!(schema);
45+
}
46+
3547
#[test]
3648
fn unknown_fields_explicitly_allowed() {
3749
let json = serde_json::json!({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
source: packages/schema/tests/idl.rs
3+
expression: schema
4+
---
5+
{
6+
"$schema": "http://json-schema.org/draft-07/schema#",
7+
"title": "MapMsg",
8+
"type": "object",
9+
"required": [
10+
"btree",
11+
"hash"
12+
],
13+
"properties": {
14+
"btree": {
15+
"type": "object",
16+
"additionalProperties": {
17+
"type": "integer",
18+
"format": "uint32",
19+
"minimum": 0.0
20+
}
21+
},
22+
"hash": {
23+
"type": "object",
24+
"additionalProperties": {
25+
"type": "integer",
26+
"format": "uint32",
27+
"minimum": 0.0
28+
}
29+
}
30+
},
31+
"additionalProperties": false
32+
}

0 commit comments

Comments
 (0)