Skip to main content

bezant_spec/
lib.rs

1//! Vendored copy of the IBKR Client Portal Web API OpenAPI specification.
2//!
3//! Interactive Brokers publishes the spec at
4//! <https://api.ibkr.com/gw/api/v3/api-docs> as OpenAPI **3.0**. Bezant
5//! vendors a pinned copy so downstream crates always build from a known
6//! version. For Rust codegen via the [`bezant-api`] crate we upgrade
7//! the spec to **3.1** (see [`SPEC_JSON_3_1`]) — the 3.0 source is
8//! preserved via [`SPEC_JSON`] so consumers running their own generator
9//! can pick whichever major they need.
10//!
11//! Refresh the vendored copy with `scripts/refresh-spec.sh`, then run
12//! `scripts/codegen.sh` to regenerate the 3.1 derivative and the Rust client.
13//!
14//! [`bezant-api`]: https://docs.rs/bezant-api
15
16/// The pinned IBKR OpenAPI 3.0 spec as a UTF-8 string — verbatim from
17/// upstream.
18///
19/// Use [`SPEC_JSON`] if you need the original 3.0 wording; use
20/// [`SPEC_JSON_3_1`] if you want the normalised-and-upgraded variant
21/// `bezant-api` itself is generated from.
22pub const SPEC_JSON: &str = include_str!("../ibkr-openapi.json");
23
24/// The normalised + 3.1-upgraded spec as a UTF-8 string. Produced by
25/// `scripts/codegen.sh` and checked in alongside the 3.0 source so
26/// consumers don't need Python to reproduce our generator input.
27pub const SPEC_JSON_3_1: &str = include_str!("../ibkr-openapi-3.1.json");
28
29/// IBKR-reported spec version embedded in the vendored spec's `info.version`
30/// field. Updated by `scripts/refresh-spec.sh`.
31pub const UPSTREAM_VERSION: &str = "2.29.0";
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn spec_is_valid_json() {
39        let v: serde_json::Value =
40            serde_json::from_str(SPEC_JSON).expect("spec must be valid JSON");
41        assert_eq!(v["openapi"].as_str().unwrap_or(""), "3.0.0");
42        assert!(!v["paths"].as_object().unwrap().is_empty());
43    }
44
45    #[test]
46    fn upstream_version_matches_embedded() {
47        let v: serde_json::Value = serde_json::from_str(SPEC_JSON).unwrap();
48        let embedded = v["info"]["version"].as_str().unwrap_or("");
49        assert_eq!(
50            embedded, UPSTREAM_VERSION,
51            "UPSTREAM_VERSION constant out of sync with vendored spec"
52        );
53    }
54}