-
Notifications
You must be signed in to change notification settings - Fork 31
Ts-codegen doesn't recognize types by reference #103
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
Comments
#102 didn't fix this issue |
To reproduce this issue: git clone https://github.com/CosmWasm/sylvia
cd sylvia/contracts/cw1-whitelist
cargo schema
cosmwasm-ts-codegen generate |
@adairrr here is shortened schema json {
"contract_name": "cw1-whitelist",
"contract_version": "0.3.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"admins",
"mutable"
],
"properties": {
"admins": {
"type": "array",
"items": {
"type": "string"
}
},
"mutable": {
"type": "boolean"
}
}
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"anyOf": [
{
"$ref": "#/definitions/ExecMsg"
}
],
"definitions": {
"ExecMsg": {
"type": "string",
"enum": []
}
}
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"anyOf": [
{
"$ref": "#/definitions/QueryMsg"
}
],
"definitions": {
"QueryMsg": {
"type": "string",
"enum": []
}
}
},
"migrate": null,
"sudo": null,
"responses": {}
} |
Yes, this issue is because sylvia has the definitions via reference which requires resolution prior to entering the logic. @pyramation is someone working on a solution for this already? |
Nobody is working on this feature yet. Not sure I understand the reference stuff, if there are some examples outputs we can put it on a todo list. If it's simple, would love to accept a PR :) |
I'm receiving a similar error but for Uint128. Unfortunately I can't substitute Uint128 for another structure because I use a Coin. I am not using sylvia. Can anyone point me in the right direction to fix? A friend is not experiencing this issue with his contract and it uses Uint128. edit He does experience it with my contract, however.
|
It is a long time since the issue was created, and there is an important question not been answered which I think is probably holding it:
I am as far from TS as I can be sop not using codegen directly, but I think I can help with that a bit. The idea is that the Rust schemars use refs to handle untagged enums. So the idea is that whenever we have two different #[derive(Serialize, Deserialize, JsonSchema)]
enum Foo {
Variant1 {
data: u32,
},
Variant2 {
name: String
},
Varient3 {}
}
#[derive(Serialize, Deserialize)]
enum Part1 {
Variant1 {
data: u32,
},
}
#[derive(Serialize, Deserialize)]
enum Part2 {
Variant2 {
name: String
},
Varient3 {}
}
#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
enum Bar {
P1(Part1),
P2(Part2),
} We want those In terms of refs themself, it is fairly simple - whenever there is I believe what might be more tricky there is the Things get trickier when What is needed to be done is that when you see the occurrence of The little thing to keep in mind is that the elements of Thu/Fri I will prepare the very simple post-processing tool which takes Sylvia schemas, and translates them to the schema accepted by codegen right now (it would perform this flattening), so I will link it here so you can use it as a reference (or figure out some more sophisticated solutions for a case of the mentioned conflict). |
Would you mind removing the 'raw' folder and any other schema files beside the contract schema and try again? There are sometimes weird conflicts. |
@hashedone yes, you are correct. This issue is not difficult to fix, though I currently do not have the bandwidth to implement the changes. @pyramation this issue would be great to prioritize over others as the number of developers using Sylvia increases. |
hey can somebody explain this to me from a TypeScript lens? I'm not a Rust/CosmWasm dev myself. Maybe @adairrr can you explain what changes may be needed to make this all work? |
the shortened schema isn't creating errors, can somebody make a PR to add to this branch the full schema causing trouble? here is the file to update: https://github.com/CosmWasm/ts-codegen/blob/issue-103/__fixtures__/issues/103/schema.json |
In the desire to get a reproduceable test case, I tried doing this (with a bit more documentation on version). $ node --version
v19.4.0
$ rustc --version
rustc 1.69.0 (84c898d65 2023-04-16)
$ npm install -g @cosmwasm/ts-codegen
$ git clone https://github.com/CosmWasm/sylvia
$ cd sylvia/contracts/cw1-whitelist
$ cargo schema
$ sha256sum schema/cw1-whitelist.json
4f330e56136aa6a654f951a0fba9241ccaf839e28158d563ba9d58de690b333d schema/cw1-whitelist.json
# this is the recommended cli usage in the README
$ cosmwasm-ts-codegen generate --plugin client --schema ./schema --out ./ts --name Cw1Whitelist --no-bundle Gives the following error:
|
Update: there was
After (I looked at |
this version is published for the |
@jawoznia Can you try this agaim with 0.28.0 version? It would be great if this works with Sylvia now. |
@pyramation @adairrr |
Thank you for the help! |
I have the execute message defined as such
This is a wrapper of three messages that my contract should support.
Schema.json generated for it (using write_api!) is:
So we have execute defined as any of theses three messages which are defined in
definitions
section.But when I ran
I get
It looks like ts-codegen doesn't understand ref to definition.
The text was updated successfully, but these errors were encountered: