...
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 PathItemProps struct {
26 Get *Operation `json:"get,omitempty"`
27 Put *Operation `json:"put,omitempty"`
28 Post *Operation `json:"post,omitempty"`
29 Delete *Operation `json:"delete,omitempty"`
30 Options *Operation `json:"options,omitempty"`
31 Head *Operation `json:"head,omitempty"`
32 Patch *Operation `json:"patch,omitempty"`
33 Parameters []Parameter `json:"parameters,omitempty"`
34 }
35
36
37
38
39
40
41
42 type PathItem struct {
43 Refable
44 VendorExtensible
45 PathItemProps
46 }
47
48
49 func (p PathItem) JSONLookup(token string) (interface{}, error) {
50 if ex, ok := p.Extensions[token]; ok {
51 return &ex, nil
52 }
53 if token == jsonRef {
54 return &p.Ref, nil
55 }
56 r, _, err := jsonpointer.GetForToken(p.PathItemProps, token)
57 return r, err
58 }
59
60
61 func (p *PathItem) UnmarshalJSON(data []byte) error {
62 if err := json.Unmarshal(data, &p.Refable); err != nil {
63 return err
64 }
65 if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
66 return err
67 }
68 return json.Unmarshal(data, &p.PathItemProps)
69 }
70
71
72 func (p PathItem) MarshalJSON() ([]byte, error) {
73 b3, err := json.Marshal(p.Refable)
74 if err != nil {
75 return nil, err
76 }
77 b4, err := json.Marshal(p.VendorExtensible)
78 if err != nil {
79 return nil, err
80 }
81 b5, err := json.Marshal(p.PathItemProps)
82 if err != nil {
83 return nil, err
84 }
85 concated := swag.ConcatJSON(b3, b4, b5)
86 return concated, nil
87 }
88
View as plain text