Documentation
¶
Overview ¶
Package operations is the generated table of every operation in the seven bundled specs, with the chi route pattern the router serves it under and the classes it declares, and an Index that finds the operation a request addresses before routing.
Role ¶
platform layer, in platform/gen, where make generate writes what it derives from the specs. tools/optable (internal/devtools/optable) writes operations.gen.go, the Table, from api/*.openapi.yaml after oapi-codegen has generated the servers. This doc.go and operation.go, the Operation type and the Index, are hand-written, and make generate leaves them alone. The Idempotency-Key gate and the shared replay's strict middleware (IDEM-01, #1406) read it at run time for the operations that accept a key, and admission (internal/app, limits_cost.go) takes each request's cost class from it (RATE-01, #1407; decision 0043).
Inputs ¶
- api/<service>.openapi.yaml, through tools/optable: each operation's method, path, operationId, x-handwritten, x-cost, x-cost-expensive-query, x-idempotency, x-pagination and a reference to the shared IdempotencyKey parameter, and its spec's server URL.
- At run time: the table for NewIndex, and a request's method and escaped path for Find and FindRequest.
Outputs ¶
- Table: one Operation per operation, sorted by pattern and method, each with only the classes its spec declares set.
- Index: Find returns the operation a method and escaped path address through chi's own tree (chi.Mux.Find), so a static segment beats a parameter as it does in the router, and reports false for a request no spec pattern matches.
- NewIndex's errors: ErrDuplicate for a method and pattern listed twice, ErrPattern for a pattern chi cannot route.
Invariants ¶
- operations.gen.go is never edited by hand: make generate rewrites it, and make verify-generate fails while it differs from what the bundles give (decision 0002). A class changes in api/src.
- Every pattern a generated server registers is a row's pattern for the same method and operationId, and every row of an operation not marked handwritten is registered by its generated server. A hand-written operation keeps its spec pattern; where its hand-written route uses another, TestAccAdmissionCostAgreesWithServedRoutes (internal/app) checks that the two admit its requests under one class.
- A pattern is the spec's server URL, the BaseURL router.go mounts each generated server under, followed by the spec path.
- A class is the spec's text as written: one of decision 0043's values, or TODO(author) on an x-draft operation make scaffold wrote, which TestAccAPIPrinciples allows nowhere else. A reader that meets a value it does not know treats the operation as unclassified.
References ¶
- Decision 0043, "Cost classes and how admission finds them" and "Replay for keyed operations": docs/research/decisions/0043-api-reliability.md.
- Decision 0002: docs/research/decisions/0002-spec-first-flat-crud-handwritten-item-paths.md.
- https://github.com/weaveplatform/artifactweave/issues/1405
Status ¶
Implemented #1405 (CON-02): the table and the Index. Read at run time by admission (RATE-01, #1407) and the key gate (IDEM-01, #1406).
Testing ¶
- TestUnitTableMatchesGeneratedServers: for each spec, the routes its generated server registers under its base URL are exactly the table's rows not marked handwritten.
- TestUnitIndexFindsEveryOperation: an Index over the Table finds each row from a request path built from its pattern.
- TestUnitIndexFind: a static segment beats a parameter, an escaped slash stays in its segment through FindRequest, and an unknown path or method finds nothing.
- TestUnitNewIndexErrors: a row listed twice and a pattern chi refuses fail.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDuplicate: two rows share a method and pattern. ErrDuplicate = errors.New("operations: a method and pattern listed twice") // ErrPattern: chi refused a pattern. ErrPattern = errors.New("operations: a pattern chi cannot route") )
Errors NewIndex wraps.
var Table = []Operation{}/* 643 elements not displayed */
Table lists every operation of the bundled specs, sorted by pattern and method.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index finds the operation a request addresses with chi's own routing over the table's patterns, so the lookup applies the router's precedence (a static segment beats a parameter) to the same escaped path.
func NewIndex ¶
NewIndex builds an Index over table. It fails when chi refuses a pattern, or when two rows share a method and pattern, which would make the lookup ambiguous.
type Operation ¶
type Operation struct {
// Service is the spec, api/<Service>.openapi.yaml.
Service string
// Method is the HTTP method in upper case.
Method string
// Pattern is the chi route pattern the router serves the operation
// under: the spec's server URL, which router.go mounts each generated
// server at, and the spec path with oapi-codegen's parameter syntax.
Pattern string
// OperationID is the spec's operationId, which the generated strict
// server passes its middleware.
OperationID string
// Handwritten marks an x-handwritten operation: a hand-written route
// serves it, and the generated server does not register its pattern.
Handwritten bool
// Cost is x-cost: ordinary, expensive, exempt or recovery.
Cost string
// ExpensiveQuery is x-cost-expensive-query: the query parameters whose
// presence makes an ordinary operation expensive.
ExpensiveQuery []string
// IdempotencyKey reports that the operation declares the shared
// IdempotencyKey parameter, so the server honours Idempotency-Key on it.
IdempotencyKey bool
// Idempotency is x-idempotency: safe, natural, key or none.
Idempotency string
// Pagination is x-pagination: cursor, offset, page, native or complete,
// or empty for an operation that returns no collection.
Pagination string
}
Operation is one operation of the bundled specs and the classes it declares (decision 0043, "Rules for every operation"). A class the spec does not declare yet is the empty string.