Skip to content

Commit 9ccdda5

Browse files
author
jennybuckley
committed
Remove untyped schema
1 parent bc83cfb commit 9ccdda5

File tree

6 files changed

+112
-39
lines changed

6 files changed

+112
-39
lines changed

schema/elements.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -177,41 +177,6 @@ type Map struct {
177177
ElementRelationship ElementRelationship `yaml:"elementRelationship,omitempty"`
178178
}
179179

180-
// UntypedAtomic implies that all elements depend on each other, and this
181-
// is effectively a scalar / leaf field; it doesn't make sense for
182-
// separate actors to set the elements.
183-
var UntypedAtomic string = "__untyped_atomic_"
184-
185-
// UntypedDeduced implies that the behavior is based on the type of data.
186-
// Structs and maps are both treated as a `separable` Map with UntypedDeduced elements.
187-
// Lists and Scalars are both treated as an UntypedAtomic.
188-
var UntypedDeduced string = "__untyped_deduced_"
189-
190-
// UntypedYAML can be added to a schema to allow it to reference basic Untyped types
191-
// which represent types that allow arbitrary content. (Think: plugin objects.)
192-
var UntypedYAML string = `types:
193-
- name: __untyped_atomic_
194-
scalar: untyped
195-
list:
196-
elementType:
197-
namedType: __untyped_atomic_
198-
elementRelationship: atomic
199-
map:
200-
elementType:
201-
namedType: __untyped_atomic_
202-
elementRelationship: atomic
203-
- name: __untyped_deduced_
204-
scalar: untyped
205-
list:
206-
elementType:
207-
namedType: __untyped_atomic_
208-
elementRelationship: atomic
209-
map:
210-
elementType:
211-
namedType: __untyped_deduced_
212-
elementRelationship: separable
213-
`
214-
215180
// FindNamedType is a convenience function that returns the referenced TypeDef,
216181
// if it exists, or (nil, false) if it doesn't.
217182
func (s Schema) FindNamedType(name string) (TypeDef, bool) {

typed/merge_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ var mergeCases = []mergeTestCase{{
5050
- name: value
5151
type:
5252
namedType: __untyped_atomic_
53+
- name: __untyped_atomic_
54+
scalar: untyped
55+
list:
56+
elementType:
57+
namedType: __untyped_atomic_
58+
elementRelationship: atomic
59+
map:
60+
elementType:
61+
namedType: __untyped_atomic_
62+
elementRelationship: atomic
5363
`,
5464
triplets: []mergeTriplet{{
5565
`{"key":"foo","value":{}}`,
@@ -84,6 +94,16 @@ var mergeCases = []mergeTestCase{{
8494
map:
8595
elementType:
8696
namedType: __untyped_atomic_
97+
- name: __untyped_atomic_
98+
scalar: untyped
99+
list:
100+
elementType:
101+
namedType: __untyped_atomic_
102+
elementRelationship: atomic
103+
map:
104+
elementType:
105+
namedType: __untyped_atomic_
106+
elementRelationship: atomic
87107
`,
88108
triplets: []mergeTriplet{{
89109
`{}`,
@@ -120,6 +140,16 @@ var mergeCases = []mergeTestCase{{
120140
- name: value
121141
type:
122142
namedType: __untyped_atomic_
143+
- name: __untyped_atomic_
144+
scalar: untyped
145+
list:
146+
elementType:
147+
namedType: __untyped_atomic_
148+
elementRelationship: atomic
149+
map:
150+
elementType:
151+
namedType: __untyped_atomic_
152+
elementRelationship: atomic
123153
`,
124154
triplets: []mergeTriplet{{
125155
`{}`,
@@ -155,6 +185,16 @@ var mergeCases = []mergeTestCase{{
155185
elementType:
156186
namedType: __untyped_atomic_
157187
elementRelationship: atomic
188+
- name: __untyped_atomic_
189+
scalar: untyped
190+
list:
191+
elementType:
192+
namedType: __untyped_atomic_
193+
elementRelationship: atomic
194+
map:
195+
elementType:
196+
namedType: __untyped_atomic_
197+
elementRelationship: atomic
158198
`,
159199
triplets: []mergeTriplet{{
160200
`{}`,

typed/parser.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ func createOrDie(schema YAMLObject) *Parser {
4949

5050
var ssParser = createOrDie(YAMLObject(schema.SchemaSchemaYAML))
5151

52-
var untypedSchema = createOrDie(YAMLObject(schema.UntypedYAML)).Schema
53-
5452
// NewParser will build a YAMLParser from a schema. The schema is validated.
5553
func NewParser(schema YAMLObject) (*Parser, error) {
5654
_, err := ssParser.Type("schema").FromYAML(schema)
@@ -61,7 +59,6 @@ func NewParser(schema YAMLObject) (*Parser, error) {
6159
if err != nil {
6260
return nil, err
6361
}
64-
p.Schema.Types = append(p.Schema.Types, untypedSchema.Types...)
6562
return p, nil
6663
}
6764

@@ -116,4 +113,25 @@ func (p ParseableType) FromUnstructured(in interface{}) (*TypedValue, error) {
116113

117114
// DeducedParseableType is a ParseableType that deduces the type from
118115
// the content of the object.
119-
var DeducedParseableType ParseableType = (&Parser{Schema: untypedSchema}).Type(schema.UntypedDeduced)
116+
var DeducedParseableType ParseableType = createOrDie(YAMLObject(`types:
117+
- name: __untyped_atomic_
118+
scalar: untyped
119+
list:
120+
elementType:
121+
namedType: __untyped_atomic_
122+
elementRelationship: atomic
123+
map:
124+
elementType:
125+
namedType: __untyped_atomic_
126+
elementRelationship: atomic
127+
- name: __untyped_deduced_
128+
scalar: untyped
129+
list:
130+
elementType:
131+
namedType: __untyped_atomic_
132+
elementRelationship: atomic
133+
map:
134+
elementType:
135+
namedType: __untyped_deduced_
136+
elementRelationship: separable
137+
`)).Type("__untyped_deduced_")

typed/symdiff_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ var symdiffCases = []symdiffTestCase{{
5656
- name: value
5757
type:
5858
namedType: __untyped_atomic_
59+
- name: __untyped_atomic_
60+
scalar: untyped
61+
list:
62+
elementType:
63+
namedType: __untyped_atomic_
64+
elementRelationship: atomic
65+
map:
66+
elementType:
67+
namedType: __untyped_atomic_
68+
elementRelationship: atomic
5969
`,
6070
quints: []symdiffQuint{{
6171
lhs: `{"key":"foo","value":1}`,
@@ -112,6 +122,16 @@ var symdiffCases = []symdiffTestCase{{
112122
map:
113123
elementType:
114124
namedType: __untyped_atomic_
125+
- name: __untyped_atomic_
126+
scalar: untyped
127+
list:
128+
elementType:
129+
namedType: __untyped_atomic_
130+
elementRelationship: atomic
131+
map:
132+
elementType:
133+
namedType: __untyped_atomic_
134+
elementRelationship: atomic
115135
`,
116136
quints: []symdiffQuint{{
117137
lhs: `{}`,
@@ -203,6 +223,16 @@ var symdiffCases = []symdiffTestCase{{
203223
elementType:
204224
namedType: __untyped_atomic_
205225
elementRelationship: atomic
226+
- name: __untyped_atomic_
227+
scalar: untyped
228+
list:
229+
elementType:
230+
namedType: __untyped_atomic_
231+
elementRelationship: atomic
232+
map:
233+
elementType:
234+
namedType: __untyped_atomic_
235+
elementRelationship: atomic
206236
`,
207237
quints: []symdiffQuint{{
208238
lhs: `{}`,

typed/toset_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ var fieldsetCases = []fieldsetTestCase{{
6161
- name: value
6262
type:
6363
namedType: __untyped_atomic_
64+
- name: __untyped_atomic_
65+
scalar: untyped
66+
list:
67+
elementType:
68+
namedType: __untyped_atomic_
69+
elementRelationship: atomic
70+
map:
71+
elementType:
72+
namedType: __untyped_atomic_
73+
elementRelationship: atomic
6474
`,
6575
pairs: []objSetPair{
6676
{`{"key":"foo","value":1}`, _NS(_P("key"), _P("value"))},

typed/validate_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ var validationCases = []validationTestCase{{
4545
- name: value
4646
type:
4747
namedType: __untyped_atomic_
48+
- name: __untyped_atomic_
49+
scalar: untyped
50+
list:
51+
elementType:
52+
namedType: __untyped_atomic_
53+
elementRelationship: atomic
54+
map:
55+
elementType:
56+
namedType: __untyped_atomic_
57+
elementRelationship: atomic
4858
`,
4959
validObjects: []typed.YAMLObject{
5060
`{"key":"foo","value":1}`,

0 commit comments

Comments
 (0)