#[openapi_trait]Expand description
Generates transport-agnostic Rust client traits from an OpenAPI specification file.
Apply this attribute to a mod block. The macro reads the OpenAPI
document at the given path (resolved relative to CARGO_MANIFEST_DIR) at
compile time and replaces the module’s contents with:
- Schema structs derived from
components/schemas - A
{OperationId}Requeststruct per operation (bundles path, query, header params and the request body) - Per-operation
{OperationId}Responseenums whose variants map to HTTP status codes - A
{ModName}Clienttrait with one method per operation (keyed byoperationId) - When the
reqwest-clientcargo feature is enabled throughopenapi-trait, a blanket reqwest-backed implementation for any user type derivingReqwestClient
The generated trait name is derived from the annotated module name, so
mod petstore {} produces petstore::PetstoreClient.
§Debugging
Set the OPENAPI_TRAIT_DEBUG environment variable to dump a prettyprinted
copy of the code this macro generates (one level deep, without recursively
expanding nested derives). Use 1/true to write to a default directory
($OUT_DIR/openapi-trait-debug, or the system temp dir), or set it to a
directory path to choose the location. The resolved file path is printed to
stderr during the build.