-
Notifications
You must be signed in to change notification settings - Fork 2
/
crdv1_type_translator.go
141 lines (111 loc) · 4.35 KB
/
crdv1_type_translator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* SPDX-FileCopyrightText: The terraform-provider-k8s Authors
* SPDX-License-Identifier: 0BSD
*/
package generator
import apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
var _ typeTranslator = (*crd1TypeTranslator)(nil)
type crd1TypeTranslator struct {
property *apiextensionsv1.JSONSchemaProps
}
func (t *crd1TypeTranslator) hasNoType() bool {
return t.property.Type == ""
}
func (t *crd1TypeTranslator) isIntOrString() bool {
return t.property.XIntOrString || t.property.Type == "string" && t.property.Format == "int-or-string"
}
func (t *crd1TypeTranslator) isBoolean() bool {
return t.property.Type == "boolean"
}
func (t *crd1TypeTranslator) isString() bool {
return t.property.Type == "string"
}
func (t *crd1TypeTranslator) isInteger() bool {
return t.property.Type == "integer"
}
func (t *crd1TypeTranslator) isNumber() bool {
return t.property.Type == "number"
}
func (t *crd1TypeTranslator) isFloat() bool {
return t.property.Format == "float" || t.property.Format == "double"
}
func (t *crd1TypeTranslator) isArray() bool {
return t.property.Type == "array"
}
func (t *crd1TypeTranslator) isObject() bool {
return t.property.Type == "object"
}
func (t *crd1TypeTranslator) hasUnknownFields() bool {
return t.property.XPreserveUnknownFields != nil && *t.property.XPreserveUnknownFields
}
func (t *crd1TypeTranslator) hasProperties() bool {
return len(t.property.Properties) > 0
}
func (t *crd1TypeTranslator) hasOneOf() bool {
return len(t.property.OneOf) > 0
}
func (t *crd1TypeTranslator) isOneOfArray() bool {
for _, oneOf := range t.property.OneOf {
if oneOf.Type == "array" {
return true
}
}
return false
}
func (t *crd1TypeTranslator) isOneOfBoolean() bool {
for _, oneOf := range t.property.OneOf {
if oneOf.Type == "boolean" {
return true
}
}
return false
}
func (t *crd1TypeTranslator) isObjectWithAdditionalStringProperties() bool {
return t.property.Type == "object" &&
t.property.AdditionalProperties != nil &&
t.property.AdditionalProperties.Schema.Type == "string"
}
func (t *crd1TypeTranslator) isObjectWithAdditionalObjectProperties() bool {
return t.property.Type == "object" &&
t.property.AdditionalProperties != nil &&
t.property.AdditionalProperties.Schema.Type == "object"
}
func (t *crd1TypeTranslator) isObjectWithAdditionalArrayProperties() bool {
return t.property.Type == "object" &&
t.property.AdditionalProperties != nil &&
t.property.AdditionalProperties.Schema.Type == "array"
}
func (t *crd1TypeTranslator) isArrayWithObjectItems() bool {
return t.property.Type == "array" &&
t.property.Items != nil &&
t.property.Items.Schema.Type == "object"
}
func (t *crd1TypeTranslator) additionalPropertiesHaveStringItems() bool {
return t.property.AdditionalProperties.Schema.Items != nil &&
t.property.AdditionalProperties.Schema.Items.Schema.Type == "string"
}
func (t *crd1TypeTranslator) additionalPropertiesHaveProperties() bool {
return len(t.property.AdditionalProperties.Schema.Properties) > 0
}
func (t *crd1TypeTranslator) additionalPropertiesHaveUnknownFields() bool {
return t.property.AdditionalProperties.Schema.XPreserveUnknownFields != nil && *t.property.AdditionalProperties.Schema.XPreserveUnknownFields
}
func (t *crd1TypeTranslator) additionalPropertiesHaveAdditionalStringProperties() bool {
return t.property.AdditionalProperties.Schema.AdditionalProperties != nil &&
t.property.AdditionalProperties.Schema.AdditionalProperties.Schema.Type == "string"
}
func (t *crd1TypeTranslator) additionalPropertiesHaveAdditionalArrayProperties() bool {
return t.property.AdditionalProperties.Schema.AdditionalProperties != nil &&
t.property.AdditionalProperties.Schema.AdditionalProperties.Schema.Type == "array"
}
func (t *crd1TypeTranslator) additionalPropertiesHaveAdditionalPropertiesWithStringItems() bool {
return t.property.AdditionalProperties.Schema.AdditionalProperties.Schema.Items != nil &&
t.property.AdditionalProperties.Schema.AdditionalProperties.Schema.Items.Schema.Type == "string"
}
func (t *crd1TypeTranslator) itemsHaveUnknownFields() bool {
return t.property.Items.Schema.XPreserveUnknownFields != nil && *t.property.Items.Schema.XPreserveUnknownFields
}
func (t *crd1TypeTranslator) itemsHaveAdditionalStringProperties() bool {
return t.property.Items.Schema.AdditionalProperties != nil &&
t.property.Items.Schema.AdditionalProperties.Schema.Type == "string"
}