Documentation
¶
Overview ¶
Package contract renders ContentKit's route catalog (internal/httpapi) and error-code registry as the files other tools read: api/openapi.json, the browser SDK's generated route table, wire types and error codes, and docs/api/routes.md. They are committed: `go generate ./internal/contract` rewrites them and TestGeneratedContractIsFresh fails when one is stale.
Index ¶
Constants ¶
const ( OpenAPIFile = "api/openapi.json" RoutesDoc = "docs/api/routes.md" SDKDir = "sdk/ui/src/client/generated/" )
Where each generated file lives, relative to the repository.
Variables ¶
var ErrStale = errors.New("generated contract files are stale")
ErrStale is a committed generated file that no longer matches the catalog.
Functions ¶
func Files ¶
Files renders every generated file by repository path. fsys is the repository: enum values are read from the source that declares them.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker holds real responses to the catalog: tests wrap a handler with it, so every answer of a real request is checked against what its route declares.
func NewChecker ¶
NewChecker builds a checker over the catalog; fsys is the repository.
func (*Checker) Check ¶
Check holds one response to its route's contract: a declared status with its body, or an error body whose code the route may answer with that code's status.
type ErrorReply ¶
type ErrorReply struct {
Error string `json:"error"`
Code string `json:"code"`
RetryAfter int `json:"retry_after,omitempty"`
Action content.Action `json:"action,omitempty"`
Ban *content.BanNotice `json:"ban,omitempty"`
Blobs []string `json:"blobs,omitempty"`
Details *media.ErrorDetails `json:"details,omitempty"`
}
ErrorReply is the flat error body every module answers. A code's own members appear only with it: retry_after with rate_limited and unavailable, action with an interaction's rate_limited, ban with comment_banned, blobs with not_uploaded, details with an upload refusal.