-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtag.go
More file actions
78 lines (64 loc) · 2.17 KB
/
Copy pathtag.go
File metadata and controls
78 lines (64 loc) · 2.17 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
73
74
75
76
77
78
package swagger
import (
"context"
"errors"
"github.com/speakeasy-api/openapi/extensions"
"github.com/speakeasy-api/openapi/internal/interfaces"
"github.com/speakeasy-api/openapi/marshaller"
"github.com/speakeasy-api/openapi/swagger/core"
"github.com/speakeasy-api/openapi/validation"
)
// Tag allows adding metadata to a single tag that is used by operations.
type Tag struct {
marshaller.Model[core.Tag]
// Name is the name of the tag.
Name string
// Description is a short description for the tag. GFM syntax can be used for rich text representation.
Description *string
// ExternalDocs is additional external documentation for this tag.
ExternalDocs *ExternalDocumentation
// Extensions provides a list of extensions to the Tag object.
Extensions *extensions.Extensions
}
var _ interfaces.Model[core.Tag] = (*Tag)(nil)
// GetName returns the value of the Name field. Returns empty string if not set.
func (t *Tag) GetName() string {
if t == nil {
return ""
}
return t.Name
}
// GetDescription returns the value of the Description field. Returns empty string if not set.
func (t *Tag) GetDescription() string {
if t == nil || t.Description == nil {
return ""
}
return *t.Description
}
// GetExternalDocs returns the value of the ExternalDocs field. Returns nil if not set.
func (t *Tag) GetExternalDocs() *ExternalDocumentation {
if t == nil {
return nil
}
return t.ExternalDocs
}
// GetExtensions returns the value of the Extensions field. Returns an empty extensions map if not set.
func (t *Tag) GetExtensions() *extensions.Extensions {
if t == nil || t.Extensions == nil {
return extensions.New()
}
return t.Extensions
}
// Validate validates the Tag object against the Swagger Specification.
func (t *Tag) Validate(ctx context.Context, opts ...validation.Option) []error {
c := t.GetCore()
errs := []error{}
if c.Name.Present && t.Name == "" {
errs = append(errs, validation.NewValueError(validation.SeverityError, validation.RuleValidationRequiredField, errors.New("`tag.name` is required"), c, c.Name))
}
if c.ExternalDocs.Present {
errs = append(errs, t.ExternalDocs.Validate(ctx, opts...)...)
}
t.Valid = len(errs) == 0 && c.GetValid()
return errs
}