From 26346612b56338df5eeb68619ea7e4ec75d8778d Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Thu, 26 Dec 2019 18:26:06 +0000 Subject: [PATCH] Add docs on generating schemas --- docs/3-generating.md | 17 ++++++++++++++++- docs/404.html | 1 + schemars/src/gen.rs | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/3-generating.md b/docs/3-generating.md index 2307204..d356d9b 100644 --- a/docs/3-generating.md +++ b/docs/3-generating.md @@ -7,4 +7,19 @@ permalink: /generating/ # Generating Schemas -Using the `schema_for!` macro, and `gen` module... \ No newline at end of file +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. + + diff --git a/docs/404.html b/docs/404.html index 0f623a0..a146d01 100644 --- a/docs/404.html +++ b/docs/404.html @@ -2,6 +2,7 @@ permalink: /404 layout: default nav_exclude: true +title: Not Found ---