whole

package
v0.0.0-...-38da05c Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package whole reads a compiled document once it is whole, for the steps that run after the lowerings: it lists the operations and indexes the members, parameters and headers those steps name (Document). It imports ir alone, so it holds what the document states and nothing of a source's context, a policy or a step's verdict.

Index

Constants

View Source
const MaxAliasHops = 64

MaxAliasHops bounds how many alias scalars Stands reads a type through (styleguide bounded-everything rule), as the schema walk bounds a tag's. A longer chain, or a loop, stands for no type a step reads.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// Types is the document's registry, which is whole.
	Types ir.TypeRegistry
	// Ops is every operation of every service, those of nested groups included
	// to ir.MaxGroupDepth, as pointers into the document, a service's before
	// the next's.
	Ops []*ir.Operation
	// Auth is the document's security schemes, the map the document holds.
	Auth map[ir.AuthID]ir.AuthScheme
	// contains filtered or unexported fields
}

Document is a finished document as the steps after the lowerings read it: its links, promotions and inferences (docs/compilers/openapi.md#policies). It lists the operations once, and indexes what those steps read again and again, each at the first ask: a model's members by wire name, an operation's parameters and a response's headers. An index is kept, so no step may append a property, parameter, binding or header after one. New runs before the document's root is lowered, so a step reading the root's Unmodeled takes it as a parameter of its own.

func New

func New(doc *ir.Document) *Document

New returns a Document over doc, whose registry and service tree are whole, that has indexed nothing yet.

func (*Document) Header

func (w *Document) Header(at ResponseKey, headers []ir.Header, name string) []ir.PropID

Header returns the headers among headers that declare name, its case aside, as HTTP compares header names. headers are those of the response at names: the first read of a response indexes them and a later read takes that index, so reads of one key pass the same headers.

func (*Document) Member

func (w *Document) Member(id ir.TypeID, wire string) (*ir.Property, bool)

Member returns the declaration the flattening of the model id stands for (Stands) takes for the wire name wire (ir.MemberReader), and false where id stands for no model or the model holds no such member, so it reads a chain of alias scalars as Members does. Each answer is read once, by a walk of the model's composition, so a model read for n names costs n walks (#1955).

func (*Document) Members

func (w *Document) Members(id ir.TypeID) []*ir.Property

Members returns the members of the model id stands for (Stands), in layout order (ir.FlattenedProperties), and none for any other type. It flattens each model once, however many aliases name it, for a step that reads every member; one asking for a name reads it with Member, which flattens nothing.

func (*Document) Params

func (w *Document) Params(op *ir.Operation) ParamIndex

Params returns op's parameters by where its HTTP bindings place them, indexed at the first ask and kept.

func (*Document) Stands

func (w *Document) Stands(id ir.TypeID) ir.TypeDef

Stands returns the type id stands for, read through at most MaxAliasHops alias scalars, and nil past them or where the registry holds none, a typed nil included, so a caller's comma-ok assertion holds a node.

func (*Document) Walk

func (w *Document) Walk(root ir.TypeID, tokens []string) ([]ir.PropID, bool)

Walk returns the property each token names, from the model root through the type of each member it reaches, and false where a step reaches no model, or a model declaring no member of that name.

type ParamIndex

type ParamIndex struct {
	// contains filtered or unexported fields
}

ParamIndex is an operation's parameters by the location and the wire name its HTTP bindings place each at, in binding order: what a link's values and parameters keys and a replacement name read. It also holds where each parameter is placed, which a step reading a parameter's location reads. The host's bindings, which no such name reaches, are left out. Indexed once, a name or a parameter costs a map read however many an operation holds.

func (ParamIndex) Bound

func (ix ParamIndex) Bound(location ir.HTTPLocation, name string) []ir.ParamID

Bound returns the parameters bound at location under name, or at any location but the host for an empty one. A header's name matches in any case, as HTTP compares header names.

func (ParamIndex) Named

func (ix ParamIndex) Named(key string) (ir.ParamID, int)

Named returns the parameter key names, as a link's parameters key and a replacement name a parameter: `<in>.<name>`, or a name alone. It also returns how many parameters key matched, so a caller can tell none from several; the ID is only set when that is one.

func (ParamIndex) Placements

func (ix ParamIndex) Placements(id ir.ParamID) []Placement

Placements returns where the operation's bindings place the parameter id, in binding order, each place once; none for a parameter no binding places but at the host.

type Placement

type Placement struct {
	Location ir.HTTPLocation
	Name     string
}

Placement is where a binding places a parameter: its location, and the name it is sent under there, its wire name or else the parameter's own, as written.

type ResponseKey

type ResponseKey struct {
	Op    ir.OpID
	List  ResponseList
	Index int
}

ResponseKey names one response of a service, which Document indexes the headers of: the operation carrying it, the list it sits in, and where in the list. The default response is the one of ListDefault, at Index 0.

type ResponseList

type ResponseList int

ResponseList is the field of an ir.Operation a response sits in.

const (
	ListResponses ResponseList = iota
	ListErrors
	ListDefault
)

The fields an operation holds its responses in.

Jump to

Keyboard shortcuts

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