Skip to content

Ts-codegen doesn't recognize types by reference #103

Closed
@jawoznia

Description

@jawoznia

I have the execute message defined as such

#[derive(sylvia::serde::Serialize, Clone, Debug, PartialEq, sylvia::schemars::JsonSchema)]
#[serde(rename_all = "snake_case", untagged)]
pub enum ContractExecMsg {
    Cw1(cw1::Cw1ExecMsg),
    Whitelist(whitelist::WhitelistExecMsg),
    Cw1WhitelistContract(ExecMsg),
}

This is a wrapper of three messages that my contract should support.

Schema.json generated for it (using write_api!) is:

  "execute": {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "ExecuteMsg",
    "anyOf": [
      {
        "$ref": "#/definitions/Cw1ExecMsg"
      },
      {
        "$ref": "#/definitions/WhitelistExecMsg"
      },
      {
        "$ref": "#/definitions/ExecMsg"
      }
    ],
    "definitions": 
    ...
      "Cw1ExecMsg": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "execute"
            ],
            "properties": {
              "execute": {
                "type": "object",
                "required": [
                  "msgs"
                ],
                "properties": {
                  "msgs": {
                    "type": "array",
                    "items": {
                      "$ref": "#/definitions/CosmosMsg_for_Empty"
                    }
                  }
                }
              }
            },
            "additionalProperties": false
          }
        ]
      },
    ...

So we have execute defined as any of theses three messages which are defined in definitions section.
But when I ran

cosmwasm-ts-codegen generate \
          --plugin client \
          --schema ./schema \
          --out ./ts \
          --name whitelist \
          --no-bundle

I get

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

MissingPointerError: Token "Cw1ExecMsg" does not exist.
    at Pointer.resolve (/usr/lib/node_modules/@cosmwasm/ts-codegen/node_modules/@pyramation/json-schema-ref-parser
}

It looks like ts-codegen doesn't understand ref to definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions