-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_location.go
44 lines (36 loc) · 1.37 KB
/
parameter_location.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
package openapi
import (
"slices"
"github.com/MarkRosemaker/errpath"
)
// ParameterLocation defines the location of the parameter.
// There are four possible parameter locations specified by the `in` field of a Parameter.
type ParameterLocation string
const (
// Used together with Path Templating, where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
ParameterLocationPath ParameterLocation = "path"
// Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
ParameterLocationQuery ParameterLocation = "query"
// Custom headers that are expected as part of the request. Note that RFC7230 states header names are case insensitive.
ParameterLocationHeader ParameterLocation = "header"
// Used to pass a specific cookie value to the API.
ParameterLocationCookie ParameterLocation = "cookie"
)
var allParameterLocations = []ParameterLocation{
ParameterLocationPath,
ParameterLocationQuery,
ParameterLocationHeader,
ParameterLocationCookie,
}
func (p ParameterLocation) Validate() error {
if p == "" {
return &errpath.ErrRequired{}
}
if slices.Contains(allParameterLocations, p) {
return nil
}
return &errpath.ErrInvalid[ParameterLocation]{
Value: p,
Enum: allParameterLocations,
}
}