Generate the OpenAPI document from a route table
Security / Vulnerability check (push) Successful in 38s
Test / Lint and test (push) Successful in 1m53s

The server registers its routes from one table in server/routes.go, and
tools/genopenapi (run by go generate) writes docs/swagger.json, an
OpenAPI 3.1 document, from the same table and the Go types it names.
Schemas are reflected with invopop/jsonschema: descriptions from the
first paragraph of the doc comments, enums and limits from jsonschema
tags. Request schemas are strict, as the decoder is; response schemas
allow fields added later. The daemon serves the embedded document at
GET /openapi.json without a token, internal/app passes it to the server
in its config, and release archives and the Docker build include it.

Tests keep it honest: a golden test and a CI step fail when the
document is stale, every registered route must be in the table, and the
tags are held to validation, to the Go constants and to the values the
handlers send. receipt.Element and printqueue.Status gain field doc
comments for the descriptions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 09:30:42 -06:00
1 parent 9f7c5db923
commit bdd337e2dc
31 files changed
+3153 -128

No files matched your search

+10
View File
@@ -32,8 +32,18 @@ included, carry `Cache-Control: no-store`.
| POST | `/api/v1/preview` | Show the lines a job prints, without printing it |
| GET | `/api/v1/jobs/:id` | Job status |
| GET | `/healthz` | Printer and queue health (no auth) |
| GET | `/openapi.json` | This API's OpenAPI 3.1 document (no auth) |
| GET | `/` | Version information (no auth) |
[docs/swagger.json](swagger.json) is the API's OpenAPI 3.1 document:
every route, its parameters, its responses and the codes it and its
middleware answer with, and the schemas of the job and of every response.
The codes the HTTP server itself can send for any request are listed once,
in its description. It is generated from the server's route table and the
Go types behind it, and the daemon serves the copy built into it at
`GET /openapi.json`. Its enums list the canonical spellings; the server
also accepts other letter case and a few aliases, such as `centre`.
### Print a receipt
```sh
+11
View File
@@ -113,6 +113,17 @@ client ─HTTPS─▶ Caddy ─▶ server ── validate ──▶ printqueue (
`error` is for people. A refusal is answered and never logged as a failure.
An unexpected error or panic is logged once and reported to Sentry once,
without the body or the `Authorization` header.
- **The OpenAPI document is generated (owner, 2026-11-30).** One route
table drives both the server's routes and `docs/swagger.json`, so the
document cannot describe a route the server lacks. Schemas come from the
Go types by reflection, descriptions from the first paragraph of their doc
comments, and enums and limits from `jsonschema` tags. Tests hold the tags
to validation and to the values the handlers send; the enums list the
canonical spellings, while validation also takes other letter case and a
few aliases. Request schemas are strict, as the decoder is; response
schemas allow fields added later. Nothing in the document is written by
hand. The server gets the document in its config, so the generator does
not build the package that embeds its own output.
- **What stays compatible with 0.1.** The endpoint, the HS256 tokens and the
config keys stay as they were. The 0.1 body and its plain-text answer do
not. A 0.1 body gets a `400` that points to the element format in
+13
View File
@@ -0,0 +1,13 @@
// Package docs embeds swagger.json, the OpenAPI document of Überbringer's
// HTTP API, which tools/genopenapi writes into this directory from the route
// table, so the daemon serves the document of the build it runs.
package docs
import _ "embed"
//go:embed swagger.json
var openAPI []byte
// OpenAPI returns the HTTP API's OpenAPI 3.1 document. The caller must not
// modify it.
func OpenAPI() []byte { return openAPI }
+1207
View File
File diff suppressed because it is too large. Load diff