Skip to main content

Schema

Derive Macro Schema 

Source
#[derive(Schema)]
{
    // Attributes available to this derive:
    #[schema]
    #[serde]
}
Expand description

Derive macro for Schema

Supports #[schema(name = "CustomName")] attribute to set custom OpenAPI schema name.

§Duplicate schema name detection

SCHEMA_STORAGE is keyed by the OpenAPI schema name (struct ident by default, or #[schema(name = "...")] if specified). When two different struct definitions register under the same name, only the last one would survive in openapi.json — a silent footgun that has bitten real users. This derive therefore checks the storage before inserting and emits a compile_error! so the conflict surfaces at build time instead of at spec-generation time.

Identical re-registrations (e.g. incremental rebuilds running the same derive twice) are idempotent: the definition token-stream matches and the second call is a no-op.