Add separate docs for v0.8/v1

This commit is contained in:
Graham Esau 2024-06-09 19:01:24 +01:00
parent 3150f98fc8
commit d511d447f7
61 changed files with 1620 additions and 58 deletions

View file

@ -0,0 +1,15 @@
---
title: Generate Schema from Example Value
parent: Examples
nav_order: 9
summary: >-
Generating a schema for a serializable value.
---
# Generate Schema from Example Value
If you want a schema for a type that can't/doesn't implement `JsonSchema`, but does implement [`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html), then you can generate a JSON schema from a value of that type. However, this schema will generally be less precise than if the type implemented `JsonSchema` - particularly when it involves enums, since schemars will not make any assumptions about the structure of an enum based on a single variant.
{% include example_v0.md name="from_value" %}
Note that the schema for the enum is not very useful in this case, since schemars doesn't know anything about the second variant.