Documentation
¶
Overview ¶
Package parameter defines serialization functions for HTTP parameters.
Index ¶
- func DecodeCookieParameters(definition []*oaschema.Parameter, cookies []*http.Cookie) (map[string]any, []httperror.ValidationError)
- func DecodeHeaderParameters(definition []*oaschema.Parameter, headers http.Header) (map[string]any, []httperror.ValidationError)
- func DecodePathValue(definition *oaschema.Parameter, value string) (any, []httperror.ValidationError)
- func DecodeQueryFromParameters(definitions []*oaschema.Parameter, values map[string][]string) (map[string]any, []httperror.ValidationError)
- func EncodeHeader(definition *oaschema.Parameter, value any) string
- func EncodeParamDelimitedStyleNonExplode(params ParameterItems, separator string, assignSymbol string, ...) string
- func EncodePathValue(definition *oaschema.Parameter, value any) string
- func EncodeQueryEscape(value string, allowReserved bool) string
- func EncodeQueryValuesUnescape(values url.Values) string
- func GetQueryEscapeFunc(allowReserved bool) func(string) string
- func IsParamIndex(selector ParamSelector) bool
- func IsParamKey(selector ParamSelector) bool
- func IsReservedCharacter[C byte | rune](c C) bool
- func IsUnreservedCharacter[C byte | rune](c C) bool
- func NormalizeHeaders(headers http.Header) map[string]any
- func QueryEscapeAllowReserved(query string) string
- func SetQueryParam(params url.Values, definition *oaschema.Parameter, value any)
- type ParamIndex
- type ParamKey
- type ParamKeys
- type ParamSelector
- type ParameterItem
- type ParameterItems
- type ParameterNode
- func (pn *ParameterNode) Decode(schema *base.Schema) (any, []httperror.ValidationError)
- func (pn *ParameterNode) FindNode(key ParamSelector) *ParameterNode
- func (pn *ParameterNode) InsertNode(keys ParamKeys, values []string) *httperror.ValidationError
- func (pn *ParameterNode) Normalize()
- func (pn ParameterNode) String() string
- type ParameterNodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeCookieParameters ¶
func DecodeCookieParameters( definition []*oaschema.Parameter, cookies []*http.Cookie, ) (map[string]any, []httperror.ValidationError)
DecodeCookieParameters decodes header parameters from the header map value. Each header value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func DecodeHeaderParameters ¶
func DecodeHeaderParameters( definition []*oaschema.Parameter, headers http.Header, ) (map[string]any, []httperror.ValidationError)
DecodeHeaderParameters decodes header parameters from the header map value. Each header value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func DecodePathValue ¶
func DecodePathValue( definition *oaschema.Parameter, value string, ) (any, []httperror.ValidationError)
DecodePathValue decodes the path parameter from a string value. The value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func DecodeQueryFromParameters ¶
func DecodeQueryFromParameters( definitions []*oaschema.Parameter, values map[string][]string, ) (map[string]any, []httperror.ValidationError)
DecodeQueryFromParameters decodes the query parameters from string values. The value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func EncodeHeader ¶
EncodeHeader encodes the header from an arbitrary value. The value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func EncodeParamDelimitedStyleNonExplode ¶
func EncodeParamDelimitedStyleNonExplode( params ParameterItems, separator string, assignSymbol string, formatFunc func(string) string, ) string
EncodeParamDelimitedStyleNonExplode encodes ampersand-separated values with explode=false.
func EncodePathValue ¶
EncodePathValue encodes the path parameter from an arbitrary value. The value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
func EncodeQueryEscape ¶
EncodeQueryEscape encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key with escape.
func EncodeQueryValuesUnescape ¶
EncodeQueryValuesUnescape encode query values into “URL encoded” form ("bar=baz&foo=quux") sorted by key without escape.
func GetQueryEscapeFunc ¶
GetQueryEscapeFunc returns either query escape or allow-reserved encoder function.
func IsParamIndex ¶
func IsParamIndex(selector ParamSelector) bool
IsParamIndex reports whether selector is a numeric index.
func IsParamKey ¶
func IsParamKey(selector ParamSelector) bool
IsParamKey reports whether selector is a string key.
func IsReservedCharacter ¶
IsReservedCharacter checks if the character is allowed in a URI and has a reserved purpose.
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
func IsUnreservedCharacter ¶
IsUnreservedCharacter checks if the character is allowed in a URI but do not has a reserved purpose are called unreserved.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
func NormalizeHeaders ¶
NormalizeHeaders normalize HTTP headers to a string value map. Header keys are transformed to lowercase. Header values are transformed to either string or array string if they have many items.
func QueryEscapeAllowReserved ¶
QueryEscapeAllowReserved escapes the string so it can be safely placed inside a URL query. Allow reserved character.
func SetQueryParam ¶
SetQueryParam encodes and set the query param into URL values. The value is encoded differently on each style, according to the [OpenAPI specification].
[OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/3.2.0/versions/3.2.0.md#style-examples)
Types ¶
type ParamIndex ¶
type ParamIndex int
ParamIndex represents a parameter index. The sentinel value -1 is used when a bare "[]" suffix is parsed from a deep-object key (e.g. "ids[]"), meaning the position within the array is not known until Normalize resolves it.
func (ParamIndex) Equal ¶
func (k ParamIndex) Equal(target ParamSelector) bool
Equal checks if the target value is equal.
func (ParamIndex) String ¶
func (k ParamIndex) String() string
String implements fmt.Stringer interface.
type ParamKey ¶
type ParamKey string
ParamKey represents a parameter key string.
func (ParamKey) Equal ¶
func (k ParamKey) Equal(target ParamSelector) bool
Equal checks if the target value is equal.
type ParamKeys ¶
type ParamKeys []ParamSelector
ParamKeys is an ordered path of selectors that locates a value within a nested parameter tree, e.g. [ParamKey("address"), ParamKey("city")] or [ParamKey("ids"), ParamIndex(0)].
type ParamSelector ¶
ParamSelector is the discriminated union for a single path segment: either a string key (ParamKey) for object properties or a numeric index (ParamIndex) for array elements.
type ParameterItem ¶
type ParameterItem struct {
// contains filtered or unexported fields
}
ParameterItem represents the key-value pair.
func NewParameterItem ¶
func NewParameterItem(keys ParamKeys, value string) ParameterItem
NewParameterItem creates a parameter value pair.
func (ParameterItem) IsNested ¶
func (pi ParameterItem) IsNested() bool
IsNested checks if the parameter is a nested object field.
func (ParameterItem) Keys ¶
func (pi ParameterItem) Keys() ParamKeys
Keys return key fragments of the parameter item.
func (ParameterItem) Value ¶
func (pi ParameterItem) Value() string
Value return the value of the item.
type ParameterItems ¶
type ParameterItems []ParameterItem
ParameterItems is the flattened representation of a (potentially nested) parameter value produced by EvaluateParameterValue. Each item carries the full key path and the serialized leaf value so encoders can reconstruct any OpenAPI serialization style.
func EvaluateParameterValue ¶
func EvaluateParameterValue(value any, parentKeys ParamKeys) ParameterItems
EvaluateParameterValue evaluates the type of the value and encode it into a string map.
type ParameterNode ¶
type ParameterNode struct {
// contains filtered or unexported fields
}
ParameterNode is a single node in the decoded parameter tree. Leaf nodes (no items) carry raw string values; branch nodes carry child nodes keyed by ParamKey (object property) or ParamIndex (array element).
func (*ParameterNode) Decode ¶
func (pn *ParameterNode) Decode(schema *base.Schema) (any, []httperror.ValidationError)
Decode resolves the node's raw values into a typed Go value guided by schema. Object and array schema types are tried first; remaining scalar types are tried in declaration order.
func (*ParameterNode) FindNode ¶
func (pn *ParameterNode) FindNode(key ParamSelector) *ParameterNode
FindNode returns the direct child node matching key, or nil if absent.
func (*ParameterNode) InsertNode ¶
func (pn *ParameterNode) InsertNode(keys ParamKeys, values []string) *httperror.ValidationError
InsertNode walks (or creates) the path described by keys and stores values at the leaf. When mixing ParamKey and ParamIndex siblings it tries to coerce the odd type so that the whole level is consistently typed; it returns an error if coercion is impossible.
func (*ParameterNode) Normalize ¶
func (pn *ParameterNode) Normalize()
Normalize resolves ambiguities that arise from deep-object query parsing:
- A single numeric ParamKey child ("0") is promoted to ParamIndex so the node is treated as an array element rather than an object property.
- A single ParamIndex child with no further children is collapsed: its values are hoisted into the parent, flattening a one-element array.
- Multi-element arrays are sorted by index so later schema validation sees items in order.
func (ParameterNode) String ¶
func (pn ParameterNode) String() string
type ParameterNodes ¶
type ParameterNodes []*ParameterNode
ParameterNodes is a flat list of root-level ParameterNode entries, one per distinct top-level key. It is used as the working set when inserting and decoding deep-object query parameters.
func (ParameterNodes) Find ¶
func (pn ParameterNodes) Find(key ParamSelector) *ParameterNode
Find returns the first node whose key equals key, or nil if not found.
func (*ParameterNodes) Insert ¶
func (pn *ParameterNodes) Insert(keys ParamKeys, values []string) *httperror.ValidationError
Insert inserts a leaf at the path described by keys, creating intermediate nodes as needed.
func (ParameterNodes) String ¶
func (pn ParameterNodes) String() string
String implements fmt.Stringer for debugging.