diff --git a/CHANGELOG.md b/CHANGELOG.md index cd05b2cf..9ad1cc9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.1] + ### Breaking Changes - Rust generated clients now expose backend-native header maps from diff --git a/Cargo.lock b/Cargo.lock index f3d89dbe..42f31cc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -447,7 +447,7 @@ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "fixture-generator-additional-properties" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "axum-extra", @@ -468,7 +468,7 @@ dependencies = [ [[package]] name = "fixture-generator-enum-repr" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "axum-extra", @@ -489,7 +489,7 @@ dependencies = [ [[package]] name = "fixture-generator-petstore" -version = "0.2.0" +version = "0.2.1" dependencies = [ "axum", "axum-extra", @@ -1032,7 +1032,7 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "openapi-nexus" -version = "0.2.0" +version = "0.2.1" dependencies = [ "clap", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index ef2aad6a..f309e70d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ ] [workspace.package] -version = "0.2.0" +version = "0.2.1" edition = "2024" rust-version = "1.90" description = "OpenAPI 3.x multi-language code generator" diff --git a/README.md b/README.md index ab9fe76e..87333c90 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ OpenAPI Nexus transforms OpenAPI specifications into type-safe client libraries. **Shell installer (no Rust toolchain needed):** ```sh -curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-codegen-group/openapi-nexus/releases/download/0.2.0/openapi-nexus-installer.sh | sh +curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-codegen-group/openapi-nexus/releases/download/0.2.1/openapi-nexus-installer.sh | sh ``` **Nightly build (latest main):** diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md index d9bf6da9..4110a004 100644 --- a/docs/src/getting_started.md +++ b/docs/src/getting_started.md @@ -5,7 +5,7 @@ **Shell installer (no Rust toolchain needed):** ```sh -curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-codegen-group/openapi-nexus/releases/download/0.2.0/openapi-nexus-installer.sh | sh +curl --proto '=https' --tlsv1.2 -LsSf https://github.com/rust-codegen-group/openapi-nexus/releases/download/0.2.1/openapi-nexus-installer.sh | sh ``` **Nightly build (latest main):** diff --git a/docs/src/response_headers.md b/docs/src/response_headers.md index c94a3184..a2a88c86 100644 --- a/docs/src/response_headers.md +++ b/docs/src/response_headers.md @@ -39,6 +39,44 @@ paths: $ref: "#/components/headers/RetryAfter" ``` +## Reading headers + +Generated accessor names follow the operation and header names in the OpenAPI +document. This Rust example uses an accessor for each declared header and falls +back to the backend-native header map for an undeclared tracing header: + +```rust +match api.create_resource(&request).await { + Ok(response) => { + let request_id = response.x_request_id_header(); + let traceparent = response + .headers + .get("traceparent") + .and_then(|value| value.to_str().ok()); + + println!("request_id={request_id:?} traceparent={traceparent:?}"); + } + Err(error) => { + let retry_after = error.retry_after_header().map(str::to_owned); + + // Erase the payload type when only common response metadata is needed. + let error: ApiCallError = error.into(); + let traceparent = error + .headers() + .and_then(|headers| headers.get("traceparent")) + .and_then(|value| value.to_str().ok()); + + eprintln!("retry_after={retry_after:?} traceparent={traceparent:?}"); + } +} +``` + +In this example, `X-Request-Id` and `Retry-After` are declared in OpenAPI, so +the generator provides typed accessors. `traceparent` is undeclared and remains +available through the native header map. Match the operation-specific error +before converting it to `ApiCallError` when its decoded body is needed; see +[Generated Error Handling](rust_config.md#generated-error-handling). + ## Generated access | Generator | Successful response headers | Error response headers |