(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any, res *ValidateResult)
| 335 | } |
| 336 | |
| 337 | func validateDiscriminator(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any, res *ValidateResult) { |
| 338 | var kk any |
| 339 | found := true |
| 340 | |
| 341 | if vv, ok := v.(map[string]any); ok { |
| 342 | kk, found = vv[s.Discriminator.PropertyName] |
| 343 | } |
| 344 | |
| 345 | if vv, ok := v.(map[any]any); ok { |
| 346 | kk, found = vv[s.Discriminator.PropertyName] |
| 347 | } |
| 348 | |
| 349 | if !found { |
| 350 | path.Push(s.Discriminator.PropertyName) |
| 351 | res.Add(path, v, validation.MsgExpectedPropertyNameInObject) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | if kk == nil { |
| 356 | // Either `v` is not a map or the property is set to null. Return so that |
| 357 | // type and enum checks on the field can complete elsewhere. |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | key, ok := kk.(string) |
| 362 | if !ok { |
| 363 | path.Push(s.Discriminator.PropertyName) |
| 364 | return |
| 365 | } |
| 366 | |
| 367 | ref, found := s.Discriminator.Mapping[key] |
| 368 | if !found { |
| 369 | validateOneOf(r, s, path, mode, v, res) |
| 370 | return |
| 371 | } |
| 372 | |
| 373 | Validate(r, r.SchemaFromRef(ref), path, mode, v, res) |
| 374 | } |
| 375 | |
| 376 | // Validate an input value against a schema, collecting errors in the validation |
| 377 | // result object. If successful, `res.Errors` will be empty. It is suggested |
no test coverage detected
searching dependent graphs…