Document schema_with attribute

This commit is contained in:
Graham Esau 2020-05-15 17:42:37 +01:00
parent 3fd316063a
commit 4c501990b1
6 changed files with 39 additions and 9 deletions

View file

@ -30,6 +30,7 @@ Serde also allows setting `#[serde(...)]` attributes which change how types are
- [`flatten`](#flatten)
- [`with`](#with)
1. [Other Attributes](#other-attributes)
- [`schema_with`](#schema_with)
- [Doc Comments (`doc`)](#doc)
## Supported Serde Attributes
@ -117,16 +118,23 @@ Serde docs: [field](https://serde.rs/field-attrs.html#flatten)
`#[serde(with = "Type")]` / `#[schemars(with = "Type")]`
</h3>
Set on a field to generate this field's schema as the given type instead of the field's actual type. Serde allows the `with` attribute to refer to any module path, but Schemars requires this to be an actual type which implements `JsonSchema`.
Set on a variant or field to generate its schema as the given type instead of its actual type. Serde allows the `with` attribute to refer to any module path, but Schemars requires this to be an actual type which implements `JsonSchema`.
If the given type has any required generic type parameters, then they must all be explicitly specified in this attribute. Serde frequently allows you to omit them as it can make use of type inference, but unfortunately this is not possible with Schemars. For example, `with = "Vec::<i32>"` will work, but `with = "Vec"` and `with = "Vec::<_>"` will not.
Serde docs: [field](https://serde.rs/field-attrs.html#with)
Serde docs: [variant](https://serde.rs/variant-attrs.html#with) / [field](https://serde.rs/field-attrs.html#with)
</div>
## Other Attributes
<h3 id="schema_with">
`#[schemars(schema_with = "some::function")]`
</h3>
Set on a variant or field to generate this field's schema using the given function. This function must be callable as `fn(&mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema`.
<h3 id="doc">
Doc Comments (`#[doc = "..."]`)