Crate ffx_schema

source ·
Expand description

Generate schemas for types that implement the serde::Deserialize trait.

let mut gen = Generator::new(Default::default());
gen.resolve_type::<MyType>()?;
let schema = gen.schema()?;

The returned schema implements the serde::Serialize trait. It is possible to output that in whatever format you want. Alternatively, you can inspect the schema directly as it contains types from the ast module.

The methodology used here gets a little tricky with enums. By default, we attempt to resolve all enum variants even within nested types. If you call resolve_type with all enum types that you transitively depend on as well as the top level type, then you can ensure you won’t have to deal with any of the trickery required to handle enums not at the top level.

let config = GeneratorConfig::default();
let mut gen = Generator::new(config);
gen.resolve_type::<OtherNestedEnum>()?;
gen.resolve_type::<SomeEnum>()?;
gen.resolve_type::<MyType>()?;
let schema = gen.schema()?;

Re-exports

pub use schema::Generator;
pub use schema::GeneratorConfig;
pub use schema::Schema;

Modules

Module defining the Abstract Syntax Tree (AST) used by Serde.

Enums