feat: add OpenAPI 3.1 document generation and runtime API explorer#2
Merged
InTheMorning merged 1 commit intoApr 17, 2026
Merged
Conversation
Adds a runtime-served API explorer backed by a machine-generated
OpenAPI 3.1 specification, preserving the project's existing custom
Apple-style dark UI (api.html) rather than replacing it with a
packaged Swagger/Scalar viewer.
## What changed
### New: src/openapi.rs
Full OpenAPI 3.1 document builder covering every route. Two modes:
- DocMode::Primary – all routes including ingest, mutations, proofs,
sync/register and reconcile endpoints
- DocMode::Readonly – community/read-only node subset (omits all write
and sync endpoints)
Public API: primary_document() / readonly_document() returning
utoipa::openapi::OpenApi, serialisable to JSON.
### New: src/bin/gen_openapi.rs
Standalone binary that prints the spec to stdout. Used for the static
preview workflow and for CI artifact generation.
cargo run --bin gen_openapi # primary spec
cargo run --bin gen_openapi -- --readonly
### Modified: src/api.rs
Three new routes wired into both build_router and build_readonly_router:
GET /api – serves the themed HTML explorer
GET /api.html – alias for the above
GET /openapi.json – serves the appropriate OpenAPI document as JSON
### Modified: src/lib.rs
- pub mod openapi declaration
- #![recursion_limit = "256"] – the large serde_json::json! macro in
ingest_request_example() exceeds the default limit of 128
### Modified: Cargo.toml
Added utoipa = "5" for OpenAPI data types and JSON serialisation.
No proc-macro annotations are used; the spec is built as
serde_json::Value then deserialised into utoipa::openapi::OpenApi.
### New: tests/api_docs_tests.rs
Three integration tests:
- api_explorer_html_is_served – correct content-type and body
- primary_spec_has_expected_paths – /ingest/feed present, security
schemes defined
- readonly_spec_excludes_write_paths – /sync/register and PATCH absent
### New: scripts/preview-docs.sh
Helper script that builds gen_openapi, dumps openapi.json, copies
api.html, and serves both with python3 -m http.server on port 8787 –
opening the browser automatically.
./scripts/preview-docs.sh # primary spec
./scripts/preview-docs.sh --readonly
43c78b6 to
261e04f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a machine-generated OpenAPI 3.1 specification and wires it into the existing custom
api.htmlexplorer, replacing the previous hardcoded endpoint list with a dynamic, spec-driven UI. The visual design ofapi.htmlis fully preserved.What changed
src/openapi.rs(new)Full OpenAPI 3.1 document builder covering every route, controlled by a
DocModeenum:PrimaryReadonlyPublic surface:
primary_document()/readonly_document()returningutoipa::openapi::OpenApi.src/bin/gen_openapi.rs(new)Standalone binary that prints the spec to stdout. Useful for CI artifact generation and the local preview workflow.
cargo run --bin gen_openapi # primary spec cargo run --bin gen_openapi -- --readonlysrc/api.rsThree new routes added to both
build_routerandbuild_readonly_router:GET /apiGET /api.htmlGET /openapi.jsonsrc/lib.rspub mod openapideclarationCargo.tomlAdded
utoipa = "5"for OpenAPI types and JSON serialisation. No proc-macro annotations are used anywhere — the spec is built asserde_json::Valueand deserialised intoutoipa::openapi::OpenApi, keeping the diff minimal.tests/api_docs_tests.rs(new)Three integration tests:
api_explorer_html_is_served— correct content-type and bodyprimary_spec_has_expected_paths—/ingest/feedpresent, security schemes definedreadonly_spec_excludes_write_paths—/sync/registerand PATCH routes absentscripts/preview-docs.sh(new)Helper that builds
gen_openapi, dumpsopenapi.json, copiesapi.html, and serves both on port 8787 — opening the browser automatically../scripts/preview-docs.sh # primary spec ./scripts/preview-docs.sh --readonlyTesting