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.