runtimeexpr

package
v0.0.0-...-5e35309 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package runtimeexpr reads the runtime expressions an OpenAPI document writes, as the values of a link and the page walk of an extension do, and finds the members of a body one names, through the reading of the compiled document those steps share (whole.Document). It reads the document the walks built and nothing of the walks, so the step resolving links and the one promoting a pagination, which run once the document is whole, read an expression alike (docs/compilers/openapi.md#policies).

Index

Constants

View Source
const (
	SourceURL        = "url"
	SourceMethod     = "method"
	SourceStatusCode = "statusCode"
	SourceRequest    = "request"
	SourceResponse   = "response"
)

The sources a runtime expression reads, as OpenAPI's grammar spells them.

View Source
const (
	PartHeader = "header"
	PartQuery  = "query"
	PartPath   = "path"
	PartBody   = "body"
)

The parts of a request or a response an expression reads.

Variables

This section is empty.

Functions

func BodyPath

func BodyPath(w *whole.Document, p *ir.Payload, tokens []string, side string) (segments []ir.PropID, why string, ok bool)

BodyPath returns the members tokens walk to from the root of every content of p, the body of side, and none for the body whole. Each content must walk to the same members, since an expression reads one value whichever media type arrives. A member is one declaration, so contents reaching the same one first walk the same chain from there, and only the first step tells them apart: each other content is asked for that member alone (whole.Document.Member). It returns why, and false, where p holds no body or the tokens name no such members.

func Embeds

func Embeds(s string) bool

Embeds reports whether s holds a runtime expression in braces, as a template such as `item-{$response.body#/id}` does: a string an expression is substituted into, which no link value spells, even when the braces hold the whole string. Braces count when what they hold starts as an expression, whether or not the rest keeps the grammar, as Parse tells an expression from a constant by its start. So no candidate is parsed, and braces opened many times before one close cost a look at each opening.

func RequestValue

func RequestValue(w *whole.Document, op *ir.Operation, text string) (*ir.InputPath, ir.TypeID, string)

RequestValue resolves text, an expression naming a value of op's request: a runtime expression reading a parameter or the body, or the shorthand `$request.` and a dotted chain of names, the first a parameter's name or, where no parameter carries it, a member of the body. It returns the value, the type of the parameter or member it names, "" for the body whole, which no one declaration types, and why it resolves nothing. Every step reading an expression of the request reads it here, so they read it alike.

Types

type Expression

type Expression struct {
	// Source is SourceURL, SourceMethod, SourceStatusCode, SourceRequest or
	// SourceResponse.
	Source string
	// Part is what of the request or response it reads, "" for the other
	// sources.
	Part string
	// Name is the header, query or path parameter it reads.
	Name string
	// Tokens are the decoded tokens of the pointer into the body, none for the
	// body whole.
	Tokens []string
}

Expression is one runtime expression, as the Runtime Expressions section of the OpenAPI Specification defines it: a value of the exchange a response ends.

func Parse

func Parse(s string) (Expression, bool, error)

Parse reads s as a runtime expression. It returns false for a string that is not one, which a link passes as a constant, and an error for one that starts as an expression and breaks the grammar: `$request.` or `$response.` followed by no part it names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL