Documentation
¶
Overview ¶
Package pathtemplate reads the paths of an OpenAPI document, whose segments may hold parameters, such as {id}. The mock generator and the openapi matcher read them alike: the matcher routes a request to the operation whose mocks the generator orders first.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Param = regexp.MustCompile(`\{[^{}/]+\}`)
Param matches a parameter of a path, such as {id}.
Functions ¶
func Decode ¶
Decode returns s, text of a path of the spec, decoded, as the server compares a path: a % that starts no escape, such as that of 50%, is a percent sign.
func Fill ¶
Fill returns path, a path of the spec, with literal applied to each text between its parameters and each parameter, such as {id}, replaced by param of it.
Types ¶
type Kind ¶
type Kind int
Kind is how the mocks of a path compare a request's path.
const ( // Literal compares the request's path, decoded, with [Route.Path], for a path without parameters. Literal Kind = iota // Segments compares the request's path with [Route.Path], a path template whose parameters are whole segments: // as a mock's path_template does it, both split at each / before they are decoded. Segments // Pattern matches the request's path, decoded, against [Route.Path], a regular expression, for a parameter inside // a segment, such as {name}.txt. Pattern )
type Route ¶
type Route struct {
// Kind is how the mocks compare a request's path.
Kind Kind
// Path is what they compare it with: the path decoded, a path template, or a regular expression.
Path string
// contains filtered or unexported fields
}
Route is where the mocks of a path answer: how they compare a request's path, and with what.
func NewExample ¶
NewExample returns the route of an example of path, a path of the spec under base, whose parameters, such as {id}, take the values of values, by parameter, decoded: a parameter values lacks stays one. Its mocks match only requests that those of NewRoute match: the ones with those values, or with others for a parameter inside a segment, whose example matches the same path decoded. It returns false when they would match none: a value is empty, or holds a / inside a segment.
func NewRoute ¶
NewRoute returns the route of path, a path of the spec under base, a base path decoded. An escape of the spec, such as %20, matches the request that sends it.