(r Registry, fieldName string, s *Schema, value string)
| 515 | } |
| 516 | |
| 517 | func jsonTagValue(r Registry, fieldName string, s *Schema, value string) any { |
| 518 | if s.Ref != "" { |
| 519 | s = r.SchemaFromRef(s.Ref) |
| 520 | if s == nil { |
| 521 | return nil |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // Special case: strings don't need quotes. |
| 526 | if s.Type == TypeString { |
| 527 | return value |
| 528 | } |
| 529 | |
| 530 | // Special case: array of strings with comma-separated values and no quotes. |
| 531 | if s.Type == TypeArray && s.Items != nil && s.Items.Type == TypeString && value[0] != '[' { |
| 532 | var values []string |
| 533 | for s := range strings.SplitSeq(value, ",") { |
| 534 | values = append(values, strings.TrimSpace(s)) |
| 535 | } |
| 536 | return values |
| 537 | } |
| 538 | |
| 539 | var v any |
| 540 | if err := json.Unmarshal([]byte(value), &v); err != nil { |
| 541 | panic(fmt.Errorf("invalid %s tag value '%s' for field '%s': %w", s.Type, value, fieldName, err)) |
| 542 | } |
| 543 | |
| 544 | ensureType(r, fieldName, s, value, v) |
| 545 | |
| 546 | return v |
| 547 | } |
| 548 | |
| 549 | // jsonTag returns a value of the schema's type for the given tag string. |
| 550 | // Uses JSON parsing if the schema is not a string. |
no test coverage detected
searching dependent graphs…