@@ -16,8 +16,6 @@ limitations under the License.
16
16
17
17
package schema
18
18
19
- import "sigs.k8s.io/structured-merge-diff/value"
20
-
21
19
// Schema is a list of named types.
22
20
type Schema struct {
23
21
Types []TypeDef `yaml:"types,omitempty"`
@@ -45,13 +43,15 @@ type TypeRef struct {
45
43
}
46
44
47
45
// Atom represents the smallest possible pieces of the type system.
46
+ // Each set field in the Atom represents a possible type for the object.
47
+ // If none of the fields are set, any object will fail validation against the atom.
48
48
type Atom struct {
49
- // Exactly one of the below must be set.
50
- * Scalar `yaml:"scalar ,omitempty"`
51
- * Struct `yaml:"struct,omitempty"`
52
- * List `yaml:"list,omitempty"`
53
- * Map `yaml:"map ,omitempty"`
54
- * Untyped `yaml:"untyped ,omitempty"`
49
+ * Scalar `yaml:"scalar,omitempty"`
50
+ * List `yaml:"list ,omitempty"`
51
+
52
+ // At most, one of the below must be set, since both look the same when serialized
53
+ * Struct `yaml:"struct ,omitempty"`
54
+ * Map `yaml:"map ,omitempty"`
55
55
}
56
56
57
57
// Scalar (AKA "primitive") represents a type which has a single value which is
@@ -67,20 +67,18 @@ const (
67
67
)
68
68
69
69
// ElementRelationship is an enum of the different possible relationships
70
- // between the elements of container types (maps, lists, structs, untyped ).
70
+ // between the elements of container types (maps, lists, structs).
71
71
type ElementRelationship string
72
72
73
73
const (
74
74
// Associative only applies to lists (see the documentation there).
75
75
Associative = ElementRelationship ("associative" )
76
- // Atomic makes container types (lists, maps, structs, untyped ) behave
77
- // as scalars / leaf fields (which is the default for untyped data).
76
+ // Atomic makes container types (lists, maps, structs) behave
77
+ // as scalars / leaf fields
78
78
Atomic = ElementRelationship ("atomic" )
79
79
// Separable means the items of the container type have no particular
80
80
// relationship (default behavior for maps and structs).
81
81
Separable = ElementRelationship ("separable" )
82
- // Deduced only applies to untyped (see the documentation there).
83
- Deduced = ElementRelationship ("deduced" )
84
82
)
85
83
86
84
// Struct represents a type which is composed of a number of different fields.
@@ -179,50 +177,6 @@ type Map struct {
179
177
ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
180
178
}
181
179
182
- // Untyped represents types that allow arbitrary content. (Think: plugin
183
- // objects.)
184
- type Untyped struct {
185
- // ElementRelationship states the relationship between the items, if
186
- // container-typed data happens to be present here.
187
- // * `deduced` implies that the behavior is based on the type of data.
188
- // Structs and maps are both treated as a `separable` Map with `deduced` Untyped elements.
189
- // Lists and Scalars are both treated as an `atomic` Untyped.
190
- // * `atomic` implies that all elements depend on each other, and this
191
- // is effectively a scalar / leaf field; it doesn't make sense for
192
- // separate actors to set the elements.
193
- // TODO: support "guess" (guesses at associative list keys)
194
- // The default behavior for untyped data is `atomic`; it's permitted to
195
- // leave this unset to get the default behavior.
196
- ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
197
- }
198
-
199
- // DeduceType determines the behavior based on a value.
200
- func DeduceType (v * value.Value ) TypeRef {
201
- if v != nil && v .MapValue != nil {
202
- return TypeRef {
203
- Inlined : Atom {
204
- Map : & Map {
205
- ElementType : TypeRef {
206
- Inlined : Atom {
207
- Untyped : & Untyped {
208
- ElementRelationship : Deduced ,
209
- },
210
- },
211
- },
212
- ElementRelationship : Separable ,
213
- },
214
- },
215
- }
216
- }
217
- return TypeRef {
218
- Inlined : Atom {
219
- Untyped : & Untyped {
220
- ElementRelationship : Atomic ,
221
- },
222
- },
223
- }
224
- }
225
-
226
180
// FindNamedType is a convenience function that returns the referenced TypeDef,
227
181
// if it exists, or (nil, false) if it doesn't.
228
182
func (s Schema ) FindNamedType (name string ) (TypeDef , bool ) {
0 commit comments