1
16
17 package spec3
18
19 import (
20 "encoding/json"
21
22 "github.com/go-openapi/swag"
23 "k8s.io/kube-openapi/pkg/internal"
24 jsonv2 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json"
25 "k8s.io/kube-openapi/pkg/validation/spec"
26 )
27
28
29
30
31 type Parameter struct {
32 spec.Refable
33 ParameterProps
34 spec.VendorExtensible
35 }
36
37
38 func (p *Parameter) MarshalJSON() ([]byte, error) {
39 if internal.UseOptimizedJSONMarshalingV3 {
40 return internal.DeterministicMarshal(p)
41 }
42 b1, err := json.Marshal(p.Refable)
43 if err != nil {
44 return nil, err
45 }
46 b2, err := json.Marshal(p.ParameterProps)
47 if err != nil {
48 return nil, err
49 }
50 b3, err := json.Marshal(p.VendorExtensible)
51 if err != nil {
52 return nil, err
53 }
54 return swag.ConcatJSON(b1, b2, b3), nil
55 }
56
57 func (p *Parameter) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error {
58 var x struct {
59 Ref string `json:"$ref,omitempty"`
60 ParameterProps parameterPropsOmitZero `json:",inline"`
61 spec.Extensions
62 }
63 x.Ref = p.Refable.Ref.String()
64 x.Extensions = internal.SanitizeExtensions(p.Extensions)
65 x.ParameterProps = parameterPropsOmitZero(p.ParameterProps)
66 return opts.MarshalNext(enc, x)
67 }
68
69 func (p *Parameter) UnmarshalJSON(data []byte) error {
70 if internal.UseOptimizedJSONUnmarshalingV3 {
71 return jsonv2.Unmarshal(data, p)
72 }
73
74 if err := json.Unmarshal(data, &p.Refable); err != nil {
75 return err
76 }
77 if err := json.Unmarshal(data, &p.ParameterProps); err != nil {
78 return err
79 }
80 if err := json.Unmarshal(data, &p.VendorExtensible); err != nil {
81 return err
82 }
83
84 return nil
85 }
86
87 func (p *Parameter) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error {
88 var x struct {
89 spec.Extensions
90 ParameterProps
91 }
92 if err := opts.UnmarshalNext(dec, &x); err != nil {
93 return err
94 }
95 if err := internal.JSONRefFromMap(&p.Ref.Ref, x.Extensions); err != nil {
96 return err
97 }
98 p.Extensions = internal.SanitizeExtensions(x.Extensions)
99 p.ParameterProps = x.ParameterProps
100 return nil
101 }
102
103
104 type ParameterProps struct {
105
106 Name string `json:"name,omitempty"`
107
108 In string `json:"in,omitempty"`
109
110 Description string `json:"description,omitempty"`
111
112 Required bool `json:"required,omitempty"`
113
114 Deprecated bool `json:"deprecated,omitempty"`
115
116 AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
117
118 Style string `json:"style,omitempty"`
119
120 Explode bool `json:"explode,omitempty"`
121
122 AllowReserved bool `json:"allowReserved,omitempty"`
123
124 Schema *spec.Schema `json:"schema,omitempty"`
125
126 Content map[string]*MediaType `json:"content,omitempty"`
127
128 Example interface{} `json:"example,omitempty"`
129
130 Examples map[string]*Example `json:"examples,omitempty"`
131 }
132
133 type parameterPropsOmitZero struct {
134 Name string `json:"name,omitempty"`
135 In string `json:"in,omitempty"`
136 Description string `json:"description,omitempty"`
137 Required bool `json:"required,omitzero"`
138 Deprecated bool `json:"deprecated,omitzero"`
139 AllowEmptyValue bool `json:"allowEmptyValue,omitzero"`
140 Style string `json:"style,omitempty"`
141 Explode bool `json:"explode,omitzero"`
142 AllowReserved bool `json:"allowReserved,omitzero"`
143 Schema *spec.Schema `json:"schema,omitzero"`
144 Content map[string]*MediaType `json:"content,omitempty"`
145 Example interface{} `json:"example,omitempty"`
146 Examples map[string]*Example `json:"examples,omitempty"`
147 }
148
View as plain text