Code refactoring for bpa operator
[icn.git] / cmd / bpa-operator / vendor / k8s.io / apiextensions-apiserver / pkg / apis / apiextensions / v1beta1 / conversion.go
1 /*
2 Copyright 2017 The Kubernetes Authors.
3
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
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 */
16
17 package v1beta1
18
19 import (
20         "k8s.io/apimachinery/pkg/conversion"
21         "k8s.io/apimachinery/pkg/runtime"
22         "k8s.io/apimachinery/pkg/util/json"
23
24         "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
25 )
26
27 func addConversionFuncs(scheme *runtime.Scheme) error {
28         // Add non-generated conversion functions
29         err := scheme.AddConversionFuncs(
30                 Convert_apiextensions_JSONSchemaProps_To_v1beta1_JSONSchemaProps,
31                 Convert_apiextensions_JSON_To_v1beta1_JSON,
32                 Convert_v1beta1_JSON_To_apiextensions_JSON,
33         )
34         if err != nil {
35                 return err
36         }
37         return nil
38 }
39
40 func Convert_apiextensions_JSONSchemaProps_To_v1beta1_JSONSchemaProps(in *apiextensions.JSONSchemaProps, out *JSONSchemaProps, s conversion.Scope) error {
41         if err := autoConvert_apiextensions_JSONSchemaProps_To_v1beta1_JSONSchemaProps(in, out, s); err != nil {
42                 return err
43         }
44         if in.Default != nil && *(in.Default) == nil {
45                 out.Default = nil
46         }
47         if in.Example != nil && *(in.Example) == nil {
48                 out.Example = nil
49         }
50         return nil
51 }
52
53 func Convert_apiextensions_JSON_To_v1beta1_JSON(in *apiextensions.JSON, out *JSON, s conversion.Scope) error {
54         raw, err := json.Marshal(*in)
55         if err != nil {
56                 return err
57         }
58         out.Raw = raw
59         return nil
60 }
61
62 func Convert_v1beta1_JSON_To_apiextensions_JSON(in *JSON, out *apiextensions.JSON, s conversion.Scope) error {
63         if in != nil {
64                 var i interface{}
65                 if err := json.Unmarshal(in.Raw, &i); err != nil {
66                         return err
67                 }
68                 *out = i
69         } else {
70                 out = nil
71         }
72         return nil
73 }