Skip to content

feat(#416): real OpenAPI 3.0 spec at /api/openapi - #456

Open
woahwhattheheck wants to merge 5 commits into
Open-audit-foundation:mainfrom
woahwhattheheck:wire/oa-416-openapi
Open

woahwhattheheck wants to merge 5 commits into
Open-audit-foundation:mainfrom
woahwhattheheck:wire/oa-416-openapi

Conversation

@woahwhattheheck

@woahwhattheheck woahwhattheheck commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

Closes #416.

/docs pointed Swagger UI at /api/openapi, but that route did not exist, so the docs page failed for every visitor. This PR:

  • Adopts the existing routeDoc convention across every app/api/**/route.ts
  • Adds GET /api/openapi that aggregates those docs into a valid OpenAPI 3.0 document with security schemes, shared component schemas, and request/response shapes
  • Fixes middleware.ts PUBLIC_ROUTES: replaces the mangled /api/ingest-historical/openapi entry with /api/openapi
  • Adds drift/validator coverage so newly added API routes must remain represented in the generated spec
  • Preserves the repository's legacy Event source: null response compatibility while continuing to document live and historical as the non-null source values

Acceptance

  • /api/openapi returns a valid OpenAPI 3.0 document
  • /docs can fetch /api/openapi as a public route
  • Every route under app/api/ exports routeDoc
  • Drift coverage fails if a route is added without documentation
  • Middleware allowlist no longer contains the mangled path
  • Generated spec passes the OpenAPI validator
  • Actual list/search response validation accepts legacy source: null plus live / historical, while rejecting unknown strings and numeric source values

Focused validation

The current-head validation receipt is documented in docs/validation/openapi-event-source-20261004.md.

A source-bound selection passed 21 tests, 0 failures, 0 pending:

npm exec -- vitest run \
  lib/openapi/__tests__/event-responses.test.ts \
  lib/openapi/__tests__/openapi-spec.test.ts \
  app/api/v1/events/export/route.test.ts \
  --maxWorkers=1 --reporter=json --outputFile=after.json

That selection includes the new list/search compatibility cases, maintained OpenAPI validator/drift cases, and export schema regressions. It calls the actual handlers and obtains schemas from the actual public OpenAPI handler; database/authentication collaborators are controlled.

Formatting follow-through ran Prettier write/check successfully on the final files. The hosted workflow's overall result was not green because a later byte-for-byte emitted-JavaScript comparator treated a whitespace-only line-wrap change as significant. Independent TypeScript parsing found zero diagnostics and identical syntax trees excluding positions/trivia. No functional rerun is claimed for that whitespace-only formatting edit.

Evidence boundary

No full-suite, full application typecheck/build, live database, deployed Swagger browser, authentication, upstream CI approval, or maintainer-acceptance result is asserted by this focused continuation. The original PR, branch, and contributor are preserved.

Notes

  • Hand-written routeDoc objects only; drift coverage keeps the registry honest
  • Out of scope: client SDK generation

woahwhattheheck and others added 5 commits September 25, 2026 19:05
Wire routeDoc exports on every app/api route (matching the
ingest-historical convention), aggregate them into a valid OpenAPI 3.0
document at GET /api/openapi, fix the mangled PUBLIC_ROUTES entry, and
add drift + schema-validator tests so the docs page stops failing on load.
Model the middleware API key and metrics bearer token as one AND security
requirement when METRICS_TOKEN is configured. Leave API-key-only security
when unset, remove the ignored Authorization header parameter, and avoid
putting any token value in the public specification.

The installed Swagger request builder reproduced the missing Authorization
header before this change; its generated request now reaches the existing
metrics handler successfully. Metrics/OpenAPI checks: 18 passed. Changed
files pass TypeScript and Prettier.

Required full tests: 677 passed, 96 failed, 18 skipped; all 103 failure
reports (including collection errors) match unchanged parent 0831c76.
Whole-project TypeScript/lint diagnostics also match that parent. Build
still stops on the four unchanged parser errors in clickhouse-ingest,
historical-ingester, dag/engine, and jobs/queue. No full-build/CI-green claim.

Refs Open-audit-foundation#416
Reuse the nine production postimages from 31972c3, retaining the OpenAPI and metrics changes on this branch. All original blobs matched that repair's parent.

The composed application compiles with Turbopack and passes the full TypeScript check (npm run lint, Node heap 512 MiB). The complete Next build remains unverified: its TypeScript worker was killed under shared memory pressure, and the subsequent bounded build hit ENOSPC. No full-suite or hosted-CI success is asserted.

Source repair: 31972c3
Operation: OA455-456-BUILD-REPAIR-REUSE-20261003-01
Align the JSON response metadata with the unchanged streamed array and its nine row fields. Extend the existing export regression to check populated and empty responses against the generated document, and reject a serialized JSON string as the response value.

Prettier passes using the repository configuration. Maintained tests, type checking and lint are not rerun in this continuation because the exact retained dependency donor is unavailable; their remaining acceptance requirements are preserved.
Allow null alongside the documented live/historical Event source values. Exercise actual list/search JSON against the served specification, retaining rejection of unknown strings and numeric sources.

Focused execution: original enum reproduced 2 failures; repaired selection passed 21 tests, including existing OpenAPI validation/drift and JSON export cases. Preserve the source-bound results and formatting-only limitations in docs/validation/openapi-event-source-20261004.md. Runtime handlers, dependencies and prior fixes are unchanged.
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.

Build a real, accurate OpenAPI specification served at /api/openapi

1 participant