diff --git a/.gitignore b/.gitignore index dfdaaa6..9095dea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Build results /target +/schema # Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) .cargo-ok diff --git a/examples/schema.rs b/examples/schema.rs index 055cb4a..b378cc2 100644 --- a/examples/schema.rs +++ b/examples/schema.rs @@ -1,20 +1,11 @@ -use std::env::current_dir; -use std::fs::create_dir_all; +use cosmwasm_schema::write_api; -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; - -use {{crate_name}}::msg::{ExecuteMsg, GetCountResponse, InstantiateMsg, QueryMsg}; -use {{crate_name}}::state::State; +use {{crate_name}}::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - export_schema(&schema_for!(InstantiateMsg), &out_dir); - export_schema(&schema_for!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); - export_schema(&schema_for!(State), &out_dir); - export_schema(&schema_for!(GetCountResponse), &out_dir); + write_api! { + instantiate: InstantiateMsg, + execute: ExecuteMsg, + query: QueryMsg, + } } diff --git a/schema/execute_msg.json b/schema/execute_msg.json deleted file mode 100644 index 6fa0a75..0000000 --- a/schema/execute_msg.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ExecuteMsg", - "anyOf": [ - { - "type": "object", - "required": [ - "increment" - ], - "properties": { - "increment": { - "type": "object" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "reset" - ], - "properties": { - "reset": { - "type": "object", - "required": [ - "count" - ], - "properties": { - "count": { - "type": "integer", - "format": "int32" - } - } - } - }, - "additionalProperties": false - } - ] -} diff --git a/schema/get_count_response.json b/schema/get_count_response.json deleted file mode 100644 index 02619f0..0000000 --- a/schema/get_count_response.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "GetCountResponse", - "type": "object", - "required": [ - "count" - ], - "properties": { - "count": { - "type": "integer", - "format": "int32" - } - } -} diff --git a/schema/instantiate_msg.json b/schema/instantiate_msg.json deleted file mode 100644 index e794ec1..0000000 --- a/schema/instantiate_msg.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "InstantiateMsg", - "type": "object", - "required": [ - "count" - ], - "properties": { - "count": { - "type": "integer", - "format": "int32" - } - } -} diff --git a/schema/query_msg.json b/schema/query_msg.json deleted file mode 100644 index be0245b..0000000 --- a/schema/query_msg.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "anyOf": [ - { - "type": "object", - "required": [ - "get_count" - ], - "properties": { - "get_count": { - "type": "object" - } - }, - "additionalProperties": false - } - ] -} diff --git a/schema/state.json b/schema/state.json deleted file mode 100644 index e18725d..0000000 --- a/schema/state.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "State", - "type": "object", - "required": [ - "count", - "owner" - ], - "properties": { - "count": { - "type": "integer", - "format": "int32" - }, - "owner": { - "$ref": "#/definitions/Addr" - } - }, - "definitions": { - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - } - } -}