schema!() { /* proc-macro */ }Expand description
Generate an OpenAPI Schema from a type with optional field filtering.
This macro creates a vespera::schema::Schema struct at compile time
from a type that has #[derive(Schema)].
§Syntax
ⓘ
// Full schema (all fields)
let user_schema = schema!(User);
// Schema with fields omitted
let response_schema = schema!(User, omit = ["password", "internal_id"]);
// Schema with only specified fields (pick)
let summary_schema = schema!(User, pick = ["id", "name"]);§Parameters
Type: The type to generate schema for (must have#[derive(Schema)])omit = [...]: Optional list of field names to exclude from the schemapick = [...]: Optional list of field names to include (excludes all others)
Note: omit and pick cannot be used together.
§Example
ⓘ
use vespera::{Schema, schema};
#[derive(Schema)]
struct User {
pub id: i32,
pub name: String,
pub email: String,
pub password: String, // sensitive!
}
// For API responses, omit password
let response_schema = schema!(User, omit = ["password"]);
// For list endpoints, only return summary fields
let list_schema = schema!(User, pick = ["id", "name"]);