facet-json-schema

Crates.iofacet-json-schema
lib.rsfacet-json-schema
version0.43.2
created_at2025-12-31 12:33:37.99805+00
updated_at2026-01-23 18:06:23.014198+00
descriptionGenerate JSON Schema from facet type metadata
homepagehttps://facet.rs
repositoryhttps://github.com/facet-rs/facet
max_upload_size
id2014615
size52,197
Amos Wenger (fasterthanlime)

documentation

README

facet-json-schema

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

facet-json-schema

Generate JSON Schema from facet type metadata.

This crate uses facet's reflection capabilities to generate JSON Schema definitions from any type that implements Facet. The generated schemas can be used for:

  • API documentation (OpenAPI/Swagger)
  • Runtime validation
  • Cross-language type generation
  • Editor autocompletion

Usage

use facet::Facet;
use facet_json_schema::to_schema;

#[derive(Facet)]
struct User {
    name: String,
    age: u32,
    email: Option<String>,
}

let schema = to_schema::<User>();
println!("{}", schema);

Output

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0, "maximum": 4294967295 },
    "email": { "type": "string" }
  },
  "required": ["name", "age"]
}

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Commit count: 3380

cargo fmt