Add docs on generating schemas

This commit is contained in:
Graham Esau 2019-12-26 18:26:06 +00:00
parent ebb20130f7
commit 26346612b5
3 changed files with 21 additions and 2 deletions

View file

@ -7,4 +7,19 @@ permalink: /generating/
# Generating Schemas
Using the `schema_for!` macro, and `gen` module...
The easiest way to generate a schema for a type that implements is to use the [`schema_for!` macro](https://docs.rs/schemars/latest/schemars/macro.schema_for.html), like so:
```rust
let my_schema = schema_for!(MyStruct);
```
This will create a schema that conforms to [JSON Schema Draft 7](https://json-schema.org/specification-links.html#draft-7), but this is liable to change in a future version of Schemars if support for other JSON Schema versions is added.
If you want more control over how the schema is generated, you can use the [`gen` module](https://docs.rs/schemars/latest/schemars/gen/). There are two main types in this module:
* [`SchemaSettings`](https://docs.rs/schemars/0.6.1/schemars/gen/struct.SchemaSettings.html), which defines what JSON Schema features should be used when generating schemas (for example, how `Option`s should be represented).
* [`SchemaGenerator`](https://docs.rs/schemars/0.6.1/schemars/gen/struct.SchemaGenerator.html), which manages the generation of a schema document.
See the API documentation for more info on how to use those types for custom schema generation.
<!-- TODO:
create and link to example
-->

View file

@ -2,6 +2,7 @@
permalink: /404
layout: default
nav_exclude: true
title: Not Found
---
<style type="text/css" media="screen">