Skip to main content

impl_json_schema

Macro impl_json_schema 

Source
macro_rules! impl_json_schema {
    ($ty:ty) => { ... };
    ($ty:ty, $name:expr) => { ... };
}
Expand description

Implement schemars::JsonSchema for a type that has a json_schema() associated function (generated by vld::schema! with the openapi feature enabled, or by #[derive(Validate)]).

This makes the type usable with aide for OpenAPI documentation generation.

§Usage

use vld::prelude::*;
use vld_aide::impl_json_schema;

vld::schema! {
    #[derive(Debug)]
    pub struct CreateUser {
        pub name: String => vld::string().min(2).max(100),
        pub email: String => vld::string().email(),
    }
}

impl_json_schema!(CreateUser);

// Now CreateUser implements schemars::JsonSchema and works with aide.

You can also pass a custom schema name:

impl_json_schema!(Req, "CreateUserRequest");