11package generator
22
33import (
4- "encoding/json"
54 "errors"
65 "fmt"
76 "github.com/brianvoe/gofakeit/v6"
@@ -110,13 +109,6 @@ func (r *resolver) fakeObject(req *Request) (*sortedmap.LinkedHashMap[string, *f
110109 }
111110
112111 for it := s .Properties .Iter (); it .Next (); {
113- if ! slices .Contains (s .Required , it .Key ()) {
114- n := gofakeit .Float32Range (0 , 1 )
115- if n > 0.7 {
116- continue
117- }
118- }
119-
120112 prop := append (req .Path , it .Key ())
121113 ex := propertyFromExample (it .Key (), req )
122114 f , err := r .resolve (req .With (prop , it .Value (), ex ), fallback )
@@ -140,6 +132,16 @@ func (r *resolver) fakeObject(req *Request) (*sortedmap.LinkedHashMap[string, *f
140132 return nil , err
141133 }
142134 }
135+
136+ if ! slices .Contains (s .Required , it .Key ()) {
137+ fakes .Set (it .Key (), newFaker (func () (any , error ) {
138+ n := gofakeit .Float32Range (0 , 1 )
139+ if n > 0.7 {
140+ return nil , nil
141+ }
142+ return f .fake ()
143+ }))
144+ }
143145 fakes .Set (it .Key (), f )
144146 }
145147 return fakes , nil
@@ -389,21 +391,3 @@ func examples(s *schema.Schema) []any {
389391 }
390392 return result
391393}
392-
393- func mergeUnique (a , b []interface {}) []interface {} {
394- seen := make (map [string ]struct {})
395- var result []any
396-
397- for _ , item := range append (a , b ... ) {
398- // simple way to get a unique key
399- keyBytes , _ := json .Marshal (item )
400- key := string (keyBytes )
401-
402- if _ , exists := seen [key ]; ! exists {
403- seen [key ] = struct {}{}
404- result = append (result , item )
405- }
406- }
407-
408- return result
409- }
0 commit comments