Skip to content

Commit

Permalink
make schema gen export raw schemas by default
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Nov 21, 2022
1 parent c15d57d commit c3e1169
Show file tree
Hide file tree
Showing 72 changed files with 9,262 additions and 27 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to
the `cosmwasm_1_2` feature needs to be enabled for the `cosmwasm_std`
dependency. This makes the contract incompatible with chains running versions
of CosmWasm earlier than 1.2.0 ([#1481]).
- cosmwasm-schema: In contracts, `cosmwasm schema` will now output a separate
JSON Schema file for each entrypoint in the `raw` subdirectory.

[#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481

Expand All @@ -34,9 +36,6 @@ and this project adheres to
`CanonicalAddr` ([#1463]).
- cosmwasm-std: Implement `PartialEq` between `CanonicalAddr` and
`HexBinary`/`Binary` ([#1463]).
- cosmwasm-schema: In contracts, `cosmwasm schema` now accepts the `--basic`
flag. This will output a separate JSON Schema file for each entrypoint,
similar to the old way. No unified file is produced this way.

[#1463]: https://github.com/CosmWasm/cosmwasm/pull/1463

Expand Down
7 changes: 7 additions & 0 deletions contracts/burner/schema/raw/instantiate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"description": "A placeholder where we don't take any input",
"type": "object",
"additionalProperties": false
}
6 changes: 6 additions & 0 deletions contracts/crypto-verify/schema/raw/instantiate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ListVerificationsResponse",
"type": "object",
"required": [
"verification_schemes"
],
"properties": {
"verification_schemes": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifyResponse",
"type": "object",
"required": [
"verifies"
],
"properties": {
"verifies": {
"type": "boolean"
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifyResponse",
"type": "object",
"required": [
"verifies"
],
"properties": {
"verifies": {
"type": "boolean"
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifyResponse",
"type": "object",
"required": [
"verifies"
],
"properties": {
"verifies": {
"type": "boolean"
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifyResponse",
"type": "object",
"required": [
"verifies"
],
"properties": {
"verifies": {
"type": "boolean"
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifyResponse",
"type": "object",
"required": [
"verifies"
],
"properties": {
"verifies": {
"type": "boolean"
}
},
"additionalProperties": false
}
52 changes: 52 additions & 0 deletions contracts/cyberpunk/schema/raw/execute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"description": "Hashes some data. Uses CPU and memory, but no external calls.",
"type": "object",
"required": [
"argon2"
],
"properties": {
"argon2": {
"type": "object",
"required": [
"mem_cost",
"time_cost"
],
"properties": {
"mem_cost": {
"description": "The amount of memory requested (KB).",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"time_cost": {
"description": "The number of passes.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the env for testing",
"type": "object",
"required": [
"mirror_env"
],
"properties": {
"mirror_env": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
6 changes: 6 additions & 0 deletions contracts/cyberpunk/schema/raw/instantiate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt 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)",
"type": "object"
}
52 changes: 52 additions & 0 deletions contracts/cyberpunk/schema/raw/migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"description": "Hashes some data. Uses CPU and memory, but no external calls.",
"type": "object",
"required": [
"argon2"
],
"properties": {
"argon2": {
"type": "object",
"required": [
"mem_cost",
"time_cost"
],
"properties": {
"mem_cost": {
"description": "The amount of memory requested (KB).",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"time_cost": {
"description": "The number of passes.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the env for testing",
"type": "object",
"required": [
"mirror_env"
],
"properties": {
"mirror_env": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
52 changes: 52 additions & 0 deletions contracts/cyberpunk/schema/raw/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"description": "Hashes some data. Uses CPU and memory, but no external calls.",
"type": "object",
"required": [
"argon2"
],
"properties": {
"argon2": {
"type": "object",
"required": [
"mem_cost",
"time_cost"
],
"properties": {
"mem_cost": {
"description": "The amount of memory requested (KB).",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"time_cost": {
"description": "The number of passes.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the env for testing",
"type": "object",
"required": [
"mirror_env"
],
"properties": {
"mirror_env": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
98 changes: 98 additions & 0 deletions contracts/cyberpunk/schema/raw/response_to_mirror_env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Env",
"type": "object",
"required": [
"block",
"contract"
],
"properties": {
"block": {
"$ref": "#/definitions/BlockInfo"
},
"contract": {
"$ref": "#/definitions/ContractInfo"
},
"transaction": {
"description": "Information on the transaction this message was executed in. The field is unset when the `MsgExecuteContract`/`MsgInstantiateContract`/`MsgMigrateContract` is not executed as part of a transaction.",
"anyOf": [
{
"$ref": "#/definitions/TransactionInfo"
},
{
"type": "null"
}
]
}
},
"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"
},
"BlockInfo": {
"type": "object",
"required": [
"chain_id",
"height",
"time"
],
"properties": {
"chain_id": {
"type": "string"
},
"height": {
"description": "The height of a block is the number of blocks preceding it in the blockchain.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"time": {
"description": "Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).\n\nThe source of this is the [BFT Time in Tendermint](https://github.com/tendermint/tendermint/blob/58dc1726/spec/consensus/bft-time.md), which has the same nanosecond precision as the `Timestamp` type.\n\n# Examples\n\nUsing chrono:\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; # extern crate chrono; use chrono::NaiveDateTime; let seconds = env.block.time.seconds(); let nsecs = env.block.time.subsec_nanos(); let dt = NaiveDateTime::from_timestamp(seconds as i64, nsecs as u32); ```\n\nCreating a simple millisecond-precision timestamp (as used in JavaScript):\n\n``` # use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, MessageInfo, Timestamp, TransactionInfo}; # let env = Env { # block: BlockInfo { # height: 12_345, # time: Timestamp::from_nanos(1_571_797_419_879_305_533), # chain_id: \"cosmos-testnet-14002\".to_string(), # }, # transaction: Some(TransactionInfo { index: 3 }), # contract: ContractInfo { # address: Addr::unchecked(\"contract\"), # }, # }; let millis = env.block.time.nanos() / 1_000_000; ```",
"allOf": [
{
"$ref": "#/definitions/Timestamp"
}
]
}
}
},
"ContractInfo": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"$ref": "#/definitions/Addr"
}
}
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"TransactionInfo": {
"type": "object",
"required": [
"index"
],
"properties": {
"index": {
"description": "The position of this transaction in the block. The first transaction has index 0.\n\nThis allows you to get a unique transaction indentifier in this chain using the pair (`env.block.height`, `env.transaction.index`).",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
}
}
}
Loading

0 comments on commit c3e1169

Please sign in to comment.