Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate crashes with Empty enum msg #27

Closed
de-husk opened this issue Jun 25, 2022 · 5 comments
Closed

Generate crashes with Empty enum msg #27

de-husk opened this issue Jun 25, 2022 · 5 comments

Comments

@de-husk
Copy link

de-husk commented Jun 25, 2022

Having an empty QueryMsg enum:

pub enum QueryMsg {}

https://github.com/DA0-DA0/dao-contracts/pull/370/files#diff-840200e9bacf09b0b4728e7462feae7f2bd9cfbc92ae5d3cfe330c1a47b0ff9cR22

Causes an error when generating the ts files:

SyntaxError: '=>' expected. (9:1)
  7 |
  8 | export type QueryMsg = ()
> 9 |
    | ^
    at Ve (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:1:[15](https://github.com/DA0-DA0/dao-contracts/runs/7050221031?check_suite_focus=true#step:5:16)607)
    at vz (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:280:5919)
    at Object.yz [as parse] (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/parser-typescript.js:280:6242)
    at Object.parse (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/index.js:7334:23)
    at coreFormat (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/index.js:8645:18)
    at formatWithCursor2 (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/index.js:8837:18)
    at /home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/index.js:37226:12
    at Object.format (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/node_modules/prettier/index.js:37240:12)
    at Object.format (/home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/dist/src/formatter.js:20:23)
    at /home/runner/work/dao-contracts/dao-contracts/types/node_modules/json-schema-to-typescript/dist/src/index.js:[17](https://github.com/DA0-DA0/dao-contracts/runs/7050221031?check_suite_focus=true#step:5:18)0:45 {
  loc: { start: { line: 9, column: 1 } },
  codeFrame: '  7 |\n  8 | export type QueryMsg = ()\n> 9 |\n    | ^'
}

https://github.com/DA0-DA0/dao-contracts/runs/7050221031?check_suite_focus=true#step:5:14

The json schema when exporting an empty enum:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "QueryMsg",
  "type": "string",
  "enum": []
}
@pyramation
Copy link
Collaborator

Thanks for reporting! Will get this ASAP

tracking here https://github.com/CosmWasm/cosmwasm-typescript-gen/tree/fix/empty-enums

@pyramation
Copy link
Collaborator

ok, so I've discovered this is an error in a dependency. Will be pushing upstream.
bcherny/json-schema-to-typescript#463

@pyramation
Copy link
Collaborator

pyramation commented Jun 25, 2022

Until either they fix the issue or we write our own processor (#7), It looks like we can delete the empty enums, or potentially look for these and pre-process JSON schema files and potentially see what modifications we need to make.

A temporary solution:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "QueryMsg",
  "type": "string",
  "enum": []
}

will compile with a change to

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "QueryMsg",
  "type": "string"
}

I could look for schemas that have this type:string, enum: [] scenario, and delete the enum field in this case.

pyramation added a commit that referenced this issue Jun 25, 2022
@pyramation
Copy link
Collaborator

@de-husk

npm install -g cosmwasm-typescript-gen@0.3.6

@de-husk
Copy link
Author

de-husk commented Jun 28, 2022

Thanks again for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants