Skip to content

Added better map support#452

Merged
GREsau merged 5 commits intoGREsau:masterfrom
staratlasmeta:better-map-support
Dec 25, 2025
Merged

Added better map support#452
GREsau merged 5 commits intoGREsau:masterfrom
staratlasmeta:better-map-support

Conversation

@Buzzec
Copy link
Copy Markdown
Contributor

@Buzzec Buzzec commented Jul 2, 2025

Supports map verification for enum keys for both unit variants and #[serde(untagged)] variants. Still defaults back to string keys in other cases.

Closes #424
Closes #384

@Buzzec
Copy link
Copy Markdown
Contributor Author

Buzzec commented Jul 9, 2025

@GREsau Is there anything we need to do for this PR? AFAICT this is fully compatible with serde_json and just adds specificity. We'd love to get this merged so we can move off private dependencies on this branch in our production environment.

@stegaBOB
Copy link
Copy Markdown
Contributor

stegaBOB commented Dec 4, 2025

Hey @GREsau would be great to get this in. We're still stuck with using our fork for the time being

@oknozor
Copy link
Copy Markdown

oknozor commented Dec 23, 2025

Same here @GREsau, stuck with my fork that support enum. We'd love to see this merged.

@GREsau GREsau merged commit 2ac8ff5 into GREsau:master Dec 25, 2025
6 checks passed
GREsau added a commit that referenced this pull request Dec 25, 2025
@GREsau
Copy link
Copy Markdown
Owner

GREsau commented Dec 25, 2025

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 serde_json::from_str here fails:

#[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!

@GREsau
Copy link
Copy Markdown
Owner

GREsau commented Dec 26, 2025

I believe the deserialization issue I mentioned above is a case of serde-rs/serde#1183

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

Successfully merging this pull request may close these issues.

Provide verification and completion for HashMap's key

4 participants