talira

Schemars

Generate JSON Schema documents from Rust types, matching how Serde serializes them

open sourceMITfree

Schemars generates JSON Schema documents from Rust code: derive JsonSchema on your types and call schema_for!. Its schemas aim to match how Serde and serde_json serialize and deserialize your types, so it reads #[serde(...)] attributes (renames, defaults, tagging) and lets #[schemars(...)] override them. It can also build a less precise schema from a value of a type that only implements Serialize. Its output declares JSON Schema 2020-12 by default, and it implements JsonSchema for standard library types and, behind feature flags, for types from crates such as chrono, uuid, url, indexmap and bigdecimal. It works in no_std environments with the std feature off.

Problems it solves

  • generate a JSON Schema from my Rust structs
  • keep my API's JSON Schema in sync with my Serde types
  • publish a schema for my Rust config file format

Features

  • #[derive(JsonSchema)] and the schema_for! macro
  • follows #[serde(...)] attributes, overridable with #[schemars(...)]
  • schema from a value of a type that implements Serialize
  • JSON Schema 2020-12 output by default
  • optional JsonSchema impls for chrono, uuid, url, indexmap, bigdecimal and other crates
  • no_std support