Documentation
¶
Overview ¶
Package spec loads an OpenAPI document and exposes its operations in a deterministic order. It encapsulates the OpenAPI library (kin-openapi) so the rest of apitest does not depend on its API directly.
Index ¶
Constants ¶
const ( FindingExampleSchema = "example_schema" FindingHeuristic = "heuristic" FindingBinding = "binding" FindingValidation = "validation" FindingAuth = "auth" )
Finding kinds.
const AssumedScheme = "apitestBearer"
AssumedScheme is the security scheme apitest adds when a spec declares no security at all (see AssumeBearer).
const Untagged = "untagged"
Untagged is the group of operations without tags.
Variables ¶
This section is empty.
Functions ¶
func CompilePattern ¶
func CompilePattern(expr string) (openapi3.RegexMatcher, error)
CompilePattern compiles a schema pattern the way apitest validates it, for tools that must produce values apitest accepts.
func DecodeJSON ¶
DecodeJSON decodes JSON with numbers kept as json.Number.
Types ¶
type Finding ¶
type Finding struct {
Kind string // e.g. FindingExampleSchema
Where string // location in the spec
Message string
}
Finding is a problem in the spec that does not prevent loading.
type Operation ¶
type Operation struct {
// ID is the operationId, or the substitute "<METHOD> <path>" (FR-SPEC-06).
ID string
HasOperationID bool
Method string
Path string
Tags []string
Op *openapi3.Operation
// Params are path-level and operation-level parameters merged; operation
// parameters override path parameters with the same name and location.
Params []*openapi3.Parameter
// Security is the effective security: the operation's own requirements
// or, if unset, the document's. An empty slice means "no authentication".
Security openapi3.SecurityRequirements
// Where is the location of the operation in the spec, e.g. "paths./x.post".
Where string
// SecurityDeclared is set if the operation or the document declares
// security, including an explicit "security: []".
SecurityDeclared bool
}
Operation is one path + method combination with its effective parameters and security requirements.
type SchemaError ¶
SchemaError is one validation problem at a JSON pointer.
func (SchemaError) String ¶
func (e SchemaError) String() string
type Spec ¶
type Spec struct {
Doc *openapi3.T
Path string // absolute path of the spec file
Version string // value of the "openapi" field
Ops []*Operation
Findings []Finding
}
Spec is a loaded, validated OpenAPI document.
func Load ¶
Load reads, resolves and validates the spec at path. Relative paths are resolved against the current working directory, as is usual in Go tests.
func (*Spec) AssumeBearer ¶
AssumeBearer handles specs that declare no security anywhere although the API needs a token: every operation without declared security requires a bearer token. It changes nothing if any operation or the document declares security (also "security: []"). With exactly one defined security scheme, that scheme is used, otherwise an http bearer scheme is added. It returns the scheme name and whether the spec was changed.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates values against schemas. It holds only per-validation settings; nothing is registered globally (FR-GO-04).
func NewValidator ¶
func NewValidator() *Validator
NewValidator returns a validator with format checks for the formats that FR-CMP-01 requires. Formats already known to kin-openapi (date, date-time, byte, int32, int64) are validated as well.