Generate the OpenAPI document from a route table
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:
1 parent
9f7c5db923
commit
bdd337e2dc
31 files changed
+3153
-128
No files matched your search
@@ -124,6 +124,8 @@ make run
|
||||
|
||||
[docs/api.md](docs/api.md) is the API reference: the routes, the print
|
||||
elements and blocks, and the error codes.
|
||||
[docs/swagger.json](docs/swagger.json) is the OpenAPI 3.1 document,
|
||||
generated from the route table; the daemon serves it at `GET /openapi.json`.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -251,6 +253,7 @@ make check # the CI gate, below
|
||||
make build # bin/uberbringer
|
||||
make fmt # gofmt + goimports
|
||||
make vuln # govulncheck
|
||||
make openapi # regenerate docs/swagger.json (go generate ./...)
|
||||
make snapshot # release archives in dist/; publishes nothing
|
||||
```
|
||||
|
||||
@@ -261,14 +264,24 @@ order:
|
||||
2. `tidy-check`: `go mod tidy -diff`.
|
||||
3. `go vet`.
|
||||
4. staticcheck.
|
||||
5. `go test -race -timeout 5m`.
|
||||
6. `release-check`: `goreleaser check`, which validates the release config
|
||||
5. `openapi-check`: `go generate ./...` must leave `docs/swagger.json`
|
||||
unchanged.
|
||||
6. `go test -race -timeout 5m`.
|
||||
7. `release-check`: `goreleaser check`, which validates the release config
|
||||
without building.
|
||||
|
||||
It needs goreleaser installed. govulncheck is not part of it; run
|
||||
`make vuln`. `make snapshot` builds the release archives locally; run it after
|
||||
changing `.goreleaser.yaml` or `packaging/`. `make` builds report the version without the leading `v`, e.g.
|
||||
`0.1.2-3-gabc1234`, as release binaries do.
|
||||
`make vuln`. `make snapshot` builds the release archives locally; run it
|
||||
after changing `.goreleaser.yaml` or `packaging/`. `make` builds report the
|
||||
version without the leading `v`, e.g. `0.1.2-3-gabc1234`, as release
|
||||
binaries do.
|
||||
|
||||
`docs/swagger.json` is generated by `tools/genopenapi` from the route table
|
||||
in `internal/app/uberbringer/server/routes.go`, which the server also
|
||||
registers its routes from. The schemas come from the Go types the routes
|
||||
name: their `json` and `jsonschema` tags and their doc comments. Never edit
|
||||
the file by hand: change the route table or the types, run
|
||||
`go generate ./...`, and commit the document with the change.
|
||||
|
||||
The linters are pinned as Go tools in `go.mod`, so `go tool staticcheck`,
|
||||
`go tool govulncheck` and `go tool goimports` need no separate install. The
|
||||
@@ -289,7 +302,8 @@ internal/pkg/printqueue/ Job queue, worker and status history
|
||||
configs/ Example configuration
|
||||
examples/ Example jobs, such as the block calibration receipt
|
||||
packaging/ systemd unit
|
||||
docs/ Design notes and feature plans
|
||||
tools/genopenapi/ Generates docs/swagger.json from the route table
|
||||
docs/ API reference, OpenAPI document, design notes and feature plans
|
||||
```
|
||||
|
||||
[docs/design.md](docs/design.md) explains why the daemon is shaped as it is.
|
||||
@@ -300,9 +314,10 @@ docs/ Design notes and feature plans
|
||||
CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
|
||||
`.github/` directory.
|
||||
|
||||
- `test.yml` runs the `make check` gate on every branch push. It lints, tests
|
||||
and validates the release config, but builds no binaries, and it does not
|
||||
run on pull requests or tags. Binaries are built only by `release.yml`.
|
||||
- `test.yml` runs the `make check` gate on every branch push. It lints,
|
||||
checks that `docs/swagger.json` is up to date, tests and validates the
|
||||
release config, but builds no binaries, and it does not run on pull
|
||||
requests or tags. Binaries are built only by `release.yml`.
|
||||
- `security.yml` runs govulncheck on pushes to main and every Monday at
|
||||
06:00 UTC. Scheduled runs use main's copy of the workflow.
|
||||
- `release.yml` builds and publishes a release with goreleaser 2.20.3 when a
|
||||
@@ -311,8 +326,8 @@ CI runs on the Gitea runner from `.gitea/workflows/`. The repository has no
|
||||
- `vX.Y.Z-rc.N` tags are published as prereleases, so they never become the
|
||||
latest release that `install.sh` installs.
|
||||
- Each archive holds the binary, `LICENSE.txt`, `README.md`,
|
||||
`docs/api.md`, `CHANGELOG.md`, `configs/config.example.toml` and
|
||||
`packaging/uberbringer.service`.
|
||||
`docs/api.md`, `docs/swagger.json`, `CHANGELOG.md`,
|
||||
`configs/config.example.toml` and `packaging/uberbringer.service`.
|
||||
- The release notes link to `CHANGELOG.md` at the tag.
|
||||
|
||||
## License
|
||||
|
||||
Reference in new issue
Block a user