hyperweb-io/ts-codegen

Supports untagged enum

Opened this issue · 5 comments

Current ts-codegen can't generate code from the following schema

{ 
  ...
  "execute": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "ExecuteMsg",
      "anyOf": [
        {
          "$ref": "#/definitions/ExecuteMsg_for_Nullable_Empty_and_Empty"
        },
        {
          "$ref": "#/definitions/ICNSNameExecuteMsg"
        }
      ],
      "definitions": { ... },
  ...
}

as it tries to find properties under value of "execute" but it couldn't find one.

This schema is generated from

#[cw_serde]
#[serde(untagged)]
pub enum ExecuteMsg {
    CW721Base(cw721_base::ExecuteMsg<cw721_base::Extension, Empty>),
    ICNSName(ICNSNameExecuteMsg),
}

It fails as it tries to find Object.keys on execute's properties but it couldn't find one on this line of code

hey @iboss-ptk can you send me a full schema I can use for testing?

Also, what is the expectation of ExecuteMsg_for_Nullable_Empty_and_Empty, I know it may be unrelated, but perhaps ExecuteMsgForNullableEmptyAndEmpty?

It's from ExecuteMsg<Option<Empty>,Empty>, I'm remapping it with name and it works fine now. Not sure of a good representation in ts, your suggestion should just work as well.

will sent you the schema for testing

cool, lmk!