Skip to content

feat: add OpenAPI 3.1 document generation and runtime API explorer#2

Merged
InTheMorning merged 1 commit into
InTheMorning:mainfrom
dardevelin:feature/openapi-explorer
Apr 17, 2026
Merged

feat: add OpenAPI 3.1 document generation and runtime API explorer#2
InTheMorning merged 1 commit into
InTheMorning:mainfrom
dardevelin:feature/openapi-explorer

Conversation

@dardevelin
Copy link
Copy Markdown

Summary

Adds a machine-generated OpenAPI 3.1 specification and wires it into the existing custom api.html explorer, replacing the previous hardcoded endpoint list with a dynamic, spec-driven UI. The visual design of api.html is fully preserved.


What changed

src/openapi.rs (new)

Full OpenAPI 3.1 document builder covering every route, controlled by a DocMode enum:

Mode Included routes
Primary All routes — ingest, mutations, proofs, sync/register, reconcile
Readonly Read-only subset — omits all write and sync endpoints

Public surface: primary_document() / readonly_document() returning utoipa::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 -- --readonly

src/api.rs

Three new routes added to both build_router and build_readonly_router:

Route Description
GET /api Serves the themed HTML explorer
GET /api.html Alias
GET /openapi.json Serves the appropriate spec as JSON

src/lib.rs

  • pub mod openapi declaration

Cargo.toml

Added utoipa = "5" for OpenAPI types and JSON serialisation. No proc-macro annotations are used anywhere — the spec is built as serde_json::Value and deserialised into utoipa::openapi::OpenApi, keeping the diff minimal.

tests/api_docs_tests.rs (new)

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 routes absent

scripts/preview-docs.sh (new)

Helper that builds gen_openapi, dumps openapi.json, copies api.html, and serves both on port 8787 — opening the browser automatically.

./scripts/preview-docs.sh             # primary spec
./scripts/preview-docs.sh --readonly

Testing

cargo test                 # all tests pass
cargo clippy -- -D warnings  # clean
cargo fmt --check          # clean

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
@dardevelin dardevelin force-pushed the feature/openapi-explorer branch from 43c78b6 to 261e04f Compare April 17, 2026 17:58
@InTheMorning InTheMorning merged commit daab054 into InTheMorning:main Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants