G: G1 REST spec derive the OpenAPI document from the handlers
This commit is contained in:
1 parent
5f4a0583f3
commit
3d8e840427
13 files changed
+1347
-20
No files matched your search
@@ -21,3 +21,11 @@ Stand-alone workstream, not part of Phase 5. Request: an autogenerated OpenAPI d
|
||||
Reuse existing DTOs, do not duplicate types for the doc. Read-only, no secrets in the spec or examples. Surfaces call `sources/`, do not touch D-Bus or Docker from the doc code. Tests in the same commit as the code. No workstream tags in comments.
|
||||
|
||||
## Log
|
||||
|
||||
- 2026-10-20: **G1 REST spec.** `utoipa` 6.0.0 (default features, macros included) added to `Cargo.toml`; `cargo tree -i openssl` is still empty. Every REST handler carries `#[utoipa::path]` with an explicit `operationId`, tag, params and the real response set (200 body plus 400/401/404/405/503 `ErrorBody` where they exist); handlers became `pub(crate)` so the `ApiDoc` derive in `src/openapi.rs` can name them. One `ApiDoc` plus one `document(peers: bool)` function; the bearer scheme is declared once (`bearer_auth`) and applied globally, with `/healthz` opting out via `security(())`. Peer paths are dropped when `peers` is false, matching the router (`paths.retain`). The peer pass-through is documented as one wildcard operation `GET /api/v1/peers/{peer}/{path}` whose description lists the allowlist.
|
||||
|
||||
**Owned-files conflict with G1 as written.** G1 says "derive `ToSchema` on the response DTOs", but those DTOs live in `src/sources/mod.rs` and `src/peers/types.rs`, which are not in this workstream's owned files, so no derive could be added there. Resolution, inside `src/openapi.rs` only: the DTOs already derive `schemars::JsonSchema` for MCP, so a small bridge (`reflected<T>()` + a `PartialSchema`/`ToSchema` impl macro) reflects each component from the schemars schema of the same type. There is exactly one definition per DTO and a field added to a DTO shows up in the spec with no edit here. `peer_status_components...`-style payloads that exist only as JSON (error body, `/healthz` and `/api/v1/ping` body) or have no schemars derive (`PeerStatus`, `ServerStatus`, `ApiStatus`, `AuthState` from `src/peers/types.rs`) are described by hand with utoipa builders and checked against the JSON the server really emits (`error_body_and_health_match_the_real_payloads`, `peer_status_components_cover_the_serialized_fields`), so an added field fails a test instead of vanishing from the document. `reflected_schemas_match_schemars` asserts the reflected component equals the schemars output exactly, which pins the converter (object/array/oneOf/anyOf/allOf/format/enum/default/minimum/maximum/required/properties).
|
||||
|
||||
Translation note for a future merger: if WS-G is ever allowed to touch the DTO files, the derive can replace the bridge for `src/sources/mod.rs`; the peer types would still need `JsonSchema` added.
|
||||
|
||||
Tests: 10 unit tests in `src/openapi.rs` (reflection parity, payload parity, peer gating, operation ids and 2xx, bearer scheme, determinism) and `tests/openapi.rs` with the router drift guard started here (source scan of every `.route(...)` literal in `src/api/**` plus `src/server.rs`, `/api/v1` prefix applied as `server.rs` nests it, axum `{*path}` normalised to OpenAPI `{path}`, and one request per documented path that must not hit the fallback's `no such route`). `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings` and `cargo test` green.
|
||||
Reference in new issue
Block a user