Macro typify_macro::import_types

source ·
import_types!() { /* proc-macro */ }
Expand description

Import types from a schema file. This may be invoked with simply a pathname for a JSON Schema file (relative to $CARGO_MANIFEST_DIR), or it may be invoked with a structured form:

use typify_macro::import_types;
use serde::{Deserialize,Serialize};
import_types!(
    schema = "../example.json",
    derives = [schemars::JsonSchema],
);
  • schema: string literal; the JSON schema file

  • derives: optional array of derive macro paths; the derive macros to be applied to all generated types

  • struct_builder: optional boolean; (if true) generates a ::builder() method for each generated struct that can be used to specify each property and construct the struct

  • unknown_crates: optional policy regarding the handling of schemas that contain the x-rust-type extension whose crates are not explicitly named in the crates section. The options are generate to ignore the extension and generate a de novo type, allow to use the named type (which may require the addition of a new dependency to compile, and which ignores version compatibility checks), or deny to produce a compile-time error (requiring the user to specify the crate’s disposition in the crates section).

  • crates: optional map from crate name to the version of the crate in use. Types encountered with the Rust type extension (x-rust-type) will use types from the specified crates rather than generating them (within the constraints of type compatibility).

  • patch: optional map from type to an object with the optional members rename and derives. This may be used to renamed generated types or to apply additional (non-default) derive macros to them.

  • replace: optional map from definition name to a replacement type. This may be used to skip generation of the named type and use a existing Rust type.

  • convert: optional map from a JSON schema type defined in $defs to a replacement type. This may be used to skip generation of the schema and use an existing Rust type.