(ref *openapi3.SchemaRef, v any, name string, depth int)
| 123 | } |
| 124 | |
| 125 | func (f *restFiller) fill(ref *openapi3.SchemaRef, v any, name string, depth int) any { |
| 126 | if ref == nil || ref.Value == nil || depth > maxSchemaDepth { |
| 127 | return v |
| 128 | } |
| 129 | s := ref.Value |
| 130 | if v == nil { |
| 131 | if allowsNull(s) { |
| 132 | return nil |
| 133 | } |
| 134 | f.filled++ |
| 135 | return f.generate(ref, name, depth) |
| 136 | } |
| 137 | |
| 138 | for _, sub := range s.AllOf { |
| 139 | v = f.fill(sub, v, name, depth+1) |
| 140 | } |
| 141 | if alts := alternatives(s); len(alts) > 0 { |
| 142 | if matchesSchema(ref, v) { |
| 143 | return v |
| 144 | } |
| 145 | if d := s.Discriminator; d != nil { |
| 146 | if obj, ok := v.(map[string]any); ok { |
| 147 | for _, alt := range alts { |
| 148 | candidate, _ := cloneJSON(obj).(map[string]any) |
| 149 | trial := &restFiller{} |
| 150 | if _, has := candidate[d.PropertyName]; !has { |
| 151 | candidate[d.PropertyName] = discriminatorValue(d, alt) |
| 152 | trial.filled++ |
| 153 | } |
| 154 | filled := trial.fill(alt, candidate, name, depth+1) |
| 155 | if matchesSchema(ref, filled) { |
| 156 | f.filled += trial.filled |
| 157 | return filled |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | for _, alt := range alts { |
| 163 | if alt.Value != nil && typeMatches(alt.Value, v) { |
| 164 | return f.fill(alt, v, name, depth+1) |
| 165 | } |
| 166 | } |
| 167 | f.filled++ |
| 168 | return f.generate(alts[0], name, depth+1) |
| 169 | } |
| 170 | |
| 171 | switch { |
| 172 | case isObjectSchema(s): |
| 173 | obj, ok := v.(map[string]any) |
| 174 | if !ok { |
| 175 | f.filled++ |
| 176 | return f.generate(ref, name, depth) |
| 177 | } |
| 178 | for _, key := range slices.Sorted(maps.Keys(s.Properties)) { |
| 179 | if val, ok := obj[key]; ok { |
| 180 | obj[key] = f.fill(s.Properties[key], val, key, depth+1) |
| 181 | } |
| 182 | } |
no test coverage detected