parseSchemaFromYAML parses a JSON schema from YAML content.
(yamlContent string)
| 83 | |
| 84 | // parseSchemaFromYAML parses a JSON schema from YAML content. |
| 85 | func parseSchemaFromYAML(yamlContent string) (*jsonschema.Schema, error) { |
| 86 | // First parse YAML to a generic interface |
| 87 | var yamlData any |
| 88 | if err := yaml.Unmarshal([]byte(yamlContent), &yamlData); err != nil { |
| 89 | return nil, fmt.Errorf("failed to parse YAML: %w", err) |
| 90 | } |
| 91 | |
| 92 | // Convert to JSON (this handles YAML-specific types like map[string]any) |
| 93 | jsonBytes, err := json.Marshal(yamlData) |
| 94 | if err != nil { |
| 95 | return nil, fmt.Errorf("failed to convert YAML to JSON: %w", err) |
| 96 | } |
| 97 | |
| 98 | // Parse into jsonschema.Schema |
| 99 | var schema jsonschema.Schema |
| 100 | if err := json.Unmarshal(jsonBytes, &schema); err != nil { |
| 101 | return nil, fmt.Errorf("failed to parse JSON schema: %w", err) |
| 102 | } |
| 103 | |
| 104 | return &schema, nil |
| 105 | } |
no test coverage detected