CosmWasm / ts-codegen

Convert your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
https://cosmology.zone/products/ts-codegen
Apache License 2.0
116 stars 27 forks source link

support for definition in queryMsg / execMsg in schemas #98

Closed whalelephant closed 1 year ago

whalelephant commented 1 year ago

When generating schemas from sylvia framework written contracts, the queryMsg (and execMsg) is a ref to a definition, this causes error in ts-codegen.

/Users/.../node_modules/wasm-ast-types/main/client/client.js:175
  var methods = (0, _utils.getMessageProperties)(queryMsg).map(function (jsonschema) {
                                                           ^

Example of the schema

"query": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "QueryMsg",
    "anyOf": [
      {
        "$ref": "#/definitions/InstallableQueryMsg"
      },
      {
        "$ref": "#/definitions/QueryMsg"
      }
    ],
    "definitions": {
      "InstallableQueryMsg": {
        "type": "string",
        "enum": []
      },
      "QueryMsg": {
        "oneOf": [
          { ...}

full version: https://gist.github.com/whalelephant/957540ad83f8a35c05cd08fa7a009385#file-schema-json-L281

adairrr commented 1 year ago

@pyramation I believe that this is an issue with parsing the entry-point messages here:

https://github.com/CosmWasm/ts-codegen/blob/10c8be3191cc16e89df92030662227e267c2df34/packages/ts-codegen/src/utils/schemas.ts#L73-L102

We should be collapsing the schema first to find them.

pyramation commented 1 year ago

should be fixed!

Successfully published:
 - @cosmwasm/ts-codegen@0.26.0