jonasbb / serde_with

This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
https://docs.rs/serde_with
Apache License 2.0
638 stars 67 forks source link

Implement JsonSchemaAs for KeyValueMap #713

Closed swlynch99 closed 6 months ago

swlynch99 commented 6 months ago

I'm back with yet another PR! This time we're doing KeyValueMap.

I think this one is probably the most complicated conversion that needs to be done to make the schema work. We need to convert a schema that looks like this

{
  "type": "object",
  "properties": {
    "$key$": "...",
    "a": "...",
  },
  "required": ["$key$", "a"]
}

into this

{
  "type": "object",
  "additionalProperties": {
    "type": "object",
    "required": ["a"],
    "properties": { "a": "..." }
  }
}

On its own that is not to bad but it gets more complicated since we also have to deal subschemas which can be generated from types that make use of #[serde(untagged)] and #[serde(flatten)]. See the doc comment on kvmap_transform_schema for more details.

Notes

swlynch99 commented 6 months ago

The CI errors all seem to be related to the #[warn(unused_qualifications)] lint in Cargo.toml. That doesn't seem related to this PR and when I went to fix them the suggestions from cargo clippy --fix seemed like they would be invalid under #[no_std]. I'll leave this one up to you to fix and/or disable the lints and then rebase once that is done.

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 75.64103% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 66.04%. Comparing base (4c05768) to head (a804257). Report is 1 commits behind head on master.

Files Patch % Lines
serde_with/src/schemars_0_8.rs 75.64% 19 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #713 +/- ## ========================================== + Coverage 65.64% 66.04% +0.40% ========================================== Files 38 38 Lines 2343 2421 +78 ========================================== + Hits 1538 1599 +61 - Misses 805 822 +17 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jonasbb commented 6 months ago

Thank you, this looks good. Your comments are good, explain what is going on, and I could follow them. Thanks for getting this to work :)