...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package spec
16
17 import (
18 "encoding/json"
19
20 "github.com/go-openapi/jsonpointer"
21 "github.com/go-openapi/swag"
22 )
23
24
25 type TagProps struct {
26 Description string `json:"description,omitempty"`
27 Name string `json:"name,omitempty"`
28 ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
29 }
30
31
32 func NewTag(name, description string, externalDocs *ExternalDocumentation) Tag {
33 return Tag{TagProps: TagProps{Description: description, Name: name, ExternalDocs: externalDocs}}
34 }
35
36
37
38
39
40
41 type Tag struct {
42 VendorExtensible
43 TagProps
44 }
45
46
47 func (t Tag) JSONLookup(token string) (interface{}, error) {
48 if ex, ok := t.Extensions[token]; ok {
49 return &ex, nil
50 }
51
52 r, _, err := jsonpointer.GetForToken(t.TagProps, token)
53 return r, err
54 }
55
56
57 func (t Tag) MarshalJSON() ([]byte, error) {
58 b1, err := json.Marshal(t.TagProps)
59 if err != nil {
60 return nil, err
61 }
62 b2, err := json.Marshal(t.VendorExtensible)
63 if err != nil {
64 return nil, err
65 }
66 return swag.ConcatJSON(b1, b2), nil
67 }
68
69
70 func (t *Tag) UnmarshalJSON(data []byte) error {
71 if err := json.Unmarshal(data, &t.TagProps); err != nil {
72 return err
73 }
74 return json.Unmarshal(data, &t.VendorExtensible)
75 }
76
View as plain text