diff --git a/Cargo.lock b/Cargo.lock index 6221f7c468..186217fc36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,7 +150,7 @@ dependencies = [ "ark-std", "derivative", "hashbrown 0.13.2", - "itertools", + "itertools 0.10.5", "num-traits", "rayon", "zeroize", @@ -168,7 +168,7 @@ dependencies = [ "ark-std", "derivative", "digest", - "itertools", + "itertools 0.10.5", "num-bigint", "num-traits", "paste", @@ -497,7 +497,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.10.0", ] [[package]] @@ -528,6 +528,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -602,7 +614,7 @@ dependencies = [ "cosmwasm-std", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -611,7 +623,7 @@ version = "2.1.1" dependencies = [ "anyhow", "cosmwasm-schema-derive", - "schemars", + "schemars 0.8.20", "semver", "serde", "serde_json", @@ -625,7 +637,7 @@ version = "2.1.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -641,11 +653,12 @@ dependencies = [ "cosmwasm-derive", "cosmwasm-schema", "crc32fast", + "cw-schema", "derive_more", "hex", "hex-literal", "rand_core", - "schemars", + "schemars 0.8.20", "serde", "serde-json-wasm", "serde_json", @@ -675,7 +688,7 @@ dependencies = [ "leb128", "rand", "rand_core", - "schemars", + "schemars 0.8.20", "serde", "serde_json", "sha2", @@ -804,7 +817,7 @@ dependencies = [ "clap", "criterion-plot", "is-terminal", - "itertools", + "itertools 0.10.5", "num-traits", "once_cell", "oorandom", @@ -825,7 +838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools", + "itertools 0.10.5", ] [[package]] @@ -914,7 +927,33 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", +] + +[[package]] +name = "cw-schema" +version = "2.1.1" +dependencies = [ + "cw-schema-derive", + "indexmap 2.4.0", + "insta", + "pretty_assertions", + "schemars 1.0.0-alpha.6", + "serde", + "serde_json", + "serde_with", + "siphasher", +] + +[[package]] +name = "cw-schema-derive" +version = "2.1.1" +dependencies = [ + "heck 0.5.0", + "itertools 0.13.0", + "proc-macro2", + "quote", + "syn 2.0.75", ] [[package]] @@ -947,7 +986,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] @@ -961,7 +1000,8 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.65", + "strsim 0.11.1", + "syn 2.0.75", ] [[package]] @@ -983,7 +1023,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core 0.20.9", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -1077,7 +1117,7 @@ checksum = "2bba3e9872d7c58ce7ef0fcf1844fcc3e23ef2a58377b50df35dd98e42a5726e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", "unicode-xid", ] @@ -1097,6 +1137,12 @@ dependencies = [ "thousands", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "difflib" version = "0.4.0" @@ -1223,6 +1269,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "english-numbers" version = "0.3.3" @@ -1267,7 +1319,7 @@ dependencies = [ "darling 0.20.9", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -1431,7 +1483,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "indenter", - "schemars", + "schemars 0.8.20", ] [[package]] @@ -1495,6 +1547,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -1560,15 +1618,28 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", "hashbrown 0.14.5", "serde", ] +[[package]] +name = "insta" +version = "1.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810ae6042d48e2c9e9215043563a58a80b877bc863228a74cf10c49d4620a6f5" +dependencies = [ + "console", + "lazy_static", + "linked-hash-map", + "serde", + "similar", +] + [[package]] name = "is-terminal" version = "0.4.12" @@ -1595,6 +1666,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1649,6 +1729,12 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1924,6 +2010,16 @@ dependencies = [ "termtree", ] +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "primeorder" version = "0.13.6" @@ -1959,9 +2055,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -2069,6 +2165,26 @@ dependencies = [ "bitflags 2.5.0", ] +[[package]] +name = "ref-cast" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + [[package]] name = "regalloc2" version = "0.5.1" @@ -2233,12 +2349,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0218ceea14babe24a4a5836f86ade86c1effbc198164e619194cb5069187e29" dependencies = [ "dyn-clone", - "schemars_derive", + "schemars_derive 0.8.20", "serde", "serde_json", "url", ] +[[package]] +name = "schemars" +version = "1.0.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01e8b761be0b60066bf31ef0d74034654c72a2a670e6391ac1ea2767d2f34c5c" +dependencies = [ + "dyn-clone", + "ref-cast", + "schemars_derive 1.0.0-alpha.6", + "serde", + "serde_json", +] + [[package]] name = "schemars_derive" version = "0.8.20" @@ -2248,7 +2377,19 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.65", + "syn 2.0.75", +] + +[[package]] +name = "schemars_derive" +version = "1.0.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deaac8174f8db9fa1bd1d0cea80e12f41ba034dcee6a0c1cae53e14065a4b24d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.75", ] [[package]] @@ -2293,9 +2434,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.202" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -2332,13 +2473,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.202" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -2349,16 +2490,17 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -2372,13 +2514,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" +dependencies = [ + "serde", + "serde_derive", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" +dependencies = [ + "darling 0.20.9", + "proc-macro2", + "quote", + "syn 2.0.75", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.4.0", "itoa", "ryu", "serde", @@ -2432,6 +2597,18 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "similar" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slice-group-by" version = "0.3.1" @@ -2462,6 +2639,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.26.2" @@ -2477,11 +2660,11 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -2503,9 +2686,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.65" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -2570,7 +2753,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -2674,7 +2857,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.4.0", "serde", "serde_spanned", "toml_datetime", @@ -2687,7 +2870,7 @@ version = "0.22.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" dependencies = [ - "indexmap 2.2.6", + "indexmap 2.4.0", "serde", "serde_spanned", "toml_datetime", @@ -2713,7 +2896,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -2846,7 +3029,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", "wasm-bindgen-shared", ] @@ -2868,7 +3051,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3003,8 +3186,8 @@ dependencies = [ "bytesize", "derive_builder", "hex", - "indexmap 2.2.6", - "schemars", + "indexmap 2.4.0", + "schemars 0.8.20", "semver", "serde", "serde_cbor", @@ -3094,7 +3277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ "bitflags 2.5.0", - "indexmap 2.2.6", + "indexmap 2.4.0", "semver", ] @@ -3416,6 +3599,12 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927da81e25be1e1a2901d59b81b37dd2efd1fc9c9345a55007f09bf5a2d3ee03" +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zerocopy" version = "0.7.34" @@ -3433,7 +3622,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] [[package]] @@ -3453,5 +3642,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.65", + "syn 2.0.75", ] diff --git a/packages/cw-schema-derive/src/expand.rs b/packages/cw-schema-derive/src/expand.rs index 0daad8ae71..cb10a73376 100644 --- a/packages/cw-schema-derive/src/expand.rs +++ b/packages/cw-schema-derive/src/expand.rs @@ -1,9 +1,8 @@ -use std::borrow::Cow; - use crate::bail; use proc_macro2::TokenStream; use quote::quote; -use syn::{punctuated::Punctuated, DataEnum, DataStruct, DataUnion, DeriveInput, Lit}; +use std::borrow::Cow; +use syn::{DataEnum, DataStruct, DataUnion, DeriveInput, Lit}; struct SerdeContainerOptions { rename_all: Option, @@ -45,12 +44,16 @@ impl SerdeContainerOptions { } struct ContainerOptions { + r#as: Option, + r#type: Option, crate_path: syn::Path, } impl ContainerOptions { fn parse(attributes: &[syn::Attribute]) -> syn::Result { let mut options = ContainerOptions { + r#as: None, + r#type: None, crate_path: syn::parse_str("::cw_schema")?, }; @@ -62,6 +65,10 @@ impl ContainerOptions { if meta.path.is_ident("crate") { let stringified: syn::LitStr = meta.value()?.parse()?; options.crate_path = stringified.parse()?; + } else if meta.path.is_ident("as") { + options.r#as = Some(meta.value()?.parse()?); + } else if meta.path.is_ident("type") { + options.r#type = Some(meta.value()?.parse()?); } else { bail!(meta.path, "unknown attribute"); } @@ -228,55 +235,72 @@ fn expand_struct(mut meta: ContainerMeta, input: DataStruct) -> syn::Result { - let items = named.named.iter().map(|field| { - let name = field.ident.as_ref().unwrap(); - let description = normalize_option(extract_documentation(&field.attrs)?); - let field_ty = &field.ty; - - let expanded = quote! { - ( - stringify!(#name).into(), - #crate_path::StructProperty { - description: #description, - value: <#field_ty as #crate_path::Schemaifier>::visit_schema(visitor), - } - ) - }; - - Ok(expanded) - }).collect::>>()?; - + let node = if let Some(ref r#as) = meta.options.r#as { + quote! { + let definition_resource = #crate_path::Schemaifier::visit_schema(visitor); + visitor.get_schema::<#r#as>().unwrap().clone() + } + } else { + let node_ty = if let Some(ref r#type) = meta.options.r#type { quote! { - #crate_path::StructType::Named { - properties: #crate_path::reexport::BTreeMap::from([ - #( #items, )* - ]) - } + #r#type } - } - syn::Fields::Unnamed(fields) => { - let type_names = fields.unnamed.iter().map(|field| &field.ty); + } else { + let node_ty = match input.fields { + syn::Fields::Named(named) => { + let items = named.named.iter().map(|field| { + let name = field.ident.as_ref().unwrap(); + let description = normalize_option(extract_documentation(&field.attrs)?); + let field_ty = &field.ty; + + let expanded = quote! { + ( + stringify!(#name).into(), + #crate_path::StructProperty { + description: #description, + value: <#field_ty as #crate_path::Schemaifier>::visit_schema(visitor), + } + ) + }; + + Ok(expanded) + }).collect::>>()?; + + quote! { + #crate_path::StructType::Named { + properties: #crate_path::reexport::BTreeMap::from([ + #( #items, )* + ]) + } + } + } + syn::Fields::Unnamed(fields) => { + let type_names = fields.unnamed.iter().map(|field| &field.ty); + + quote! { + #crate_path::StructType::Tuple { + items: vec![ + #( + <#type_names as #crate_path::Schemaifier>::visit_schema(visitor), + )* + ], + } + } + } + syn::Fields::Unit => quote! { #crate_path::StructType::Unit }, + }; quote! { - #crate_path::StructType::Tuple { - items: vec![ - #( - <#type_names as #crate_path::Schemaifier>::visit_schema(visitor), - )* - ], - } + #crate_path::NodeType::Struct(#node_ty) } - } - syn::Fields::Unit => quote! { #crate_path::StructType::Unit }, - }; + }; - let node = quote! { - #crate_path::Node { - name: std::any::type_name::().into(), - description: #description, - value: #crate_path::NodeType::Struct(#node_ty), + quote! { + #crate_path::Node { + name: std::any::type_name::().into(), + description: #description, + value: #node_ty, + } } }; diff --git a/packages/cw-schema/Cargo.lock b/packages/cw-schema/Cargo.lock deleted file mode 100644 index 2c1676ee90..0000000000 --- a/packages/cw-schema/Cargo.lock +++ /dev/null @@ -1,414 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "console" -version = "0.15.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "windows-sys", -] - -[[package]] -name = "cw-schema" -version = "0.1.0" -dependencies = [ - "cw-schema-derive", - "insta", - "pretty_assertions", - "schemars", - "serde", - "serde_json", - "serde_with", -] - -[[package]] -name = "cw-schema-derive" -version = "0.1.0" -dependencies = [ - "heck", - "itertools", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "darling" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.20.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" -dependencies = [ - "darling_core", - "quote", - "syn", -] - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "insta" -version = "1.39.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "810ae6042d48e2c9e9215043563a58a80b877bc863228a74cf10c49d4620a6f5" -dependencies = [ - "console", - "lazy_static", - "linked-hash-map", - "serde", - "similar", -] - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - -[[package]] -name = "pretty_assertions" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" -dependencies = [ - "diff", - "yansi", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ref-cast" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "schemars" -version = "1.0.0-alpha.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec9b1e7918a904d86cb6de7147ff4da21f12ac1462c8049e12b30a8846f4699e" -dependencies = [ - "dyn-clone", - "ref-cast", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "1.0.0-alpha.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2730d5d2dbaf504ab238832cad00b0bdd727436583c7b05f9328e65fee2b475" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn", -] - -[[package]] -name = "serde" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.204" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.120" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_with" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" -dependencies = [ - "serde", - "serde_derive", - "serde_with_macros", -] - -[[package]] -name = "serde_with_macros" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "similar" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/packages/cw-schema/src/lib.rs b/packages/cw-schema/src/lib.rs index 9c87ed55e4..e900e8104c 100644 --- a/packages/cw-schema/src/lib.rs +++ b/packages/cw-schema/src/lib.rs @@ -5,11 +5,7 @@ extern crate alloc; #[cfg(feature = "std")] extern crate std; -use alloc::{ - borrow::{Cow, ToOwned}, - collections::BTreeMap, - vec::Vec, -}; +use alloc::{borrow::Cow, collections::BTreeMap, vec::Vec}; use core::hash::BuildHasherDefault; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; @@ -23,7 +19,7 @@ pub type DefinitionReference = usize; mod default_impls; #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase")] pub struct StructProperty { @@ -32,7 +28,7 @@ pub struct StructProperty { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase", untagged)] #[non_exhaustive] @@ -47,7 +43,7 @@ pub enum StructType { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase")] pub struct EnumCase { @@ -57,7 +53,7 @@ pub struct EnumCase { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase", tag = "type")] #[non_exhaustive] @@ -72,7 +68,7 @@ pub enum EnumValue { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase", tag = "type")] #[non_exhaustive] @@ -119,7 +115,7 @@ pub enum NodeType { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase")] pub struct Node { @@ -130,7 +126,7 @@ pub struct Node { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase")] pub struct SchemaV1 { @@ -139,7 +135,7 @@ pub struct SchemaV1 { } #[skip_serializing_none] -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "std", derive(::schemars::JsonSchema))] #[serde(rename_all = "camelCase", tag = "type")] #[non_exhaustive] @@ -178,6 +174,10 @@ impl SchemaVisitor { self.schemas.get_index_of(&T::id()) } + pub fn get_schema(&self) -> Option<&Node> { + self.schemas.get(&T::id()) + } + pub fn insert(&mut self, id: Identifier, node: Node) -> DefinitionReference { let (id, _) = self.schemas.insert_full(id, node); id diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 4b276c218b..756a2283db 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -54,6 +54,7 @@ base64 = "0.22.0" bnum = "0.11.0" cosmwasm-core = { version = "2.1.1", path = "../core" } cosmwasm-derive = { version = "2.1.1", path = "../derive" } +cw-schema = { version = "2.1.1", path = "../cw-schema" } derive_more = { version = "1.0.0-beta.6", default-features = false, features = ["debug"] } hex = "0.4" schemars = { workspace = true } diff --git a/packages/std/src/addresses.rs b/packages/std/src/addresses.rs index d23c5b1aa3..96faffa827 100644 --- a/packages/std/src/addresses.rs +++ b/packages/std/src/addresses.rs @@ -27,8 +27,19 @@ use crate::{HexBinary, __internal::forward_ref_partial_eq}; /// a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` /// instance. #[derive( - Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, schemars::JsonSchema, + Serialize, + Deserialize, + Clone, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + schemars::JsonSchema, + cw_schema::Schemaifier, )] +#[schemaifier(type = cw_schema::NodeType::Address)] pub struct Addr(String); forward_ref_partial_eq!(Addr, Addr); diff --git a/packages/std/src/binary.rs b/packages/std/src/binary.rs index 72dfd6cc64..5e6606edca 100644 --- a/packages/std/src/binary.rs +++ b/packages/std/src/binary.rs @@ -14,7 +14,18 @@ use crate::{ /// /// This is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. /// See also . -#[derive(Clone, Default, PartialEq, Eq, Hash, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Clone, + Default, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Binary)] pub struct Binary(#[schemars(with = "String")] Vec); impl Binary { diff --git a/packages/std/src/checksum.rs b/packages/std/src/checksum.rs index b2b1a79e9a..9a4c2baa5f 100644 --- a/packages/std/src/checksum.rs +++ b/packages/std/src/checksum.rs @@ -13,7 +13,8 @@ use crate::{StdError, StdResult}; /// /// This is often referred to as "code ID" in go-cosmwasm, even if code ID /// usually refers to an auto-incrementing number. -#[derive(JsonSchema, Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(JsonSchema, Debug, Copy, Clone, PartialEq, Eq, Hash, cw_schema::Schemaifier)] +#[schemaifier(type = cw_schema::NodeType::Checksum)] pub struct Checksum(#[schemars(with = "String")] [u8; 32]); impl Checksum { diff --git a/packages/std/src/coin.rs b/packages/std/src/coin.rs index 54d41e0858..5842ea1b9e 100644 --- a/packages/std/src/coin.rs +++ b/packages/std/src/coin.rs @@ -6,7 +6,9 @@ use crate::prelude::*; use crate::CoinFromStrError; use crate::Uint128; -#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct Coin { pub denom: String, pub amount: Uint128, diff --git a/packages/std/src/errors/system_error.rs b/packages/std/src/errors/system_error.rs index ea9052e4d7..6f8c5bd8ce 100644 --- a/packages/std/src/errors/system_error.rs +++ b/packages/std/src/errors/system_error.rs @@ -13,7 +13,7 @@ use crate::Binary; /// Such errors are only created by the VM. The error type is defined in the standard library, to ensure /// the contract understands the error format without creating a dependency on cosmwasm-vm. #[derive( - Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, thiserror::Error, + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, schemars::JsonSchema, thiserror::Error, cw_schema::Schemaifier )] #[serde(rename_all = "snake_case")] #[non_exhaustive] diff --git a/packages/std/src/hex_binary.rs b/packages/std/src/hex_binary.rs index e2168942c7..3eac10cd30 100644 --- a/packages/std/src/hex_binary.rs +++ b/packages/std/src/hex_binary.rs @@ -14,7 +14,18 @@ use crate::{ /// /// This is similar to `cosmwasm_std::Binary` but uses hex. /// See also . -#[derive(Clone, Default, PartialEq, Eq, Hash, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Clone, + Default, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::HexBinary)] pub struct HexBinary(#[schemars(with = "String")] Vec); impl HexBinary { diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 02da72e408..627d839c96 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -21,7 +21,7 @@ pub use transfer_msg_builder::*; /// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts /// (contracts that directly speak the IBC protocol via 6 entry points) #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum IbcMsg { /// Sends bank tokens owned by the contract to the given address on another chain. @@ -77,7 +77,9 @@ pub enum IbcMsg { CloseChannel { channel_id: String }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct IbcEndpoint { pub port_id: String, pub channel_id: String, @@ -86,7 +88,9 @@ pub struct IbcEndpoint { /// In IBC each package must set at least one type of timeout: /// the timestamp or the block height. Using this rather complex enum instead of /// two timeout fields we ensure that at least one timeout is set. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[serde(rename_all = "snake_case")] pub struct IbcTimeout { // use private fields to enforce the use of constructors, which ensure that at least one is set @@ -141,7 +145,9 @@ impl From for IbcTimeout { /// IbcChannel defines all information on a channel. /// This is generally used in the hand-shake process, but can be queried directly. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcChannel { pub endpoint: IbcEndpoint, @@ -176,7 +182,7 @@ impl IbcChannel { /// IbcOrder defines if a channel is ORDERED or UNORDERED /// Values come from https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/core/channel/v1/channel.proto#L69-L80 /// Naming comes from the protobuf files and go translations. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub enum IbcOrder { #[serde(rename = "ORDER_UNORDERED")] Unordered, @@ -188,7 +194,9 @@ pub enum IbcOrder { /// that can be compared against another Height for the purposes of updating and /// freezing clients. /// Ordering is (revision_number, timeout_height) -#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct IbcTimeoutBlock { /// the version that the client is currently on /// (e.g. after resetting the chain this could increment 1 as height drops to 0) @@ -219,7 +227,9 @@ impl Ord for IbcTimeoutBlock { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcPacket { /// The raw data sent from the other side in the packet @@ -252,7 +262,9 @@ impl IbcPacket { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcAcknowledgement { pub data: Binary, @@ -273,7 +285,7 @@ impl IbcAcknowledgement { } /// The message that is passed into `ibc_channel_open` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum IbcChannelOpenMsg { /// The ChanOpenInit step from https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#channel-lifecycle-management @@ -329,14 +341,16 @@ impl From for IbcChannel { /// If `null` is provided instead, the incoming channel version is accepted. pub type IbcChannelOpenResponse = Option; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct Ibc3ChannelOpenResponse { /// We can set the channel version to a different one than we were called with pub version: String, } /// The message that is passed into `ibc_channel_connect` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum IbcChannelConnectMsg { /// The ChanOpenAck step from https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#channel-lifecycle-management @@ -388,7 +402,7 @@ impl From for IbcChannel { } /// The message that is passed into `ibc_channel_close` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum IbcChannelCloseMsg { /// The ChanCloseInit step from https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#channel-lifecycle-management @@ -424,7 +438,9 @@ impl From for IbcChannel { } /// The message that is passed into `ibc_packet_receive` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcPacketReceiveMsg { pub packet: IbcPacket, @@ -438,7 +454,9 @@ impl IbcPacketReceiveMsg { } /// The message that is passed into `ibc_packet_ack` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcPacketAckMsg { pub acknowledgement: IbcAcknowledgement, @@ -461,7 +479,9 @@ impl IbcPacketAckMsg { } /// The message that is passed into `ibc_packet_timeout` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcPacketTimeoutMsg { pub packet: IbcPacket, @@ -481,7 +501,9 @@ impl IbcPacketTimeoutMsg { /// Callbacks that have return values (like receive_packet) /// or that cannot redispatch messages (like the handshake callbacks) /// will use other Response types -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcBasicResponse { /// Optional list of messages to pass. These will be executed in order. @@ -623,7 +645,9 @@ impl IbcBasicResponse { /// Where the acknowledgement bytes contain an encoded error message to be returned to /// the calling chain. (Returning ContractResult::Err will abort processing of this packet /// and not inform the calling chain). -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[non_exhaustive] pub struct IbcReceiveResponse { /// The bytes we return to the contract that sent the packet. diff --git a/packages/std/src/iterator.rs b/packages/std/src/iterator.rs index 41f043a093..bc50883841 100644 --- a/packages/std/src/iterator.rs +++ b/packages/std/src/iterator.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; /// allows contracts to reuse the type when deserializing database records. pub type Record> = (Vec, V); -#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] // We assign these to integers to provide a stable API for passing over FFI (to wasm and Go) pub enum Order { diff --git a/packages/std/src/math/decimal.rs b/packages/std/src/math/decimal.rs index 19b1c0a293..266c752b19 100644 --- a/packages/std/src/math/decimal.rs +++ b/packages/std/src/math/decimal.rs @@ -19,7 +19,18 @@ use super::{Uint128, Uint256}; /// A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0 /// /// The greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18) -#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Decimal { precision: 128, signed: false })] pub struct Decimal(#[schemars(with = "String")] Uint128); forward_ref_partial_eq!(Decimal, Decimal); diff --git a/packages/std/src/math/decimal256.rs b/packages/std/src/math/decimal256.rs index a37a0ffeec..4c6fc4c458 100644 --- a/packages/std/src/math/decimal256.rs +++ b/packages/std/src/math/decimal256.rs @@ -23,7 +23,18 @@ use super::Uint256; /// The greatest possible value that can be represented is /// 115792089237316195423570985008687907853269984665640564039457.584007913129639935 /// (which is (2^256 - 1) / 10^18) -#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Decimal { precision: 256, signed: false })] pub struct Decimal256(#[schemars(with = "String")] Uint256); forward_ref_partial_eq!(Decimal256, Decimal256); diff --git a/packages/std/src/math/int128.rs b/packages/std/src/math/int128.rs index 6d240f285a..9f245315de 100644 --- a/packages/std/src/math/int128.rs +++ b/packages/std/src/math/int128.rs @@ -30,7 +30,19 @@ use super::num_consts::NumConsts; /// let a = Int128::from(258i128); /// assert_eq!(a.i128(), 258); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 128, signed: true })] pub struct Int128(#[schemars(with = "String")] pub(crate) i128); forward_ref_partial_eq!(Int128, Int128); diff --git a/packages/std/src/math/int256.rs b/packages/std/src/math/int256.rs index 4b236bed15..9419f96f9e 100644 --- a/packages/std/src/math/int256.rs +++ b/packages/std/src/math/int256.rs @@ -41,7 +41,19 @@ use super::num_consts::NumConsts; /// ]); /// assert_eq!(a, b); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 256, signed: true })] pub struct Int256(#[schemars(with = "String")] pub(crate) I256); forward_ref_partial_eq!(Int256, Int256); diff --git a/packages/std/src/math/int512.rs b/packages/std/src/math/int512.rs index edbfaa2a47..820b609d7f 100644 --- a/packages/std/src/math/int512.rs +++ b/packages/std/src/math/int512.rs @@ -44,7 +44,19 @@ use super::num_consts::NumConsts; /// ]); /// assert_eq!(a, b); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 512, signed: true })] pub struct Int512(#[schemars(with = "String")] pub(crate) I512); forward_ref_partial_eq!(Int512, Int512); diff --git a/packages/std/src/math/int64.rs b/packages/std/src/math/int64.rs index ccabc9ef3b..704b1a2dd2 100644 --- a/packages/std/src/math/int64.rs +++ b/packages/std/src/math/int64.rs @@ -30,7 +30,19 @@ use super::num_consts::NumConsts; /// let a = Int64::from(258i64); /// assert_eq!(a.i64(), 258); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 64, signed: true })] pub struct Int64(#[schemars(with = "String")] pub(crate) i64); forward_ref_partial_eq!(Int64, Int64); diff --git a/packages/std/src/math/signed_decimal.rs b/packages/std/src/math/signed_decimal.rs index 5dd82b10e1..249f5de155 100644 --- a/packages/std/src/math/signed_decimal.rs +++ b/packages/std/src/math/signed_decimal.rs @@ -21,7 +21,18 @@ use super::Int128; /// /// The greatest possible value that can be represented is 170141183460469231731.687303715884105727 (which is (2^127 - 1) / 10^18) /// and the smallest is -170141183460469231731.687303715884105728 (which is -2^127 / 10^18). -#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Decimal { precision: 128, signed: true })] pub struct SignedDecimal(#[schemars(with = "String")] Int128); forward_ref_partial_eq!(SignedDecimal, SignedDecimal); diff --git a/packages/std/src/math/signed_decimal_256.rs b/packages/std/src/math/signed_decimal_256.rs index e994bd7bac..6f5439bdd0 100644 --- a/packages/std/src/math/signed_decimal_256.rs +++ b/packages/std/src/math/signed_decimal_256.rs @@ -26,7 +26,18 @@ use super::Int256; /// and the smallest is /// -57896044618658097711785492504343953926634992332820282019728.792003956564819968 /// (which is -2^255 / 10^18). -#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Decimal { precision: 256, signed: true })] pub struct SignedDecimal256(#[schemars(with = "String")] Int256); forward_ref_partial_eq!(SignedDecimal256, SignedDecimal256); diff --git a/packages/std/src/math/uint128.rs b/packages/std/src/math/uint128.rs index b209f28007..255fb8fc1e 100644 --- a/packages/std/src/math/uint128.rs +++ b/packages/std/src/math/uint128.rs @@ -40,7 +40,19 @@ use super::num_consts::NumConsts; /// let c = Uint128::from(70u32); /// assert_eq!(c.u128(), 70); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 128, signed: false })] pub struct Uint128(#[schemars(with = "String")] pub(crate) u128); forward_ref_partial_eq!(Uint128, Uint128); diff --git a/packages/std/src/math/uint256.rs b/packages/std/src/math/uint256.rs index 815cf34003..2a6b773c5c 100644 --- a/packages/std/src/math/uint256.rs +++ b/packages/std/src/math/uint256.rs @@ -44,7 +44,19 @@ use super::num_consts::NumConsts; /// ]); /// assert_eq!(a, b); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 256, signed: false })] pub struct Uint256(#[schemars(with = "String")] pub(crate) U256); forward_ref_partial_eq!(Uint256, Uint256); diff --git a/packages/std/src/math/uint512.rs b/packages/std/src/math/uint512.rs index cd96353c6f..bbc98c645b 100644 --- a/packages/std/src/math/uint512.rs +++ b/packages/std/src/math/uint512.rs @@ -46,7 +46,19 @@ use super::num_consts::NumConsts; /// ]); /// assert_eq!(a, b); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 512, signed: false })] pub struct Uint512(#[schemars(with = "String")] pub(crate) U512); forward_ref_partial_eq!(Uint512, Uint512); diff --git a/packages/std/src/math/uint64.rs b/packages/std/src/math/uint64.rs index 707cd9e311..3a07be73be 100644 --- a/packages/std/src/math/uint64.rs +++ b/packages/std/src/math/uint64.rs @@ -35,7 +35,19 @@ use super::num_consts::NumConsts; /// let b = Uint64::from(70u32); /// assert_eq!(b.u64(), 70); /// ``` -#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, schemars::JsonSchema)] +#[derive( + Copy, + Clone, + Default, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + schemars::JsonSchema, + cw_schema::Schemaifier, +)] +#[schemaifier(type = cw_schema::NodeType::Integer { precision: 64, signed: false })] pub struct Uint64(#[schemars(with = "String")] pub(crate) u64); forward_ref_partial_eq!(Uint64, Uint64); diff --git a/packages/std/src/metadata.rs b/packages/std/src/metadata.rs index b741f32099..1f9f458067 100644 --- a/packages/std/src/metadata.rs +++ b/packages/std/src/metadata.rs @@ -4,7 +4,9 @@ use serde::{Deserialize, Serialize}; use crate::prelude::*; /// Replicates the cosmos-sdk bank module Metadata type -#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct DenomMetadata { pub description: String, pub denom_units: Vec, @@ -17,7 +19,9 @@ pub struct DenomMetadata { } /// Replicates the cosmos-sdk bank module DenomUnit type -#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct DenomUnit { pub denom: String, pub exponent: u32, diff --git a/packages/std/src/never.rs b/packages/std/src/never.rs index 51173892f5..f63eadac01 100644 --- a/packages/std/src/never.rs +++ b/packages/std/src/never.rs @@ -25,6 +25,7 @@ /// let res: Result = Ok(5); /// assert_eq!(safe_unwrap(res), 5); /// ``` +#[derive(cw_schema::Schemaifier)] pub enum Never {} // The Debug implementation is needed to allow the use of `Result::unwrap`. diff --git a/packages/std/src/pagination.rs b/packages/std/src/pagination.rs index d9d1d8ef96..1b402d6169 100644 --- a/packages/std/src/pagination.rs +++ b/packages/std/src/pagination.rs @@ -4,7 +4,9 @@ use serde::{Deserialize, Serialize}; use crate::Binary; /// Simplified version of the PageRequest type for pagination from the cosmos-sdk -#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct PageRequest { pub key: Option, pub limit: u32, diff --git a/packages/std/src/results/contract_result.rs b/packages/std/src/results/contract_result.rs index e887c74500..f9ff679693 100644 --- a/packages/std/src/results/contract_result.rs +++ b/packages/std/src/results/contract_result.rs @@ -31,7 +31,7 @@ use crate::prelude::*; /// let result: ContractResult = ContractResult::Err(error_msg); /// assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#); /// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum ContractResult { Ok(S), diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index f35c79faeb..00449e5120 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -23,7 +23,7 @@ pub trait CustomMsg: Serialize + Clone + fmt::Debug + PartialEq + JsonSchema {} impl CustomMsg for Empty {} #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] // See https://github.com/serde-rs/serde/issues/1296 why we cannot add De-Serialize trait bounds to T pub enum CosmosMsg { @@ -88,7 +88,7 @@ impl CosmosMsg { /// /// See https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum BankMsg { /// Sends native tokens from the contract to the given address. @@ -110,7 +110,7 @@ pub enum BankMsg { /// See https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto #[cfg(feature = "staking")] #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum StakingMsg { /// This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). @@ -133,7 +133,7 @@ pub enum StakingMsg { /// See https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto #[cfg(feature = "staking")] #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum DistributionMsg { /// This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37). @@ -159,7 +159,7 @@ pub enum DistributionMsg { /// A message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). /// This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md) -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct AnyMsg { pub type_url: String, pub value: Binary, @@ -181,7 +181,7 @@ impl fmt::Display for BinaryToStringEncoder<'_> { /// /// See https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto #[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum WasmMsg { /// Dispatches a call to another contract at a known address (with known ABI). @@ -339,7 +339,7 @@ pub enum WasmMsg { /// } /// ``` #[cfg(feature = "stargate")] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum GovMsg { /// This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address. @@ -359,7 +359,7 @@ pub enum GovMsg { } #[cfg(feature = "stargate")] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum VoteOption { Yes, @@ -369,7 +369,7 @@ pub enum VoteOption { } #[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct WeightedVoteOption { pub option: VoteOption, pub weight: Decimal, diff --git a/packages/std/src/results/empty.rs b/packages/std/src/results/empty.rs index c3d3771d20..2e62c5a41d 100644 --- a/packages/std/src/results/empty.rs +++ b/packages/std/src/results/empty.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; /// It is designed to be expressable in correct JSON and JSON Schema but /// contains no meaningful data. Previously we used enums without cases, /// but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451) -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default, cw_schema::Schemaifier)] pub struct Empty {} #[cfg(test)] diff --git a/packages/std/src/results/events.rs b/packages/std/src/results/events.rs index 823a671a7c..d30a336f0c 100644 --- a/packages/std/src/results/events.rs +++ b/packages/std/src/results/events.rs @@ -12,7 +12,7 @@ use crate::prelude::*; /// /// [*Cosmos SDK* event]: https://docs.cosmos.network/main/learn/advanced/events /// [*Cosmos SDK* StringEvent]: https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/base/abci/v1beta1/abci.proto#L56-L70 -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[non_exhaustive] pub struct Event { /// The event type. This is renamed to "ty" because "type" is reserved in Rust. This sucks, we know. @@ -60,7 +60,7 @@ impl Event { } /// An key value pair that is used in the context of event attributes in logs -#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct Attribute { pub key: String, pub value: String, diff --git a/packages/std/src/results/response.rs b/packages/std/src/results/response.rs index 11bfcc1484..e185372b2d 100644 --- a/packages/std/src/results/response.rs +++ b/packages/std/src/results/response.rs @@ -60,7 +60,7 @@ use super::{Attribute, CosmosMsg, Empty, Event, SubMsg}; /// Ok(response) /// } /// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[non_exhaustive] pub struct Response { /// Optional list of messages to pass. These will be executed in order. diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index ac36fd0f7c..2326d8f92d 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -9,7 +9,7 @@ use super::{CosmosMsg, Empty, Event}; /// Use this to define when the contract gets a response callback. /// If you only need it for errors or success you can select just those in order /// to save gas. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum ReplyOn { /// Always perform a callback after SubMsg is processed @@ -28,7 +28,7 @@ pub enum ReplyOn { /// Note: On error the submessage execution will revert any partial state changes due to this message, /// but not revert any state changes in the calling contract. If this is required, it must be done /// manually in the `reply` entry point. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct SubMsg { /// An arbitrary ID chosen by the contract. /// This is typically used to match `Reply`s in the `reply` entry point to the submessage. @@ -166,7 +166,7 @@ impl SubMsg { /// The result object returned to `reply`. We always get the ID from the submessage /// back and then must handle success and error cases ourselves. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct Reply { /// The ID that the contract set when emitting the `SubMsg`. /// Use this to identify which submessage triggered the `reply`. @@ -226,7 +226,7 @@ pub struct Reply { /// let result = SubMsgResult::Err(error_msg); /// assert_eq!(to_json_string(&result).unwrap(), r#"{"error":"Something went wrong"}"#); /// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum SubMsgResult { Ok(SubMsgResponse), @@ -282,7 +282,7 @@ impl From for Result { /// The information we get back from a successful sub message execution, /// with full Cosmos SDK events. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct SubMsgResponse { pub events: Vec, #[deprecated = "Deprecated in the Cosmos SDK in favor of msg_responses. If your chain is running on CosmWasm 2.0 or higher, msg_responses will be filled. For older versions, the data field is still needed since msg_responses is empty in those cases."] @@ -298,7 +298,7 @@ pub struct SubMsgResponse { pub msg_responses: Vec, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] pub struct MsgResponse { pub type_url: String, pub value: Binary, diff --git a/packages/std/src/results/system_result.rs b/packages/std/src/results/system_result.rs index 0623d08589..34b5ac03a3 100644 --- a/packages/std/src/results/system_result.rs +++ b/packages/std/src/results/system_result.rs @@ -30,7 +30,7 @@ use crate::SystemError; /// let result: SystemResult = SystemResult::Err(error); /// assert_eq!(to_vec(&result).unwrap(), br#"{"error":{"unknown":{}}}"#); /// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier)] #[serde(rename_all = "snake_case")] pub enum SystemResult { Ok(S), diff --git a/packages/std/src/stdack.rs b/packages/std/src/stdack.rs index 953ea8099c..d5bd127cc1 100644 --- a/packages/std/src/stdack.rs +++ b/packages/std/src/stdack.rs @@ -34,7 +34,9 @@ use crate::Binary; /// let ack2 = StdAck::error("kaputt"); // Some free text error message /// assert!(ack2.is_error()); /// ``` -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] #[serde(rename_all = "snake_case")] pub enum StdAck { #[serde(rename = "result")] diff --git a/packages/std/src/timestamp.rs b/packages/std/src/timestamp.rs index 331304a03d..ee41cc27da 100644 --- a/packages/std/src/timestamp.rs +++ b/packages/std/src/timestamp.rs @@ -33,7 +33,9 @@ use crate::Uint64; PartialOrd, Ord, schemars::JsonSchema, + cw_schema::Schemaifier, )] +#[schemaifier(type = cw_schema::NodeType::Timestamp)] pub struct Timestamp(Uint64); impl Timestamp { diff --git a/packages/std/src/types.rs b/packages/std/src/types.rs index f85d42e8a0..371fae8c48 100644 --- a/packages/std/src/types.rs +++ b/packages/std/src/types.rs @@ -5,7 +5,9 @@ use crate::coin::Coin; use crate::prelude::*; use crate::{Addr, Timestamp}; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct Env { pub block: BlockInfo, /// Information on the transaction this message was executed in. @@ -15,7 +17,9 @@ pub struct Env { pub contract: ContractInfo, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct TransactionInfo { /// The position of this transaction in the block. The first /// transaction has index 0. @@ -26,7 +30,9 @@ pub struct TransactionInfo { pub index: u32, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct BlockInfo { /// The height of a block is the number of blocks preceding it in the blockchain. pub height: u64, @@ -87,7 +93,7 @@ pub struct BlockInfo { /// /// [MsgInstantiateContract]: https://github.com/CosmWasm/wasmd/blob/v0.15.0/x/wasm/internal/types/tx.proto#L47-L61 /// [MsgExecuteContract]: https://github.com/CosmWasm/wasmd/blob/v0.15.0/x/wasm/internal/types/tx.proto#L68-L78 -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, cw_schema::Schemaifier)] pub struct MessageInfo { /// The `sender` field from `MsgInstantiateContract` and `MsgExecuteContract`. /// You can think of this as the address that initiated the action (i.e. the message). What that @@ -105,7 +111,9 @@ pub struct MessageInfo { pub funds: Vec, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[derive( + Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier, +)] pub struct ContractInfo { pub address: Addr, }