sdk_schemas

Macro write_schema_for

source
macro_rules! write_schema_for {
    ($type:ty) => { ... };
    ($path:literal, $type:ty) => { ... };
}
Expand description

Creates a json schema file for any type passed in using Schemars. The filename and path of the generated schema file is derived from the namespace passed into the macro or supplied as the first argument.

The schema filename is given by the last namespace element and trims off any > characters. This means the filename will represent the last generic type of the type given.

The schema path is rooted at the current working directory.

§Usage

§Fully generated

Subpath is equal to the namespace except the last two elements, which are assumed to be a filename and struct name.

Min namespace length is currently 3.

§Examples

write_schema_for!(request::command::Command);

will generate Command.json at {{pwd}}/request/Command.json

write_schema_for!(response::two_factor_login_response::two_factor_providers::TwoFactorProviders);

will generate TwoFactorProviders.json at {{pwd}}/response/two_factor_login_response/TwoFactorProviders.json

§Path specified

You can also specify a custom path and type, separated by a comman

§Examples

write_schema_for!("path/to/folder", Request<Response>);

will generate Response.json at {{pwd}}/path/to/folder/Response.json