-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_parameters.go
49 lines (39 loc) · 1.8 KB
/
link_parameters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package openapi
import (
"iter"
"github.com/MarkRosemaker/errpath"
"github.com/MarkRosemaker/ordmap"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
)
// A map representing parameters to pass to an operation as specified with `operationId` or identified via `operationRef`. The key is the parameter name to be used, whereas the value can be a constant or an expression to be evaluated and passed to the linked operation.
// The parameter name can be qualified using the parameter location `[{in}.]{name}` for operations that use the same parameter name in different locations (e.g. path.id).
type LinkParameters map[string]*LinkParameter
func (ps LinkParameters) Validate() error {
for name, p := range ps.ByIndex() {
if err := p.Validate(); err != nil {
return &errpath.ErrKey{Key: name, Err: err}
}
}
return nil
}
// ByIndex returns a sequence of key-value pairs ordered by index.
func (ps LinkParameters) ByIndex() iter.Seq2[string, *LinkParameter] {
return ordmap.ByIndex(ps, getIndexLinkParameter)
}
// Sort sorts the map by key and sets the indices accordingly.
func (ps LinkParameters) Sort() {
ordmap.Sort(ps, setIndexLinkParameter)
}
// Set sets a value in the map, adding it at the end of the order.
func (ps *LinkParameters) Set(key string, p *LinkParameter) {
ordmap.Set(ps, key, p, getIndexLinkParameter, setIndexLinkParameter)
}
// MarshalJSONTo marshals the key-value pairs in order.
func (ps *LinkParameters) MarshalJSONTo(enc *jsontext.Encoder, opts json.Options) error {
return ordmap.MarshalJSONTo(ps, enc, opts)
}
// UnmarshalJSONFrom unmarshals the key-value pairs in order and sets the indices.
func (ps *LinkParameters) UnmarshalJSONFrom(dec *jsontext.Decoder, opts json.Options) error {
return ordmap.UnmarshalJSONFrom(ps, dec, opts, setIndexLinkParameter)
}