typeMatches reports whether a decoded JSON value has one of a schema's types.
(s *openapi3.Schema, v any)
| 389 | |
| 390 | // typeMatches reports whether a decoded JSON value has one of a schema's types. |
| 391 | func typeMatches(s *openapi3.Schema, v any) bool { |
| 392 | types := s.Type.Slice() |
| 393 | if len(types) == 0 { |
| 394 | return !isObjectSchema(s) || isMap(v) |
| 395 | } |
| 396 | for _, t := range types { |
| 397 | switch t { |
| 398 | case "object": |
| 399 | if isMap(v) { |
| 400 | return true |
| 401 | } |
| 402 | case "array": |
| 403 | if _, ok := v.([]any); ok { |
| 404 | return true |
| 405 | } |
| 406 | case "string": |
| 407 | if _, ok := v.(string); ok { |
| 408 | return true |
| 409 | } |
| 410 | case "integer": |
| 411 | if n, ok := v.(float64); ok && n == math.Trunc(n) { |
| 412 | return true |
| 413 | } |
| 414 | case "number": |
| 415 | if _, ok := v.(float64); ok { |
| 416 | return true |
| 417 | } |
| 418 | case "boolean": |
| 419 | if _, ok := v.(bool); ok { |
| 420 | return true |
| 421 | } |
| 422 | case "null": |
| 423 | if v == nil { |
| 424 | return true |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | return false |
| 429 | } |
| 430 | |
| 431 | func isMap(v any) bool { |
| 432 | _, ok := v.(map[string]any) |
no test coverage detected