Skip to main content

client

Attribute Macro client 

Source
#[client]
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}Request struct per operation (bundles path, query, header params and the request body)
  • Per-operation {OperationId}Response enums whose variants map to HTTP status codes
  • A {ModName}Client trait with one method per operation (keyed by operationId)
  • When the reqwest-client cargo feature is enabled through openapi-trait, a blanket reqwest-backed implementation for any user type deriving ReqwestClient

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.