-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver_variable.go
More file actions
71 lines (60 loc) · 2.24 KB
/
server_variable.go
File metadata and controls
71 lines (60 loc) · 2.24 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package openapi
// ServerVariable is an object representing a Server Variable for server URL template substitution.
//
// https://spec.openapis.org/oas/v3.1.1#server-variable-object
type ServerVariable struct {
// REQUIRED.
// The default value to use for substitution, which SHALL be sent if an alternate value is not supplied.
// Note this behavior is different than the Schema Object’s treatment of default values,
// because in those cases parameter values are optional.
// If the enum is defined, the value MUST exist in the enum’s values.
Default string `json:"default" yaml:"default"`
// An optional description for the server variable.
// CommonMark syntax MAY be used for rich text representation.
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// An enumeration of string values to be used if the substitution options are from a limited set.
// The array MUST NOT be empty.
Enum []string `json:"enum,omitempty" yaml:"enum,omitempty"`
}
func (o *ServerVariable) validateSpec(location string, _ *Validator) []*validationError {
var errs []*validationError
if o.Default == "" {
errs = append(errs, newValidationError(joinLoc(location, "default"), ErrRequired))
}
return errs
}
type ServerVariableBuilder struct {
spec *Extendable[ServerVariable]
}
func NewServerVariableBuilder() *ServerVariableBuilder {
return &ServerVariableBuilder{
spec: NewExtendable[ServerVariable](&ServerVariable{}),
}
}
func (b *ServerVariableBuilder) Build() *Extendable[ServerVariable] {
return b.spec
}
func (b *ServerVariableBuilder) Extensions(v map[string]any) *ServerVariableBuilder {
b.spec.Extensions = v
return b
}
func (b *ServerVariableBuilder) AddExt(name string, value any) *ServerVariableBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *ServerVariableBuilder) Default(v string) *ServerVariableBuilder {
b.spec.Spec.Default = v
return b
}
func (b *ServerVariableBuilder) Description(v string) *ServerVariableBuilder {
b.spec.Spec.Description = v
return b
}
func (b *ServerVariableBuilder) Enum(v ...string) *ServerVariableBuilder {
b.spec.Spec.Enum = v
return b
}
func (b *ServerVariableBuilder) AddEnum(v ...string) *ServerVariableBuilder {
b.spec.Spec.Enum = append(b.spec.Spec.Enum, v...)
return b
}