validateWithSchemaAndLocation validates frontmatter against a JSON schema with location information
(frontmatter map[string]any, schemaJSON, context, filePath string)
| 344 | |
| 345 | // validateWithSchemaAndLocation validates frontmatter against a JSON schema with location information |
| 346 | func validateWithSchemaAndLocation(frontmatter map[string]any, schemaJSON, context, filePath string) error { |
| 347 | schemaCompilerLog.Printf("Validating with location info: context=%s, file=%s", context, filePath) |
| 348 | err := validateWithSchema(frontmatter, schemaJSON, context) |
| 349 | if err == nil { |
| 350 | return nil |
| 351 | } |
| 352 | |
| 353 | errorMsg := err.Error() |
| 354 | isJSONSchemaError := strings.Contains(errorMsg, "jsonschema validation failed") |
| 355 | if isJSONSchemaError { |
| 356 | errorMsg = cleanJSONSchemaErrorMessage(errorMsg) |
| 357 | } |
| 358 | |
| 359 | frontmatterCtx := readFrontmatterContext(filePath) |
| 360 | if !isJSONSchemaError { |
| 361 | return err |
| 362 | } |
| 363 | |
| 364 | jsonPaths := ExtractJSONPathFromValidationError(err) |
| 365 | schemaCompilerLog.Printf("Extracted %d JSON path(s) from validation error for %s", len(jsonPaths), context) |
| 366 | if locationErr := formatJSONSchemaValidationWithLocation(jsonPaths, schemaJSON, filePath, frontmatterCtx); locationErr != nil { |
| 367 | return locationErr |
| 368 | } |
| 369 | return buildFallbackSchemaValidationError(errorMsg, schemaJSON, filePath, frontmatterCtx) |
| 370 | } |
| 371 | |
| 372 | type frontmatterContextData struct { |
| 373 | cleanPath string |