|
17 | 17 | // - sync.Once ensures schema is compiled only once |
18 | 18 | // - Schema is embedded in the binary as githubWorkflowSchema |
19 | 19 | // - Cached compiled schema is reused across all validations |
20 | | -// - YAML is converted to JSON for schema validation |
| 20 | +// - YAML is parsed directly and validated without JSON conversion |
21 | 21 | // |
22 | 22 | // # Schema Source |
23 | 23 | // |
@@ -93,31 +93,23 @@ func getCompiledSchema() (*jsonschema.Schema, error) { |
93 | 93 | // validateGitHubActionsSchema validates the generated YAML content against the GitHub Actions workflow schema |
94 | 94 | func (c *Compiler) validateGitHubActionsSchema(yamlContent string) error { |
95 | 95 | schemaValidationLog.Print("Validating workflow YAML against GitHub Actions schema") |
96 | | - // Convert YAML to any for JSON conversion |
| 96 | + |
| 97 | + // Parse YAML directly into any type for schema validation |
| 98 | + // The jsonschema library accepts any type directly, no JSON conversion needed |
97 | 99 | var workflowData any |
98 | 100 | if err := yaml.Unmarshal([]byte(yamlContent), &workflowData); err != nil { |
99 | 101 | return fmt.Errorf("failed to parse YAML for schema validation: %w", err) |
100 | 102 | } |
101 | 103 |
|
102 | | - // Convert to JSON for schema validation |
103 | | - jsonData, err := json.Marshal(workflowData) |
104 | | - if err != nil { |
105 | | - return fmt.Errorf("failed to convert YAML to JSON for validation: %w", err) |
106 | | - } |
107 | | - |
108 | 104 | // Get the cached compiled schema |
109 | 105 | schema, err := getCompiledSchema() |
110 | 106 | if err != nil { |
111 | 107 | return err |
112 | 108 | } |
113 | 109 |
|
114 | | - // Validate the JSON data against the schema |
115 | | - var jsonObj any |
116 | | - if err := json.Unmarshal(jsonData, &jsonObj); err != nil { |
117 | | - return fmt.Errorf("failed to unmarshal JSON for validation: %w", err) |
118 | | - } |
119 | | - |
120 | | - if err := schema.Validate(jsonObj); err != nil { |
| 110 | + // Validate the parsed YAML data directly against the schema |
| 111 | + // No JSON roundtrip required - the schema.Validate() accepts any type |
| 112 | + if err := schema.Validate(workflowData); err != nil { |
121 | 113 | // Enhance error message with field-specific examples |
122 | 114 | enhancedErr := enhanceSchemaValidationError(err) |
123 | 115 | schemaValidationLog.Printf("Schema validation failed: %v", enhancedErr) |
|
0 commit comments