Documentation
¶
Overview ¶
Package contract turns a document into artefacts that exercise the API it describes.
A generated document is a claim, and nothing in Spector until now could check it. The console's Execute button answers one request at a time; it is not something a repository keeps, a reviewer reads, or CI fails on. So a document and the service it describes drift apart silently, which is the one failure mode that makes documentation worse than none: it is believed.
Three artefacts come out, from one plan:
- requests.http — every endpoint as a runnable request, for the editor.
- contract_test.go — the same requests as Go tests, for CI.
- smoke.sh — status codes only, for a pipeline with nothing installed.
All three are source, not a runtime: the first version is free and every version after it belongs to the project, which is where the judgement about a particular API actually lives.
Index ¶
Constants ¶
const DefaultBaseURL = "http://localhost:8080"
DefaultBaseURL is where the artefacts point when neither the caller nor the document says otherwise.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// BaseURL is the API the artefacts call. Empty takes the document's first
// server, and failing that localhost — a generated artefact should run
// somewhere rather than not compile.
BaseURL string
// Package is the generated Go test package name; "contract" by default.
Package string
// Formats selects what is written: "http", "go", "curl". Empty means all
// three.
Formats []string
}
Options configures generation.