openapi-trait-client
Transport-agnostic client procedural macro backend for openapi-trait.
This crate is not intended for direct use. In normal projects, depend on
openapi-trait and use the re-exported macro:
What it generates
Given an annotated mod, the macro reads an OpenAPI document at compile time
and replaces the module contents with:
serde-derived Rust structs forcomponents/schemas{OperationId}Requeststructs for path, query, header, and body inputs{OperationId}Responseenums whose variants map to HTTP status codes- A
{ModName}Clienttrait with one method peroperationId
The generated trait name comes from the annotated module name, so mod petstore {} produces petstore::PetstoreClient.
Reqwest derive support
This crate also defines the ReqwestClient derive that powers the
feature-gated blanket reqwest implementation re-exported from openapi-trait.
By default, the derive expects named fields called client and base_url, and
those defaults can be overridden with:
#[openapi_trait(client)]#[openapi_trait(base_url)]
Path resolution
The macro resolves the OpenAPI file path relative to CARGO_MANIFEST_DIR and
uses include_str! so Cargo recompiles the crate when the spec changes.
Crate role
This crate isolates client-side code generation and optional reqwest-backed
integration so the public openapi-trait crate can expose a single entry point
without making the proc-macro implementation details part of its API surface.