@@ -48,9 +48,6 @@ type TypeRef struct {
48
48
type Atom struct {
49
49
* Scalar `yaml:"scalar,omitempty"`
50
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
51
* Map `yaml:"map,omitempty"`
55
52
}
56
53
@@ -67,23 +64,35 @@ const (
67
64
)
68
65
69
66
// ElementRelationship is an enum of the different possible relationships
70
- // between the elements of container types (maps, lists, structs ).
67
+ // between the elements of container types (maps, lists).
71
68
type ElementRelationship string
72
69
73
70
const (
74
71
// Associative only applies to lists (see the documentation there).
75
72
Associative = ElementRelationship ("associative" )
76
- // Atomic makes container types (lists, maps, structs ) behave
73
+ // Atomic makes container types (lists, maps) behave
77
74
// as scalars / leaf fields
78
75
Atomic = ElementRelationship ("atomic" )
79
76
// Separable means the items of the container type have no particular
80
- // relationship (default behavior for maps and structs ).
77
+ // relationship (default behavior for maps).
81
78
Separable = ElementRelationship ("separable" )
82
79
)
83
80
84
- // Struct represents a type which is composed of a number of different fields.
81
+ // Map is a key-value pair. Its default semantics are the same as an
82
+ // associative list, but:
83
+ // * It is serialized differently:
84
+ // map: {"k": {"value": "v"}}
85
+ // list: [{"key": "k", "value": "v"}]
86
+ // * Keys must be string typed.
87
+ // * Keys can't have multiple components.
88
+ //
89
+ // Optionally, maps may be atomic (for example, imagine representing an RGB
90
+ // color value--it doesn't make sense to have different actors own the R and G
91
+ // values).
92
+ //
93
+ // Maps may also represent a type which is composed of a number of different fields.
85
94
// Each field has a name and a type.
86
- type Struct struct {
95
+ type Map struct {
87
96
// Each struct field appears exactly once in this list. The order in
88
97
// this list defines the canonical field ordering.
89
98
Fields []StructField `yaml:"fields,omitempty"`
@@ -95,14 +104,17 @@ type Struct struct {
95
104
// overlap between unions.
96
105
Unions []Union `yaml:"unions,omitempty"`
97
106
98
- // ElementRelationship states the relationship between the struct's items.
107
+ // ElementType is the type of the structs's unknown fields.
108
+ ElementType TypeRef `yaml:"elementType,omitempty"`
109
+
110
+ // ElementRelationship states the relationship between the map's items.
99
111
// * `separable` (or unset) implies that each element is 100% independent.
100
112
// * `atomic` implies that all elements depend on each other, and this
101
113
// is effectively a scalar / leaf field; it doesn't make sense for
102
114
// separate actors to set the elements. Example: an RGB color struct;
103
115
// it would never make sense to "own" only one component of the
104
116
// color.
105
- // The default behavior for structs is `separable`; it's permitted to
117
+ // The default behavior for maps is `separable`; it's permitted to
106
118
// leave this unset to get the default behavior.
107
119
ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
108
120
}
@@ -169,15 +181,14 @@ type List struct {
169
181
// * `atomic`: the list is treated as a single entity, like a scalar.
170
182
// * `associative`:
171
183
// - If the list element is a scalar, the list is treated as a set.
172
- // - If the list element is a struct, the list is treated as a map.
173
- // - The list element must not be a map or a list itself.
184
+ // - If the list element is a map, the list is treated as a map.
174
185
// There is no default for this value for lists; all schemas must
175
186
// explicitly state the element relationship for all lists.
176
187
ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
177
188
178
189
// Iff ElementRelationship is `associative`, and the element type is
179
- // struct , then Keys must have non-zero length, and it lists the fields
180
- // of the element's struct type which are to be used as the keys of the
190
+ // map , then Keys must have non-zero length, and it lists the fields
191
+ // of the element's map type which are to be used as the keys of the
181
192
// list.
182
193
//
183
194
// TODO: change this to "non-atomic struct" above and make the code reflect this.
@@ -186,35 +197,6 @@ type List struct {
186
197
Keys []string `yaml:"keys,omitempty"`
187
198
}
188
199
189
- // Map is a key-value pair. Its default semantics are the same as an
190
- // associative list, but:
191
- // * It is serialized differently:
192
- // map: {"k": {"value": "v"}}
193
- // list: [{"key": "k", "value": "v"}]
194
- // * Keys must be string typed.
195
- // * Keys can't have multiple components.
196
- //
197
- // Although serialized the same, maps are different from structs in that each
198
- // map item must have the same type.
199
- //
200
- // Optionally, maps may be atomic (for example, imagine representing an RGB
201
- // color value--it doesn't make sense to have different actors own the R and G
202
- // values).
203
- type Map struct {
204
- // ElementType is the type of the list's elements.
205
- ElementType TypeRef `yaml:"elementType,omitempty"`
206
-
207
- // ElementRelationship states the relationship between the map's items.
208
- // * `separable` implies that each element is 100% independent.
209
- // * `atomic` implies that all elements depend on each other, and this
210
- // is effectively a scalar / leaf field; it doesn't make sense for
211
- // separate actors to set the elements.
212
- // TODO: find a simple example.
213
- // The default behavior for maps is `separable`; it's permitted to
214
- // leave this unset to get the default behavior.
215
- ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
216
- }
217
-
218
200
// FindNamedType is a convenience function that returns the referenced TypeDef,
219
201
// if it exists, or (nil, false) if it doesn't.
220
202
func (s Schema ) FindNamedType (name string ) (TypeDef , bool ) {
0 commit comments