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
@@ -61,12 +61,19 @@ const (
|
||||
|
||||
// Status describes a job.
|
||||
type Status struct {
|
||||
ID JobID `json:"id"`
|
||||
State State `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Attempts int `json:"attempts,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
StartedAt *time.Time `json:"started_at,omitempty"`
|
||||
// ID identifies the job.
|
||||
ID JobID `json:"id"`
|
||||
// State is where the job is in its lifecycle.
|
||||
State State `json:"status" jsonschema:"enum=queued,enum=printing,enum=done,enum=failed"`
|
||||
// Error says why a failed job failed.
|
||||
Error string `json:"error,omitempty"`
|
||||
// Attempts is how many times the job was sent to the printer.
|
||||
Attempts int `json:"attempts,omitempty"`
|
||||
// CreatedAt is when the job was queued.
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// StartedAt is when the worker took the job.
|
||||
StartedAt *time.Time `json:"started_at,omitempty"`
|
||||
// FinishedAt is when the job was done or failed.
|
||||
FinishedAt *time.Time `json:"finished_at,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user