[go-fan] Go Module Review: jsonschema/v6 #5191
Closed
Replies: 1 comment
-
|
⚓ Avast! This discussion be marked as outdated by Go Fan. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Go Fan Report: github.com/santhosh-tekuri/jsonschema/v6
Module Overview
The santhosh-tekuri/jsonschema library is a comprehensive JSON Schema validator for Go that provides robust validation with excellent error reporting. It supports all JSON Schema drafts from draft-04 through draft/2020-12, making it one of the most complete JSON Schema implementations available for Go.
This library is critical to gh-aw's validation infrastructure, providing schema validation for:
Current Usage in gh-aw
Files Using This Module (5 files)
pkg/workflow/schema_validation.go- GitHub Actions workflow schema validationpkg/workflow/safe_outputs_tools_schema_test.go- MCP tools schema validation testspkg/parser/schema.go- Main workflow and included file frontmatter validationpkg/parser/json_path_locator.go- JSON path extraction from validation errorspkg/parser/json_path_locator_test.go- JSON path locator testsKey APIs Used
jsonschema.NewCompiler()- Creating schema compilerscompiler.AddResource()- Adding schema documentscompiler.Compile()- Compiling schemasschema.Validate()- Validating instancesValidationError.Causes- Detailed error iterationCurrent Pattern: Cached Schema Compilation
The codebase uses an effective pattern of compiling schemas once and caching them with
sync.Once:This is excellent - schema compilation is expensive and should only happen once!
Research Findings
Repository Health
jvv0.7.0 available for standalone validationKey Features
$vocabularyRecent Updates (v6.0.0 → v6.0.2)
v6.0.2 (May 2025) - Maintenance release
v6.0.1 (June 2024)
RecursiveReffield misspellingDeprecatedfield in schema structv6.0.0 (June 2024) - Major release
$vocabularysupportsemverformat validatorValidationErrorBest Practices from Maintainers
ValidationError.Causesfor detailed error reporting ✅ Already doing this!compiler.AssertFormat()❌ Not doing thiscompiler.AssertContent()❌ Not doing thisImprovement Opportunities
🏃 Quick Wins (High Impact, Low Effort)
1. Enable Format Assertions
Current: No explicit format assertion mode enabled
Benefit: Catch format violations (email, date-time, uuid) in workflow schemas
Action: Add
compiler.AssertFormat()incompileSchema()(pkg/parser/schema.go:183)Impact: Would catch invalid formats in workflow configuration immediately
2. Enable Content Assertions
Current: No content assertion mode enabled
Benefit: Validate base64 encoding and JSON content in string fields
Action: Add
compiler.AssertContent()for schemas with contentEncoding/contentMediaTypeImpact: Better validation of embedded JSON in workflow YAML
3. Eliminate Double JSON Marshal/Unmarshal
Current:
validateWithSchema()marshals to JSON and unmarshals for normalization (pkg/parser/schema.go:297-305)Issue: Unnecessary performance overhead (2x round-trip)
Better: Pass data in correct format from the start or use
jsonschema.UnmarshalJSON()Performance Impact: ~2x improvement in validation hot path
✨ Feature Opportunities (High Impact, Medium Effort)
4. Leverage Detailed Error Output
Current: Only using basic error messages from
cause.Error()Opportunity: Use structured error output (flag/basic/detailed modes) for better debugging
Action: Implement custom error formatting using
ValidationErrorhierarchyExample: Show validation path AND schema location for clearer error messages
5. Add Custom Formats for Workflow-Specific Types
Opportunity: Register custom format validators for workflow patterns
Examples:
workflow-name: Validate workflow naming conventionscron-expression: Validate cron schedule syntaxgithub-ref: Validate GitHub ref patterns (refs/heads/, refs/tags/)Action: Create format validators and register with
compiler.RegisterFormat()6. Schema Introspection for Auto-completion
Current: Manual schema navigation in
navigateToSchemaPath()andextractAcceptedFieldsFromSchema()Opportunity: Use compiled schema structure directly for more accurate suggestions
Benefit: Better IDE-like auto-completion based on actual schema structure
📐 Best Practice Alignment (Medium Impact)
7. Consolidate Error Message Cleaning
Current: Multiple string manipulation functions for error messages
cleanJSONSchemaErrorMessage()rewriteAdditionalPropertiesError()Issue: Fragile string matching and replacement
Better: Use
ValidationErrorstructure fields directlyAction: Access
KeywordLocation,InstanceLocation, and error details from structured error8. Add Schema Version Metadata
Current: No explicit draft version in schemas
Opportunity: Specify draft version with
$schemafieldBenefit: Explicit contract, better compatibility, clearer expectations
Action: Add to embedded schemas:
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", ... }9. Implement Unified Schema Cache Manager
Current: Multiple
sync.Oncevariables for different schemasBetter: Map-based caching with schema URL as key
Benefit: More scalable, easier to add new schemas
🔧 General Improvements
10. Extract Validation Error Utilities
Current: Error extraction logic scattered across files
Opportunity: Create dedicated
pkg/validation/errors.gowith shared utilitiesBenefit: Reusable error handling, consistent formatting
11. Add Validation Performance Metrics
Opportunity: Track schema compilation and validation timing
Benefit: Identify slow schema patterns, optimize hot paths
12. Test with Official JSON Schema Test Suite
Current: Custom tests only
Opportunity: Run against JSON-Schema-Test-Suite
Benefit: Ensure compatibility, catch edge cases
Recommendations
Priority 1 (Do First - High ROI)
compiler.AssertFormat())compiler.AssertContent())Priority 2 (Next Up)
Priority 3 (Future Improvements)
$schemafield)Interesting Discovery
The library includes a semver format validator (added in v6.0.0) which could be useful for validating version strings in workflows! The library also supports custom vocabularies, which could be leveraged to create workflow-specific validation keywords.
Next Steps
The most impactful immediate improvements are:
compiler.AssertFormat()andcompiler.AssertContent()) to enable comprehensive validationThese changes require minimal code but provide significant validation improvements and better error reporting for users!
Module Summary: specs/mods/jsonschema-v6.md
Review Date: 2025-12-01
Beta Was this translation helpful? Give feedback.
All reactions