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

+31 -7
View File
@@ -12,11 +12,18 @@ root `Dockerfile`.
- Coding rules: `R:\Current Storage\Projects\AI-Memory\Golang-Programming-Standards.md`.
Every change follows it. `.gitea/workflows/`, `packaging/`, the root
`Dockerfile` and `install.sh` take the place of the standards' `build/` and
`scripts/`.
`scripts/`, and the generated `docs/swagger.json` takes the place of
`api/`.
- `docs/api.md` is the reference for the API: routes, elements, blocks and
error codes. `README.md` covers installing,
configuration, the command line and the package layout. There is no
OpenAPI document.
configuration, the command line and the package layout.
- `docs/swagger.json`, the OpenAPI 3.1 document, is generated
(`go generate ./...`, which runs `tools/genopenapi`) from the route table in
`internal/app/uberbringer/server/routes.go` and the Go types it names: their
`json` and `jsonschema` tags and their doc comments. The server registers
its routes from the same table. Never edit the file by hand; regenerate it
in the same commit as any change to a route or to a request or response
type.
- `docs/design.md` explains why the daemon is shaped as it is and lists what
is deferred. Change it in the same commit as any code that departs from it.
- `docs/plans/<feature>.md` holds a feature until it ships. A decision made
@@ -27,13 +34,18 @@ root `Dockerfile`.
`cmd/uberbringer` is a thin main. `internal/app/uberbringer` holds the CLI and
the wiring, and `server/` holds the HTTP API. `internal/pkg/*` holds the
libraries. README § Development lists them. The module path is the bare
libraries. README § Development lists them. `tools/genopenapi` writes
`docs/swagger.json`; the `docs` package embeds it, and `internal/app` hands
it to the server in its config, so the generator never builds the package
that embeds its own output. The module path is the bare
`uberbringer`, so imports read `uberbringer/internal/...`. Imports point down:
- server → printqueue, receipt, printer, escpos
- printqueue → receipt
- receipt → escpos, raster
- printer → escpos
- internal/app → docs, server and the libraries
- tools/genopenapi → server, printqueue, receipt
Only `internal/app` reads config or wires in safehttp. Packages under
`internal/pkg` take plain values, and escpos knows nothing of JSON or HTTP.
@@ -49,6 +61,7 @@ works from PowerShell and fails from Git Bash.
go mod tidy -diff
go vet ./...
go tool staticcheck ./...
go generate ./... && git diff --exit-code -- docs/swagger.json # the OpenAPI document is up to date
go test -race -timeout 5m ./... *> "$env:TEMP\uberbringer-test.txt"; "exit $LASTEXITCODE"
go tool govulncheck ./... # after any dependency or toolchain change, and before a tag
goreleaser release --snapshot --clean # into dist/; after a change to .goreleaser.yaml or packaging/
@@ -101,9 +114,20 @@ docs (`README.md` or `docs/api.md`) and CHANGELOG.md say what changed.
- These changes land in one commit with their docs:
- A config key: `internal/pkg/config` (the default and the validation),
`configs/config.example.toml` and README § Configuration.
- A route, element field, status or error code: its code, its tests and
`docs/api.md`. A new route also needs its case in `TestRoutesConform`,
which fails for a route without one.
- A route, element field, status or error code: its code, its tests,
`docs/api.md` and the regenerated `docs/swagger.json`. A route is an
entry in the table in `server/routes.go`, never a direct
`app.Get`/`Post`; it also needs its case in `TestRoutesConform`, which
fails for a route without one, and `TestRegisteredRoutesAreTheTable`
fails for a route registered outside the table.
- An enum value or a limit goes into the field's `jsonschema` tag. The
tests in `receipt/schema_test.go`, `printqueue/schema_test.go` and
`server/schema_test.go` hold the tags to validation, to the Go constants
and to the values the handlers send. The enums list the canonical
spellings; validation also takes other letter case and a few aliases.
- A schema description is the first paragraph of the type's or field's
doc comment. Write it for API readers; notes for Go readers go after a
blank `//` line.
- Dependencies are at their latest stable release when added or bumped.
- Commit, push, tag or release only when the owner asks. Releases are
`vX.Y.Z` tags on `main`; `release.yml` refuses a tag whose commit is not on