Documentation
¶
Overview ¶
Package runtimeexpr reads the runtime expressions of the OpenAPI Specification: the values a Link Object passes to another operation and the keys of a Callback Object.
The grammar is the same ABNF in every 3.x version (3.0.0 through 3.2.0 differ only in the RFCs they cite for the pieces), and OAS 2.0 has no Link or Callback Object. https://spec.openapis.org/oas/v3.2.0.html#runtime-expressions
expression = "$url" / "$method" / "$statusCode" / "$request." source / "$response." source source = header-reference / query-reference / path-reference / body-reference header-reference = "header." token query-reference = "query." name path-reference = "path." name body-reference = "body" ["#" json-pointer] json-pointer = *( "/" reference-token ) reference-token = *( unescaped / escaped ) token = 1*tchar
Index ¶
Constants ¶
const ( SourceHeader = "header" SourceQuery = "query" SourcePath = "path" SourceBody = "body" )
The sources an expression can read from.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
type Expression struct {
// Request is true for `$request.` and false for `$response.`.
Request bool
// Source is one of the Source constants, empty for `$url`, `$method` and
// `$statusCode`.
Source string
// Name is the header token, query name or path name. It is empty for a body
// reference, whose JSON Pointer the grammar checks and nothing else needs.
Name string
}
Expression is what one runtime expression names. The zero value is `$url`, `$method` or `$statusCode`, which name no source.
func Parse ¶
func Parse(s string) (Expression, error)
Parse reads s as exactly one runtime expression, and says what is wrong when it is not one.
The `name` of a query or path reference is `*char`, so it can be empty and holds nearly anything; only the header token and the body's JSON Pointer carry a real restriction.
func Scan ¶
func Scan(value string) ([]Expression, error)
Scan reads a string value that may be a runtime expression and returns every expression it holds. A value is held to the grammar only when it claims to be an expression: it begins with `$request.` or `$response.`, or it embeds one between braces (`{$...}`), which is how the specification embeds one in a longer string. Anything else is a constant, which a Link parameter and a Callback key may also be, so it yields no expression and no error.
A brace that opens with `{$` must close, and what lies between must be an expression. An embedded expression ends at the first `}`.