Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __fixtures__/issues/103/raw/duplicate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contract_name": "something-in-raw-folder"
}
58 changes: 58 additions & 0 deletions __fixtures__/issues/103/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"contract_name": "cw1-whitelist",
"contract_version": "0.3.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string",
"enum": []
}
}
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string",
"enum": []
}
}
},
"migrate": null,
"sudo": null,
"responses": {}
}
109 changes: 109 additions & 0 deletions __output__/issues/103/clean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"schemas": [
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string"
}
}
},
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string"
}
}
}
],
"responses": {},
"idlObject": {
"contract_name": "cw1-whitelist",
"contract_version": "0.3.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string"
}
}
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string"
}
}
},
"migrate": null,
"sudo": null,
"responses": {}
}
}
113 changes: 113 additions & 0 deletions __output__/issues/103/orig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"schemas": [
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string",
"enum": []
}
}
},
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string",
"enum": []
}
}
}
],
"responses": {},
"idlObject": {
"contract_name": "cw1-whitelist",
"contract_version": "0.3.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string",
"enum": []
}
}
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string",
"enum": []
}
}
},
"migrate": null,
"sudo": null,
"responses": {}
}
}
11 changes: 11 additions & 0 deletions packages/ts-codegen/__tests__/cleanse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ it('daodao/cw-code-id-registry', async () => {
mkdirp(out);
writeFileSync(out + '/orig.json', JSON.stringify(orig, null, 2));
writeFileSync(out + '/clean.json', JSON.stringify(clean, null, 2));
})

it('issues/103', async () => {
const out = OUTPUT_DIR + '/issues/103';
const schemaDir = FIXTURE_DIR + '/issues/103/';

const clean = await readSchemas({ schemaDir, clean: true });
const orig = await readSchemas({ schemaDir, clean: false });

mkdirp(out);
writeFileSync(out + '/orig.json', JSON.stringify(orig, null, 2));
writeFileSync(out + '/clean.json', JSON.stringify(clean, null, 2));
})

4 changes: 3 additions & 1 deletion packages/ts-codegen/src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const readSchemas = async ({
schemaDir, clean = true
}: ReadSchemaOpts): Promise<ContractInfo> => {
const fn = clean ? cleanse : (str) => str;
const files = glob(schemaDir + '/**/*.json');
const files = glob(schemaDir + '/**/*.json')
.filter(file => !file.match(/\/raw\//));

const schemas = files
.map(file => JSON.parse(readFileSync(file, 'utf-8')));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`execute execute classes array types 1`] = `
"export class Client implements Instance {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
}

}"
`;

exports[`execute execute interfaces no extends 1`] = `
"export interface SG721Instance {
contractAddress: string;
sender: string;
}"
`;

exports[`execute execute_msg_for__empty 1`] = `"export type ExecuteMsg = ExecuteMsg;"`;

exports[`execute query classes 1`] = `
"export class QueryClient implements ReadOnlyInstance {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
}

}"
`;

exports[`execute query classes response 1`] = `"export type QueryMsg = QueryMsg;"`;

exports[`query execute classes array types 1`] = `
"export class Client implements Instance {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
}

}"
`;

exports[`query execute interfaces no extends 1`] = `
"export interface SG721Instance {
contractAddress: string;
sender: string;
}"
`;

exports[`query execute_msg_for__empty 1`] = `"export type QueryMsg = QueryMsg;"`;

exports[`query query classes 1`] = `
"export class QueryClient implements ReadOnlyInstance {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
}

}"
`;

exports[`query query classes response 1`] = `"export type QueryMsg = QueryMsg;"`;
Loading