Skip to content

Commit

Permalink
generate schemas for entry points, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Jun 13, 2024
1 parent 67522f7 commit a5652e2
Show file tree
Hide file tree
Showing 39 changed files with 2,338 additions and 2,707 deletions.
154 changes: 73 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cw721-base-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0"
cw721-base-017 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.17.0", package = "cw721-base" } # needed for testing legacy migration
cw721-base-018 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.18.0", package = "cw721-base" } # needed for testing legacy migration
cw-multi-test = "^0.20"
cw-ownable = { git = "https://github.com/public-awesome/cw-plus-plus.git", branch = "multiple_ownership"} # TODO: switch to official https://github.com/larry0x/cw-plus-plus once merged
cw-ownable = { git = "https://github.com/public-awesome/cw-plus-plus.git", rev = "28c1a09bfc6b4f1942fefe3eb0b50faf9d3b1523"} # TODO: switch to official https://github.com/larry0x/cw-plus-plus once merged
cw-storage-plus = "^1.1"
cw-utils = "^1.0"
schemars = "^0.8"
Expand Down
8 changes: 0 additions & 8 deletions contracts/cw2981-royalties/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ pub enum QueryMsg {
Extension { msg: Extension },
}

// impl Default for Cw2981QueryMsg {
// fn default() -> Self {
// Cw2981QueryMsg::CheckRoyalties {}
// }
// }

// impl CustomMsg for Cw2981QueryMsg {}

impl From<QueryMsg> for Cw721QueryMsg<Extension> {
fn from(msg: QueryMsg) -> Cw721QueryMsg<Extension> {
match msg {
Expand Down
1 change: 1 addition & 0 deletions contracts/cw721-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-ownable = { workspace = true }
cw2 = { workspace = true }
Expand Down
23 changes: 23 additions & 0 deletions contracts/cw721-base/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use cosmwasm_schema::{export_schema_with_title, remove_schemas, schema_for};
use cosmwasm_std::Empty;
use cw721::state::DefaultOptionMetadataExtension;
use cw721_base::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use std::env::current_dir;
use std::fs::create_dir_all;

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

// entry points - generate always with title for avoiding name suffixes like "..._empty_for_..." due to generics
export_schema_with_title(&schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(
&schema_for!(ExecuteMsg::<DefaultOptionMetadataExtension, Empty>),
&out_dir,
"ExecuteMsg",
);
export_schema_with_title(&schema_for!(QueryMsg<Empty>), &out_dir, "QueryMsg");
export_schema_with_title(&schema_for!(MigrateMsg), &out_dir, "MigrateMsg");
}
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions contracts/cw721-base/schema/migrate_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"oneOf": [
{
"type": "object",
"required": [
"with_update"
],
"properties": {
"with_update": {
"type": "object",
"properties": {
"creator": {
"type": [
"string",
"null"
]
},
"minter": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
File renamed without changes.
2 changes: 2 additions & 0 deletions contracts/cw721-base/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cosmwasm_std::CustomMsg;

// expose to all others using contract, so others dont need to import cw721
pub use cw721::state::*;

use serde::de::DeserializeOwned;
use serde::Serialize;

Expand Down
25 changes: 19 additions & 6 deletions contracts/cw721-expiration/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use cosmwasm_schema::write_api;
use cosmwasm_schema::{export_schema_with_title, remove_schemas, schema_for};
use cosmwasm_std::Empty;
use cw721_expiration::msg::{InstantiateMsg, QueryMsg};
use cw721::state::DefaultOptionMetadataExtension;
use cw721_expiration::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use std::env::current_dir;
use std::fs::create_dir_all;

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg<Empty>,
}
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

// entry points - generate always with title for avoiding name suffixes like "..._empty_for_..." due to generics
export_schema_with_title(&schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(
&schema_for!(ExecuteMsg::<DefaultOptionMetadataExtension, Empty>),
&out_dir,
"ExecuteMsg",
);
export_schema_with_title(&schema_for!(QueryMsg<Empty>), &out_dir, "QueryMsg");
export_schema_with_title(&schema_for!(MigrateMsg), &out_dir, "MigrateMsg");
}
Loading

0 comments on commit a5652e2

Please sign in to comment.