Conversation
|
@GREsau Is there anything we need to do for this PR? AFAICT this is fully compatible with |
|
Hey @GREsau would be great to get this in. We're still stuck with using our fork for the time being |
|
Same here @GREsau, stuck with my fork that support enum. We'd love to see this merged. |
|
Thanks, this is now published in schemars 1.2.0 - merry christmas! I also added some test coverage in 18826cd. This revealed a slight issue in that, while serde allows serializing untagged non-string newtype variants, it doesn't allow deserializing them. e.g. the #[derive(Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
enum Enum {
#[serde(untagged)]
UntaggedU32(i32),
}
fn main() {
let map: HashMap<Enum, bool> = HashMap::from_iter([(Enum::UntaggedU32(1), true)]);
// ok:
let serialized = serde_json::to_string_pretty(&map).unwrap();
// error: "data did not match any variant of untagged enum Enum"
let deserialized: HashMap<Enum, bool> = serde_json::from_str(&serialized).unwrap();
}So while the deserialize schema generated for this case is not accurate (because it assumes that the deserialize contract is the same as the serialize contract), it was also inaccurate before this PR - so I saw no reason to hold off from merging and publish it! |
|
I believe the deserialization issue I mentioned above is a case of serde-rs/serde#1183 |
Supports map verification for
enumkeys for both unit variants and#[serde(untagged)]variants. Still defaults back to string keys in other cases.Closes #424
Closes #384