bind

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bind decides which parameters get their value from an earlier response (FR-PARAM-01 rank 1, FR-PARAM-03/05/06) and extracts those values.

Sources, in order of precedence:

  1. x-apitest-bind at the parameter,
  2. OpenAPI links in a 2xx response of the producing operation,
  3. a heuristic for path parameters within the same resource group.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

func Extract(src Source, kind Kind, header http.Header, body, reqBody any) (any, bool)

Extract reads the value of src from an exchange. body is the decoded response body (nil if none), reqBody the decoded request body.

func LastSegment

func LastSegment(loc string) string

LastSegment returns the last path segment of a URL or path, e.g. "42" for "/books/42" or "http://h/books/42?x=1".

func Pointer

func Pointer(v any, ptr string) (any, bool)

Pointer resolves a JSON pointer in a decoded value.

Types

type Binding

type Binding struct {
	Consumer *spec.Operation
	Param    *openapi3.Parameter
	Producer *spec.Operation
	Source   Source
	Kind     Kind
}

Binding fills one parameter of a consumer operation from a producer.

func (*Binding) CrossGroup

func (b *Binding) CrossGroup() bool

CrossGroup reports whether producer and consumer are in different groups.

func (*Binding) Key

func (b *Binding) Key() string

Key identifies the value a binding reads. Bindings with the same key share one value, so an update after PUT affects all of them (FR-PARAM-04).

type Kind

type Kind int

Kind is how a binding was declared.

const (
	Explicit  Kind = iota // x-apitest-bind
	Link                  // OpenAPI links
	Heuristic             // FR-PARAM-06
)

Binding kinds.

func (Kind) String

func (k Kind) String() string

type Set

type Set struct {
	Findings []spec.Finding
	// contains filtered or unexported fields
}

Set holds all bindings of a spec.

func Resolve

func Resolve(s *spec.Spec) (*Set, error)

Resolve determines the bindings of all operations. Errors in explicit declarations are returned before any request is sent (NFR-08).

func (*Set) By

func (set *Set) By(op *spec.Operation) []*Binding

By returns all bindings whose producer is op.

func (*Set) For

func (set *Set) For(op *spec.Operation, p *openapi3.Parameter) *Binding

For returns the binding of parameter p of operation op, or nil.

func (*Set) Of

func (set *Set) Of(op *spec.Operation) []*Binding

Of returns the bindings of op, sorted by parameter.

type Source

type Source struct {
	// Pointer is a JSON pointer into the response body (or the request body
	// if FromRequest is set), e.g. "/id".
	Pointer string
	// Header is a response header. For "Location" the last path segment is
	// used (FR-PARAM-03).
	Header      string
	FromRequest bool
	// Const is a constant value from a link.
	Const    any
	HasConst bool
}

Source is where a bound value comes from.

func (Source) String

func (s Source) String() string

Jump to

Keyboard shortcuts

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