incident_io/lib.rs
1//! Rust client for the [incident.io](https://incident.io) API.
2//!
3//! Everything under [`apis`] and [`models`] is generated from our published
4//! OpenAPI schema, so it tracks the live API: a function for every endpoint,
5//! and a type for every request and response.
6//!
7//! # Quickstart
8//!
9//! ```no_run
10//! use incident_io::apis::{configuration::Configuration, incidents_v2_api};
11//!
12//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
13//! let mut config = Configuration::new();
14//! config.bearer_access_token = Some("my-api-key".to_owned());
15//!
16//! let params = incidents_v2_api::IncidentsV2ListParams::new().set_page_size(25);
17//! let result = incidents_v2_api::incidents_v2_list(&config, params).await?;
18//!
19//! for incident in result.incidents {
20//! println!("{} {}", incident.reference, incident.name);
21//! }
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! # Building a request
27//!
28//! Every generated type is `#[non_exhaustive]`, so that adding a field stays a
29//! backwards-compatible change. Struct literals and `..Default::default()`
30//! therefore don't compile from outside this crate; use `new()`, which takes
31//! the required fields, and the chainable `set_*` methods for the rest:
32//!
33//! ```
34//! use incident_io::apis::incidents_v2_api::IncidentsV2ListParams;
35//!
36//! let params = IncidentsV2ListParams::new()
37//! .set_page_size(100)
38//! .set_sort_by("created_at_newest_first");
39//! ```
40//!
41//! A setter takes the value rather than `Some(value)`. Reading a field is
42//! unchanged — they are all public.
43//!
44//! `new()` takes the required fields on a params struct and on a request
45//! payload. On a **response** type it takes none: the API adds required
46//! properties to responses regularly, and a constructor that named them would
47//! break you every time it did.
48//!
49//! [`apis::configuration::Configuration`], [`apis::configuration::ApiKey`],
50//! [`apis::ResponseContent`] and [`apis::Error`] are `#[non_exhaustive]` as
51//! well. An API change cannot add a field to those, but a generator upgrade
52//! can, so they are marked for the same reason and built the same way.
53//! [`apis::Error`] needs a wildcard arm when you match it.
54//!
55//! `Default::default()` is *not* blocked by `#[non_exhaustive]`, and every
56//! model derives it. On a type with required fields it hands back empty
57//! strings, which the API rejects with a 422 — use `new()` instead.
58//!
59//! # Unknown enum values
60//!
61//! We add values to enums as a backwards-compatible change, so every generated
62//! enum carries an `Unknown(String)` variant holding the value verbatim. Match
63//! the variants you care about and treat `Unknown` as unrecognised; it
64//! serializes back as the original string, so reading a resource and writing
65//! it again does not corrupt a field this build does not know about.
66//!
67//! # TLS
68//!
69//! `rustls` by default. For OpenSSL instead:
70//!
71//! ```toml
72//! incident-io = { version = "1", default-features = false, features = ["native-tls"] }
73//! ```
74//!
75//! Cargo features are additive across a dependency graph, so another crate
76//! asking for `native-tls` brings it back in alongside rustls. Pick the
77//! backend explicitly on the `reqwest::Client` if you need to be certain.
78//!
79//! Turning both off is a compile error rather than a client that cannot
80//! reach the API.
81
82#![allow(unused_imports)]
83#![allow(clippy::too_many_arguments)]
84// Every doc comment below this line is prose from the OpenAPI schema, so it
85// contains curl examples: bare URLs, and query filters like
86// `status[one_of]=firing` that rustdoc reads as links to Rust items. Without
87// these allows the schema's own examples would have to be mangled to keep
88// rustdoc quiet.
89//
90// The cost is real, so it is written down: the generator also emits ~608
91// genuine intra-doc links between operations, and `broken_intra_doc_links`
92// is the lint that would catch one of those going stale. Measured at the time
93// of writing with `RUSTDOCFLAGS="--force-warn rustdoc::broken_intra_doc_links"`
94// — 53 warnings, every one of them the schema-prose kind, none from a real
95// link. Re-run that if the generated links ever start looking wrong.
96#![allow(rustdoc::bare_urls)]
97#![allow(rustdoc::broken_intra_doc_links)]
98
99// Both TLS features are optional and `rustls` is only a default, so
100// `default-features = false` with neither of them selected compiles clean and
101// produces a client that cannot open an HTTPS connection to api.incident.io —
102// discovered at runtime, on the first request. Say it at compile time instead.
103#[cfg(not(any(feature = "rustls", feature = "native-tls")))]
104compile_error!(
105 "incident-io needs a TLS backend. You set default-features = false without \
106 selecting one: add features = [\"rustls\"] (the default) or \
107 features = [\"native-tls\"]."
108);
109
110pub mod apis;
111pub mod models;