hyperweb-io / hyperweb-io/ts-codegen

Supports untagged enum

未关闭
#89 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
126
派生
31
平均合并
19 分钟
30 天内合并 PR
2

描述

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

```rs
#[cw_serde]
#[serde(untagged)]
pub enum ExecuteMsg {
CW721Base(cw721_base::ExecuteMsg),
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](https://github.com/CosmWasm/ts-codegen/blob/cffa2acebb86f3c1f96fb00c4abae5ba0987e63e/packages/wasm-ast-types/src/client/client.ts#L266)

贡献指南

这个仓库没有索引到贡献指南

调研方向

问题出在 packages/wasm-ast-types/src/client/client.ts 的第 266 行,生成的 schema 的 execute 值缺少属性。首先跟踪这段代码如何处理所提供的 draft-07 schema 中的 anyOf 和被引用的定义。当 ts-codegen 能够为所示的 serde(untagged) ExecuteMsg 生成代码,且不会尝试对缺失的属性调用 Object.keys 时,即可完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust, typescript
领域
tooling
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。