-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement JsonSchemaAs for OneOrMany instead of JsonSchema
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>>, }
- Loading branch information
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
serde_with/tests/schemars_0_8/snapshots/one_or_many_nested.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Test", | ||
"type": "object", | ||
"properties": { | ||
"optional_many": { | ||
"default": null, | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/OneOrMany<String, PreferOne>" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
}, | ||
"definitions": { | ||
"OneOrMany<String, PreferOne>": { | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |