2 Copyright 2017 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 "k8s.io/apimachinery/pkg/util/json"
25 var jsTrue = []byte("true")
26 var jsFalse = []byte("false")
28 func (s JSONSchemaPropsOrBool) MarshalJSON() ([]byte, error) {
30 return json.Marshal(s.Schema)
33 if s.Schema == nil && !s.Allows {
39 func (s *JSONSchemaPropsOrBool) UnmarshalJSON(data []byte) error {
40 var nw JSONSchemaPropsOrBool
44 var sch JSONSchemaProps
45 if err := json.Unmarshal(data, &sch); err != nil {
50 case len(data) == 4 && string(data) == "true":
52 case len(data) == 5 && string(data) == "false":
55 return errors.New("boolean or JSON schema expected")
61 func (s JSONSchemaPropsOrStringArray) MarshalJSON() ([]byte, error) {
62 if len(s.Property) > 0 {
63 return json.Marshal(s.Property)
66 return json.Marshal(s.Schema)
68 return []byte("null"), nil
71 func (s *JSONSchemaPropsOrStringArray) UnmarshalJSON(data []byte) error {
76 var nw JSONSchemaPropsOrStringArray
78 var sch JSONSchemaProps
79 if err := json.Unmarshal(data, &sch); err != nil {
85 if err := json.Unmarshal(data, &nw.Property); err != nil {
93 func (s JSONSchemaPropsOrArray) MarshalJSON() ([]byte, error) {
94 if len(s.JSONSchemas) > 0 {
95 return json.Marshal(s.JSONSchemas)
97 return json.Marshal(s.Schema)
100 func (s *JSONSchemaPropsOrArray) UnmarshalJSON(data []byte) error {
101 var nw JSONSchemaPropsOrArray
107 var sch JSONSchemaProps
108 if err := json.Unmarshal(data, &sch); err != nil {
114 if err := json.Unmarshal(data, &nw.JSONSchemas); err != nil {
122 func (s JSON) MarshalJSON() ([]byte, error) {
126 return []byte("null"), nil
130 func (s *JSON) UnmarshalJSON(data []byte) error {
131 if len(data) > 0 && string(data) != "null" {