MCPcopy
hub / github.com/danielgtaylor/huma / validateDiscriminator

Function validateDiscriminator

validate.go:337–374  ·  view source on GitHub ↗
(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any, res *ValidateResult)

Source from the content-addressed store, hash-verified

335}
336
337func 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

Callers 1

ValidateFunction · 0.85

Calls 5

validateOneOfFunction · 0.85
ValidateFunction · 0.85
PushMethod · 0.80
AddMethod · 0.65
SchemaFromRefMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…