Skip to content
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

[cosmwasm-schema] unknown serde variant attribute untagged #1990

Open
AmitPr opened this issue Jan 12, 2024 · 3 comments
Open

[cosmwasm-schema] unknown serde variant attribute untagged #1990

AmitPr opened this issue Jan 12, 2024 · 3 comments

Comments

@AmitPr
Copy link
Contributor

AmitPr commented Jan 12, 2024

When trying to add serde attributes, I get the "unknown serde variant attribute" error. Sample code:

#[cw_serde]
pub enum Parent {
    Foo { x: u128 },
    Bar { y: String },
    #[serde(untagged)]
    Baz(Child),
}

#[cw_serde]
pub enum Child {
    A { x: u128 },
    B { y: String },
}

And the compiler error:

error: unknown serde variant attribute `untagged`
   |
56 |     #[serde(untagged)]
   |             ^^^^^^^^
@AmitPr
Copy link
Contributor Author

AmitPr commented Jan 12, 2024

Just to elaborate, this would be used to effectively "embed" or "inherit" another ExecuteMsg, for example, to implement a standard interface. If there's a better way to do this ergonomically I'm all ears, but I found this error preventing me from the most idiomatic solution.

@AmitPr
Copy link
Contributor Author

AmitPr commented Jan 12, 2024

Seems like this happens when JsonSchema is derived on the enum: GREsau/schemars#222

Maybe there could be an option such as #[cw_serde(schema=false)]

@chipshort
Copy link
Collaborator

You have two options here:

  • Don't use #[cw_serde]: It's just an alias for a bunch of attributes, so you can just add them yourself, omitting JsonSchema. See here for the attributes.
  • Put the #[serde(untagged)] on the enum itself and wrap your messages in another enum. Then your example would look like this:
#[cw_serde]
#[serde(untagged)]
pub enum Parent {
    MyMsgs(MyMsgs),
    Baz(Child),
}

#[cw_serde]
pub enum MyMsgs {
    Foo { x: u128 },
    Bar { y: String },
}

#[cw_serde]
pub enum Child {
    A { x: u128 },
    B { y: String },
}

One thing to note here is that in the past, #[serde(untagged)] produced float operations, so the contract will be limited to 1.5+ chains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants