Skip to content

Commit 4415fd1

Browse files
authored
Merge pull request #1475 from CosmWasm/schema_for-future-proofing
Lock JSON schema version
2 parents 007fd62 + 76ed13b commit 4415fd1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and this project adheres to
2323
`-Zminimal-versions` ([#1465]).
2424
- cosmwasm-profiler: Package was removed 🪦. It served its job showing us that we
2525
cannot properly measure different runtimes for differet Wasm opcodes.
26+
- cosmwasm-schema: schema generation is now locked to produce strictly
27+
`draft-07` schemas
2628

2729
[#1465]: https://github.com/CosmWasm/cosmwasm/pull/1465
2830

packages/schema/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod export;
33
mod idl;
44
mod query_response;
55
mod remove;
6+
mod schema_for;
67

78
pub use export::{export_schema, export_schema_with_title};
89
pub use idl::{Api, IDL_VERSION};
@@ -91,7 +92,6 @@ pub use cosmwasm_schema_derive::generate_api;
9192
/// };
9293
/// ```
9394
pub use cosmwasm_schema_derive::write_api;
94-
pub use schemars::schema_for;
9595

9696
// For use in macro expansions
9797
pub use schemars;

packages/schema/src/schema_for.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// Generates a [`RootSchema`](crate::schemars::schema::RootSchema) for the given type using default settings.
2+
///
3+
/// The type must implement [`JsonSchema`](crate::schemars::JsonSchema).
4+
///
5+
/// The schema version is strictly `draft-07`.
6+
///
7+
/// # Example
8+
/// ```
9+
/// use cosmwasm_schema::schema_for;
10+
/// use schemars::JsonSchema;
11+
///
12+
/// #[derive(JsonSchema)]
13+
/// struct MyStruct {
14+
/// foo: i32,
15+
/// }
16+
///
17+
/// let my_schema = schema_for!(MyStruct);
18+
/// ```
19+
#[macro_export]
20+
macro_rules! schema_for {
21+
($type:ty) => {
22+
$crate::schemars::gen::SchemaGenerator::new($crate::schemars::gen::SchemaSettings::draft07()).into_root_schema_for::<$type>()
23+
};
24+
($_:expr) => {
25+
compile_error!("The argument to `schema_for!` is not a type.")
26+
};
27+
}

0 commit comments

Comments
 (0)