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 instead of JsonSchema #760

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

swlynch99
Copy link
Contributor

Currently, there is an impl JsonSchema for WrapSchema<OneOrMany<...>>. This works fine if you only directly need OneOrMany but causes errors if you want to nest it (e.g. Option<OneOrMany<_>>).

This PR changes the impl to a JsonSchemaAs impl, which is the correct approach. I think I just missed these ones during a rebase. In any case, the change should be fully backwards compatible due to the blanket schema impl.

I have added a snapshot test. The actual snapshot doesn't matter - the real test is that the struct below compiles

#[serde_as]
#[derive(Serialize, Deserialize, JsonSchema)]
struct Test {
    #[serde_as(as = "Option<OneOrMany<_>>")]
    optional_vec: Option<Vec<String>>,
}

Currently, there is an `impl JsonSchema for WrapSchema<OneOrMany<...>>`.
This works fine if you only directly need `OneOrMany` but causes errors
if you want to nest it (e.g. `Option<OneOrMany<_>>`).

This PR changes the impl to a `JsonSchemaAs` impl, which is the correct
approach. I think I just missed these ones during a rebase. In any case,
the change should be fully backwards compatible due to the blanket
schema impl.

I have added a snapshot test. The actual snapshot doesn't matter - the
real test is that the struct below compiles

    #[serde_as]
    #[derive(Serialize, Deserialize, JsonSchema)]
    struct Test {
	#[serde_as(as = "Option<OneOrMany<_>>")]
	optional_vec: Option<Vec<String>>,
    }
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.25%. Comparing base (1e4481c) to head (dee706a).
Report is 21 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #760      +/-   ##
==========================================
+ Coverage   66.55%   67.25%   +0.69%     
==========================================
  Files          38       38              
  Lines        2473     2452      -21     
==========================================
+ Hits         1646     1649       +3     
+ Misses        827      803      -24     

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

@jonasbb jonasbb merged commit c9d9672 into jonasbb:master Jun 30, 2024
22 checks passed
@jonasbb
Copy link
Owner

jonasbb commented Jun 30, 2024

Thanks, that looks good :)

@swlynch99 swlynch99 deleted the schemars-one-or-many-as branch July 1, 2024 18:14
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.

None yet

2 participants