Skip to main content

clickhouse_cloud_api/
meta.rs

1//! Operation stability metadata.
2//!
3//! `BETA_OPERATIONS` mirrors `x-badges` entries on operations in the ClickHouse
4//! Cloud OpenAPI spec. The list is kept sorted so [`is_beta_operation`] can use
5//! `binary_search` and snapshot diffs stay readable.
6//!
7//! Consumers — including this crate's own CLI — can use [`is_beta_operation`]
8//! to render a "(Beta)" affordance derived from the spec rather than maintained
9//! by hand.
10//!
11//! Regenerate from the snapshot with:
12//!
13//! ```text
14//! python3 scripts/regenerate-beta-lists.py
15//! ```
16//!
17//! The `beta_operations_match_spec` test in `tests/spec_coverage_test.rs` fails
18//! if this list drifts from the spec.
19
20/// Snake-case operation IDs (matching [`crate::client::Client`] method names)
21/// that the OpenAPI spec marks Beta via `x-badges`.
22pub const BETA_OPERATIONS: &[&str] = &[
23    "backup_bucket_create",
24    "backup_bucket_delete",
25    "backup_bucket_get",
26    "backup_bucket_update",
27    "click_stack_create_alert",
28    "click_stack_create_dashboard",
29    "click_stack_delete_alert",
30    "click_stack_delete_dashboard",
31    "click_stack_get_alert",
32    "click_stack_get_dashboard",
33    "click_stack_list_alerts",
34    "click_stack_list_dashboards",
35    "click_stack_list_sources",
36    "click_stack_list_webhooks",
37    "click_stack_update_alert",
38    "click_stack_update_dashboard",
39    "postgres_instance_config_get",
40    "postgres_instance_config_patch",
41    "postgres_instance_config_post",
42    "postgres_instance_create_read_replica",
43    "postgres_instance_prometheus_get",
44    "postgres_instance_restore",
45    "postgres_org_prometheus_get",
46    "postgres_service_certs_get",
47    "postgres_service_create",
48    "postgres_service_delete",
49    "postgres_service_get",
50    "postgres_service_get_list",
51    "postgres_service_patch",
52    "postgres_service_patch_state",
53    "postgres_service_set_password",
54    "scaling_schedule_delete",
55    "scaling_schedule_get",
56    "scaling_schedule_upsert",
57    "service_clickhouse_setting_get",
58    "service_clickhouse_settings_list_get",
59    "service_clickhouse_settings_schema_get",
60    "service_clickhouse_settings_update",
61];
62
63/// Returns `true` if `name` matches a client method backed by a Beta endpoint.
64///
65/// `name` is the snake-case method name (e.g. `"postgres_service_get_list"`).
66pub fn is_beta_operation(name: &str) -> bool {
67    BETA_OPERATIONS.binary_search(&name).is_ok()
68}
69
70#[cfg(test)]
71mod tests {
72    use super::*;
73
74    #[test]
75    fn list_is_sorted_and_unique() {
76        for pair in BETA_OPERATIONS.windows(2) {
77            assert!(
78                pair[0] < pair[1],
79                "BETA_OPERATIONS must be sorted and unique; {:?} >= {:?}",
80                pair[0],
81                pair[1],
82            );
83        }
84    }
85
86    #[test]
87    fn is_beta_operation_matches_constant() {
88        assert!(is_beta_operation("scaling_schedule_get"));
89        assert!(is_beta_operation("postgres_service_get_list"));
90        assert!(!is_beta_operation("services_list"));
91        assert!(!is_beta_operation("not_a_real_op"));
92    }
93}