clickhouse-cloud-api
Typed Rust client for the ClickHouse Cloud API.
Development
Structure
| Path | Purpose |
|---|---|
src/client.rs |
Client struct with an async method per API endpoint |
src/models.rs |
Request/response types matching the OpenAPI spec |
src/error.rs |
Error types (Http, Json, Api) |
clickhouse_cloud_openapi.json |
Checked-in copy of the spec (used by tests) |
tests/spec_coverage_test.rs |
Thin snapshot/live-spec consumer of the shared drift analyzer |
../clickhouse-openapi-analyzer |
Canonical Rust/OpenAPI parsing, comparison, report, and exemptions |
Field optionality
The OpenAPI spec uses two conventions for marking fields required vs optional:
- Schemas with a
requiredarray (newer/beta endpoints) use standard OpenAPI semantics. - Schemas without
required(GA/legacy endpoints) treat fields whose description starts with"Optional"as optional. Everything else is implicitly required. - Known partial
requiredarrays use the union of that array and the description heuristic, as configured by the analyzer.
Additional rules:
- PATCH request schemas (name contains
Patchand ends withRequest) are always all-optional. - Nullable fields (
type: ["string", "null"]oroneOfwith null) are alwaysOption<T>, even if required.
In models.rs, required non-nullable fields use bare types (T) and optional/nullable fields use Option<T>. All fields keep #[serde(default)] so deserialization is tolerant of partial data.
Deprecated fields
The OpenAPI spec marks some response fields as deprecated (e.g. Service.tier, ApiKey.roles, Member.role). In almost all cases, these are not needed. The Cloud API library disables them by default, gated by a Cargo feature flag deprecated-fields. Enable this feature if you need to consume deprecated fields.
Scripts
# Show a JSON manifest of required/optional fields per schema
# Regenerate the DEPRECATED_FIELDS constant from the snapshot
# Regenerate the BETA_OPERATIONS constant from the snapshot
# Check for drift between the live spec and the library (dry run)
Field optionality is maintained by hand — edit models.rs directly when the drift check flags a mismatch.
Testing
Live-API lifecycle suites are #[ignore]d by default (they provision real resources):
ClickPipes E2E binaries live under tests/clickpipes/ and are declared as named [[test]] entries in Cargo.toml. Each per-source binary provisions its own ClickHouse Cloud service and exercises one source; clickpipe_e2e_test runs every stage in parallel against a single shared service:
All require CLICKHOUSE_CLOUD_API_KEY, CLICKHOUSE_CLOUD_API_SECRET, CLICKHOUSE_CLOUD_TEST_ORG_ID, CLICKHOUSE_CLOUD_TEST_PROVIDER, and CLICKHOUSE_CLOUD_TEST_REGION in the environment, and are wired into the scheduled Cloud Integration GitHub Actions workflow. The ClickPipes E2E suites additionally need AWS credentials and an eu-west-1 region quota; clickpipe_smoke_test reads a pre-provisioned service ID from CLICKHOUSE_CLOUD_TEST_CLICKPIPE_SERVICE_ID.
spec_coverage_test sends the checked-in sources and snapshot through the
private clickhouse-openapi-analyzer crate. That same analyzer powers the
scheduled live-spec issue, so operation, model, field, optionality, beta,
deprecation, enum, snapshot, and stale-exemption findings share one
implementation. The single ignored test runs the same report against the live
spec.
Optionality exemptions
Occasionally the spec cannot be followed literally because verified API
behavior differs. All such policy lives in
crates/clickhouse-openapi-analyzer/src/config.rs, including optionality,
extra-field, deprecated-field, extra-enum-value, non-OpenAPI-method, partial
required-schema, and unsupported-enum configuration.
Add an exemption only for a deliberate runtime behavior and document why the
spec cannot be followed. New unsupported-enum acknowledgements also require a
tracking issue. The analyzer reports stale field/enum exemptions and vanished
unsupported locations so obsolete entries are removed during normal drift
remediation. See the repository AGENTS.md for exact key formats and the full
remediation and verification procedure.