[cosmwasm-schema] unknown serde variant attribute `untagged`
AmitPr opened this issue · comments
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)]
| ^^^^^^^^
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.
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)]
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, omittingJsonSchema
. 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.