Documentation
¶
Overview ¶
Package flowioverlay applies flowi overlays to request versions, works out the overlay that turns one version into an edited copy, and reads and writes overlay files.
A flowi overlay is not an OpenAPI Overlay (see package specoverlay): that patches an API description once, at import; this patches a request at send time and can set any field a request has.
Index ¶
- Constants
- func CheckName(name string) error
- func CheckOp(op model.OverlayOp) error
- func Decode(file, fallbackName string, data []byte) (model.Overlay, diag.List)
- func Describe(op model.OverlayOp) string
- func Diff(base, edited model.RequestVersion) (ops []model.OverlayOp, unsupported []string)
- func Encode(o model.Overlay) ([]byte, error)
- func ForRequest(o model.Overlay, id model.ID) []model.OverlayOp
- func MergePatch(base, patch any) any
- func Resolve(overlays []model.Overlay, stack string, id model.ID) (ops []model.OverlayOp, missing string)
- func Stack(stack string) []string
- type Problem
Constants ¶
const FormatVersion = 1
FormatVersion is the value of the file's flowi_overlay key.
const StackSeparator = "+"
StackSeparator joins the names of overlays laid over one request, in order: "vip+slow". CheckName refuses it in a name, so a stack is never ambiguous and stays one string wherever an overlay is named (a flag, a flow step, a folder of saved responses).
const Suffix = ".flowi-overlay.yaml"
Suffix ends the file name of a flowi overlay, kept under overlays/.
Variables ¶
This section is empty.
Functions ¶
func CheckName ¶
CheckName reports why name cannot be a flowi overlay's name: it becomes a file name and appears in response folders and flags.
func CheckOp ¶
CheckOp reports why op can never apply to any version: an unknown field, a verb the field does not take, or a missing name after the dot. It does not look at any version, so it cannot tell a header that is absent.
func Decode ¶
Decode reads a *.flowi-overlay.yaml file. fallbackName names the overlay when the file does not (the file name without the suffix). Problems are FLW-OVL-001.
func Describe ¶
Describe says what op does in a short sentence a user reads in a save dialog or a warning: "Set header X-Tier to "vip"".
func Diff ¶
func Diff(base, edited model.RequestVersion) (ops []model.OverlayOp, unsupported []string)
Diff works out the operations that turn base into edited, and the parts of the edit an overlay cannot hold (inline hooks, a changed form or file body), each as a short sentence. Applying the operations to base gives edited, except for those parts.
func Encode ¶
Encode writes an overlay as a file. Requests are sorted by id so the file changes only where the overlay does.
func ForRequest ¶
ForRequest returns the operations that apply to request id: the shared part first, then the request's own.
func MergePatch ¶
MergePatch applies an RFC 7386 JSON merge patch: objects merge key by key, null removes a key, anything else replaces.
func Resolve ¶
func Resolve(overlays []model.Overlay, stack string, id model.ID) (ops []model.OverlayOp, missing string)
Resolve returns the operations the overlays of stack make to request id, each overlay's shared part and then its own, in the order named, so a later overlay wins where two set the same field. missing is the first name that is not among overlays ("" when all are).
Types ¶
type Problem ¶
type Problem struct {
Op model.OverlayOp
Reason string
// Drift marks an operation that was applied: the base no longer holds
// what it held when the overlay was saved. Otherwise the operation was
// left out.
Drift bool
}
Problem is an operation that did not fit the version it was applied to, or that applied although the base changed since the overlay was saved.
func Apply ¶
func Apply(v model.RequestVersion, ops []model.OverlayOp) (model.RequestVersion, []Problem)
Apply returns v with ops applied in order. An operation that does not fit (it removes a header the version no longer has) is left out and reported; the rest still apply. v is not changed.