forked from chanced/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
60 lines (51 loc) · 1.42 KB
/
tag.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
50
51
52
53
54
55
56
57
58
59
60
package openapi
import (
"encoding/json"
"github.com/chanced/openapi/yamlutil"
)
// Tag adds metadata that is used by the Operation Object.
//
// It is not mandatory to have a Tag Object per tag defined in the Operation
// Object instances.
type Tag struct {
// The name of the tag.
//
// *required*
Name string `json:"name" yaml:"name"`
// A description for the tag.
//
// CommonMark syntax MAY be used for rich text representation.
//
// https://spec.commonmark.org/
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// Additional external documentation for this tag.
ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" bson:"externalDocs,omitempty"`
Extensions `json:"-"`
}
type tag Tag
// MarshalJSON marshals t into JSON
func (t Tag) MarshalJSON() ([]byte, error) {
return marshalExtendedJSON(tag(t))
}
// UnmarshalJSON unmarshals json into t
func (t *Tag) UnmarshalJSON(data []byte) error {
v := tag{}
err := unmarshalExtendedJSON(data, &v)
*t = Tag(v)
return err
}
// MarshalYAML first marshals and unmarshals into JSON and then marshals into
// YAML
func (t Tag) MarshalYAML() (interface{}, error) {
b, err := json.Marshal(t)
if err != nil {
return nil, err
}
var v interface{}
err = json.Unmarshal(b, &v)
return v, err
}
// UnmarshalYAML unmarshals yaml into t
func (t *Tag) UnmarshalYAML(unmarshal func(interface{}) error) error {
return yamlutil.Unmarshal(unmarshal, t)
}