| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
type SecurityScheme struct { |
| 30 |
spec.Refable |
| 31 |
SecuritySchemeProps |
| 32 |
spec.VendorExtensible |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
func (s *SecurityScheme) MarshalJSON() ([]byte, error) { |
| 37 |
if internal.UseOptimizedJSONMarshalingV3 { |
| 38 |
return internal.DeterministicMarshal(s) |
| 39 |
} |
| 40 |
b1, err := json.Marshal(s.SecuritySchemeProps) |
| 41 |
if err != nil { |
| 42 |
return nil, err |
| 43 |
} |
| 44 |
b2, err := json.Marshal(s.VendorExtensible) |
| 45 |
if err != nil { |
| 46 |
return nil, err |
| 47 |
} |
| 48 |
b3, err := json.Marshal(s.Refable) |
| 49 |
if err != nil { |
| 50 |
return nil, err |
| 51 |
} |
| 52 |
return swag.ConcatJSON(b1, b2, b3), nil |
| 53 |
} |
| 54 |
|
| 55 |
func (s *SecurityScheme) MarshalNextJSON(opts jsonv2.MarshalOptions, enc *jsonv2.Encoder) error { |
| 56 |
var x struct { |
| 57 |
Ref string `json:"$ref,omitempty"` |
| 58 |
SecuritySchemeProps `json:",inline"` |
| 59 |
spec.Extensions |
| 60 |
} |
| 61 |
x.Ref = s.Refable.Ref.String() |
| 62 |
x.Extensions = internal.SanitizeExtensions(s.Extensions) |
| 63 |
x.SecuritySchemeProps = s.SecuritySchemeProps |
| 64 |
return opts.MarshalNext(enc, x) |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
func (s *SecurityScheme) UnmarshalJSON(data []byte) error { |
| 69 |
if err := json.Unmarshal(data, &s.SecuritySchemeProps); err != nil { |
| 70 |
return err |
| 71 |
} |
| 72 |
if err := json.Unmarshal(data, &s.VendorExtensible); err != nil { |
| 73 |
return err |
| 74 |
} |
| 75 |
return json.Unmarshal(data, &s.Refable) |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
type SecuritySchemeProps struct { |
| 80 |
|
| 81 |
Type string `json:"type,omitempty"` |
| 82 |
|
| 83 |
Description string `json:"description,omitempty"` |
| 84 |
|
| 85 |
Name string `json:"name,omitempty"` |
| 86 |
|
| 87 |
In string `json:"in,omitempty"` |
| 88 |
|
| 89 |
Scheme string `json:"scheme,omitempty"` |
| 90 |
|
| 91 |
BearerFormat string `json:"bearerFormat,omitempty"` |
| 92 |
|
| 93 |
Flows map[string]*OAuthFlow `json:"flows,omitempty"` |
| 94 |
|
| 95 |
OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"` |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
type OAuthFlow struct { |
| 100 |
OAuthFlowProps |
| 101 |
spec.VendorExtensible |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
func (o *OAuthFlow) MarshalJSON() ([]byte, error) { |
| 106 |
b1, err := json.Marshal(o.OAuthFlowProps) |
| 107 |
if err != nil { |
| 108 |
return nil, err |
| 109 |
} |
| 110 |
b2, err := json.Marshal(o.VendorExtensible) |
| 111 |
if err != nil { |
| 112 |
return nil, err |
| 113 |
} |
| 114 |
return swag.ConcatJSON(b1, b2), nil |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
func (o *OAuthFlow) UnmarshalJSON(data []byte) error { |
| 119 |
if err := json.Unmarshal(data, &o.OAuthFlowProps); err != nil { |
| 120 |
return err |
| 121 |
} |
| 122 |
return json.Unmarshal(data, &o.VendorExtensible) |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
type OAuthFlowProps struct { |
| 127 |
|
| 128 |
AuthorizationUrl string `json:"authorizationUrl,omitempty"` |
| 129 |
|
| 130 |
TokenUrl string `json:"tokenUrl,omitempty"` |
| 131 |
|
| 132 |
RefreshUrl string `json:"refreshUrl,omitempty"` |
| 133 |
|
| 134 |
Scopes map[string]string `json:"scopes,omitempty"` |
| 135 |
} |