//! Write the OpenAPI spec to `openapi.json` at the crate root. //! //! The spec is a checked-in artifact rather than something only served at //! runtime, because it is the SyncKit wire contract and the client lives in //! another repo. A file can be vendored and diffed; a live endpoint cannot be //! reached from `synckit-client`'s test suite. //! //! `openapi::tests::committed_spec_matches_generated` fails when this output is //! stale, so the regeneration step is: //! //! ```sh //! cargo run --bin export-openapi //! ``` //! //! `--stdout` writes the same bytes to standard output instead of the file, so //! a caller can diff the generated spec against a committed copy without //! touching the source tree. The pre-commit hook uses it to compare against the //! *staged* `openapi.json`, which is the copy the commit would actually carry. use std::io::Write as _; fn main() -> std::io::Result<()> { let spec = makenotwork::openapi::spec_json(); if std::env::args().any(|a| a == "--stdout") { std::io::stdout().write_all(spec.as_bytes())?; return Ok(()); } let path = concat!(env!("CARGO_MANIFEST_DIR"), "/openapi.json"); let mut file = std::fs::File::create(path)?; file.write_all(spec.as_bytes())?; println!("wrote {path}"); Ok(()) }