@@ -160,7 +160,6 @@ func TestApplyDefaults(t *testing.T) {
160160 t .Fatal (err )
161161 }
162162
163- type S struct { A , B , C int }
164163 for _ , tt := range []struct {
165164 instancep any // pointer to instance value
166165 want any // desired value (not a pointer)
@@ -173,14 +172,6 @@ func TestApplyDefaults(t *testing.T) {
173172 // "C" not added: it is required (Validate will catch that)
174173 },
175174 },
176- {
177- & S {B : 1 },
178- S {
179- A : 1 , // filled from default
180- B : 1 , // untouched: non-zero
181- C : 0 , // untouched: required
182- },
183- },
184175 } {
185176 if err := rs .ApplyDefaults (tt .instancep ); err != nil {
186177 t .Fatal (err )
@@ -218,14 +209,6 @@ func TestApplyNestedDefaults(t *testing.T) {
218209 },
219210 }
220211
221- type Nested struct { B string }
222- type Root struct { A Nested }
223- type RootPtr struct { A * Nested }
224- type RootMap struct { A map [string ]any }
225- type RootPtrMap struct { A * map [string ]any }
226-
227- mapPtr := func (m map [string ]any ) * map [string ]any { return & m }
228-
229212 for _ , tc := range []struct {
230213 name string
231214 schema * Schema
@@ -264,83 +247,6 @@ func TestApplyNestedDefaults(t *testing.T) {
264247 instancep : & map [string ]map [string ]any {},
265248 want : map [string ]map [string ]any {"A" : {"B" : "foo" }},
266249 },
267- {
268- name : "MapValueStructMissingParentTyped" ,
269- schema : base ,
270- instancep : & map [string ]Nested {},
271- want : map [string ]Nested {"A" : {B : "foo" }},
272- },
273- {
274- name : "StructZeroValueParent" ,
275- schema : base ,
276- instancep : & Root {},
277- want : Root {A : Nested {B : "foo" }},
278- },
279- {
280- name : "StructZeroValueParentWithParentDefault" ,
281- schema : withParentDefault ,
282- instancep : & Root {},
283- want : Root {A : Nested {B : "foo" }},
284- },
285- {
286- name : "StructPointerNilParent" ,
287- schema : base ,
288- instancep : & RootPtr {},
289- want : RootPtr {A : & Nested {B : "foo" }},
290- },
291- {
292- name : "StructPresentNonzeroChildPreserved" ,
293- schema : base ,
294- instancep : & Root {A : Nested {B : "bar" }},
295- want : Root {A : Nested {B : "bar" }},
296- },
297- {
298- name : "StructPointerNonNilChildPreserved" ,
299- schema : base ,
300- instancep : & RootPtr {A : & Nested {B : "bar" }},
301- want : RootPtr {A : & Nested {B : "bar" }},
302- },
303- {
304- name : "StructMapNilParent" ,
305- schema : base ,
306- instancep : & RootMap {},
307- want : RootMap {A : map [string ]any {"B" : "foo" }},
308- },
309- {
310- name : "StructMapParentDefaultObjectMissing" ,
311- schema : withParentDefault ,
312- instancep : & RootMap {},
313- want : RootMap {A : map [string ]any {"X" : float64 (1 ), "B" : "foo" }},
314- },
315- {
316- name : "StructMapParentDefaultObjectPresent" ,
317- schema : withParentDefault ,
318- instancep : & RootMap {A : map [string ]any {}},
319- want : RootMap {A : map [string ]any {"B" : "foo" }},
320- },
321- {
322- name : "StructPtrMapNilParent" ,
323- schema : base ,
324- instancep : & RootPtrMap {},
325- want : RootPtrMap {A : mapPtr (map [string ]any {"B" : "foo" })},
326- },
327- {
328- name : "StructMapNilParentWithNullParentDefault" ,
329- schema : & Schema {
330- Type : "object" ,
331- Properties : map [string ]* Schema {
332- "A" : {
333- // Default null exercises map allocation in struct subschemas
334- Default : mustMarshal (nil ),
335- Properties : map [string ]* Schema {
336- "B" : {Type : "string" , Default : mustMarshal ("foo" )},
337- },
338- },
339- },
340- },
341- instancep : & RootMap {},
342- want : RootMap {A : map [string ]any {"B" : "foo" }},
343- },
344250 } {
345251 t .Run (tc .name , func (t * testing.T ) {
346252 rs , err := tc .schema .Resolve (& ResolveOptions {ValidateDefaults : true })
@@ -522,7 +428,8 @@ func TestStructEmbedding(t *testing.T) {
522428 },
523429 Required : []string {"id" , "name" , "extra" },
524430 AdditionalProperties : falseSchema (),
525- }},
431+ },
432+ },
526433 validInstance : []Banana {
527434 {Apple : & Apple {ID : "foo1" , Name : "Test Foo 2" }, Extra : "additional data 1" },
528435 {Apple : & Apple {ID : "foo2" , Name : "Test Foo 2" }, Extra : "additional data 2" },
@@ -544,7 +451,8 @@ func TestStructEmbedding(t *testing.T) {
544451 },
545452 Required : []string {"id" , "name" , "extra" },
546453 AdditionalProperties : falseSchema (),
547- }},
454+ },
455+ },
548456 validInstance : [2 ]Banana {
549457 {Apple : & Apple {ID : "foo1" , Name : "Test Foo 2" }, Extra : "additional data 1" },
550458 {Apple : & Apple {ID : "foo2" , Name : "Test Foo 2" }, Extra : "additional data 2" },
@@ -564,7 +472,8 @@ func TestStructEmbedding(t *testing.T) {
564472 },
565473 Required : []string {"id" , "name" , "extra" },
566474 AdditionalProperties : falseSchema (),
567- }},
475+ },
476+ },
568477 validInstance : []Durian {
569478 {cranberry : & cranberry {ID : "foo1" , Name : "Test Foo 2" }, Extra : "additional data 1" },
570479 {cranberry : & cranberry {ID : "foo2" , Name : "Test Foo 2" }, Extra : "additional data 2" },
@@ -584,7 +493,8 @@ func TestStructEmbedding(t *testing.T) {
584493 },
585494 Required : []string {"id" , "name" , "extra" },
586495 AdditionalProperties : falseSchema (),
587- }},
496+ },
497+ },
588498 validInstance : []Fig {
589499 {Elderberry : Elderberry {ID : "foo1" , Name : "Test Foo 2" }, Extra : "additional data 1" },
590500 {Elderberry : Elderberry {ID : "foo2" , Name : "Test Foo 2" }, Extra : "additional data 2" },
@@ -604,7 +514,8 @@ func TestStructEmbedding(t *testing.T) {
604514 },
605515 Required : []string {"id" , "name" , "extra" },
606516 AdditionalProperties : falseSchema (),
607- }},
517+ },
518+ },
608519 validInstance : []Honeyberry {
609520 {grape : grape {ID : "foo1" , Name : "Test Foo 2" }, Extra : "additional data 1" },
610521 {grape : grape {ID : "foo2" , Name : "Test Foo 2" }, Extra : "additional data 2" },
0 commit comments