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

Implement JsonSchemaAs for OneOrMany #719

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

swlynch99
Copy link
Contributor

Here's the next type. This one implements JsonSchemaAs for OneOrMany. It is fortunately much simpler than KeyValueMap.

For OneOrMany the transformation we want to do is basically to take this schema

{ "$ref": "..." }

and transform it into

{
  "anyOf": [
    { "$ref": "..." },
    {
      "type": "array",
      "items": { "$ref": "..." }
    }
  ]
}

that is, we change it so it can take either an array or a single value. The only difference between the PreferOne and the PreferMany variants is that the inner object is marked as writeOnly: true.

I have also included some tests that should cover pretty much everything.

@swlynch99 swlynch99 force-pushed the schemars-one-or-many branch from a1a0419 to 86ab7e5 Compare March 11, 2024 21:12
@swlynch99 swlynch99 force-pushed the schemars-one-or-many branch from 86ab7e5 to 5e36083 Compare March 11, 2024 21:15
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

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

Project coverage is 66.21%. Comparing base (bb2ab60) to head (5e36083).
Report is 5 commits behind head on master.

Files Patch % Lines
serde_with/src/schemars_0_8.rs 83.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #719      +/-   ##
==========================================
+ Coverage   65.64%   66.21%   +0.57%     
==========================================
  Files          38       38              
  Lines        2343     2445     +102     
==========================================
+ Hits         1538     1619      +81     
- Misses        805      826      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonasbb
Copy link
Owner

jonasbb commented Mar 11, 2024

That looks great :) Thank you.

@jonasbb jonasbb merged commit 7e9772f into jonasbb:master Mar 11, 2024
22 checks passed
@jonasbb
Copy link
Owner

jonasbb commented Mar 11, 2024

I published your new JsonSchemaAs implementations and fix for the serde_as macro in v3.7.0

@swlynch99 swlynch99 deleted the schemars-one-or-many branch March 11, 2024 21:55
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.

2 participants