diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f051fd..f231587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## In-dev - version TBC +### Added: +- `#[schemars(example = "...")]` attribute for setting examples on generated schemas (https://github.com/GREsau/schemars/issues/23) + ## [0.7.5] - 2020-05-17 ### Added: - Setting `#[deprecated]` attribute will now cause generated schemas to have the `deprecated` property set to `true` diff --git a/docs/1.1-attributes.md b/docs/1.1-attributes.md index 99ea370..7efd92b 100644 --- a/docs/1.1-attributes.md +++ b/docs/1.1-attributes.md @@ -32,6 +32,7 @@ Serde also allows setting `#[serde(...)]` attributes which change how types are 1. [Other Attributes](#other-attributes) - [`schema_with`](#schema_with) - [`title` / `description`](#title-description) + - [`example`](#example) - [`deprecated`](#deprecated) - [Doc Comments (`doc`)](#doc) @@ -157,11 +158,18 @@ Set on a variant or field to generate this field's schema using the given functi

-`#[schemars(title = "Some title", description = "Some description)]` +`#[schemars(title = "Some title", description = "Some description")]`

Set on a container, variant or field to set the generated schema's `title` and/or `description`. If present, these will be used instead of values from any [`doc` comments/attributes](#doc). +

+ +`#[schemars(example = "some::function")]` +

+ +Set on a container, variant or field to include the result of the given function in the generated schema's `examples`. The function should take no parameters and can return any type that implements serde's `Serialize` trait - it does not need to return the same type as the attached struct/field. This attribute can be repeated to specify multiple examples. +

`#[deprecated]`