max / makenotwork
| 1 | //! Write the OpenAPI spec to `openapi.json` at the crate root. |
| 2 | //! |
| 3 | //! The spec is a checked-in artifact rather than something only served at |
| 4 | //! runtime, because it is the SyncKit wire contract and the client lives in |
| 5 | //! another repo. A file can be vendored and diffed; a live endpoint cannot be |
| 6 | //! reached from `synckit-client`'s test suite. |
| 7 | //! |
| 8 | //! `openapi::tests::committed_spec_matches_generated` fails when this output is |
| 9 | //! stale, so the regeneration step is: |
| 10 | //! |
| 11 | //! ```sh |
| 12 | //! cargo run --bin export-openapi |
| 13 | //! ``` |
| 14 | //! |
| 15 | //! `--stdout` writes the same bytes to standard output instead of the file, so |
| 16 | //! a caller can diff the generated spec against a committed copy without |
| 17 | //! touching the source tree. The pre-commit hook uses it to compare against the |
| 18 | //! *staged* `openapi.json`, which is the copy the commit would actually carry. |
| 19 | |
| 20 | use Write as _; |
| 21 | |
| 22 | |
| 23 | let spec = spec_json; |
| 24 | |
| 25 | if args.any |
| 26 | stdout.write_all?; |
| 27 | return Ok; |
| 28 | |
| 29 | |
| 30 | let path = concat!; |
| 31 | let mut file = create?; |
| 32 | file.write_all?; |
| 33 | println!; |
| 34 | Ok |
| 35 | |
| 36 |