-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtag.go
More file actions
72 lines (62 loc) · 1.83 KB
/
tag.go
File metadata and controls
72 lines (62 loc) · 1.83 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
72
package openapi
// Tag adds metadata to a single tag that is used by the Operation Object.
// It is not mandatory to have a Tag Object per tag defined in the Operation Object instances.
//
// https://spec.openapis.org/oas/v3.1.1#tag-object
//
// Example:
//
// name: pet
// description: Pets operations
type Tag struct {
// Additional external documentation for this tag.
ExternalDocs *Extendable[ExternalDocs] `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
// REQUIRED.
// The name of the tag.
Name string `json:"name" yaml:"name"`
// A description for the tag.
// CommonMark syntax MAY be used for rich text representation.
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
func (o *Tag) validateSpec(location string, validator *Validator) []*validationError {
var errs []*validationError
if o.Name == "" {
errs = append(errs, newValidationError(joinLoc(location, "name"), ErrRequired))
}
if o.ExternalDocs != nil {
errs = append(errs, o.ExternalDocs.validateSpec(joinLoc(location, "externalDocs"), validator)...)
}
validator.visited[joinLoc("tags", o.Name)] = true
return errs
}
type TagBuilder struct {
spec *Extendable[Tag]
}
func NewTagBuilder() *TagBuilder {
return &TagBuilder{
spec: NewExtendable[Tag](&Tag{}),
}
}
func (b *TagBuilder) Build() *Extendable[Tag] {
return b.spec
}
func (b *TagBuilder) Extensions(v map[string]any) *TagBuilder {
b.spec.Extensions = v
return b
}
func (b *TagBuilder) AddExt(name string, value any) *TagBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *TagBuilder) ExternalDocs(v *Extendable[ExternalDocs]) *TagBuilder {
b.spec.Spec.ExternalDocs = v
return b
}
func (b *TagBuilder) Name(v string) *TagBuilder {
b.spec.Spec.Name = v
return b
}
func (b *TagBuilder) Description(v string) *TagBuilder {
b.spec.Spec.Description = v
return b
}