jsonschema: Add caching, documentation, and version pinning support#444
Merged
jsonschema: Add caching, documentation, and version pinning support#444
Conversation
- Implement sync.Once-based schema caching to avoid repeated compilation - Add detailed documentation for fetchAndFixSchema() explaining Draft 7 workarounds - Refactor validateJSONSchema to use getOrCompileSchema() for better performance - Add TestSchemaCaching to verify caching behavior - Performance improvement: Schema compiled once, reused for all validations Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Extract schema URL to package-level constant with documentation - Document best practices for version pinning (commit SHA or version tag) - Add TestSchemaURLConfiguration to verify configurability - Improve build reproducibility by making URL easily changeable - Document alternative: embedding schema with go:embed Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Replace shadowing `err` variable with specific names (fetchErr, parseErr, addErr) - Improves code clarity and prevents potential bugs - Addresses code review feedback Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Upgrade jsonschema module from v5 to v6 with performance optimizations
jsonschema: Add caching, documentation, and version pinning support
Jan 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements Priority 1 improvements from Go Fan module review for jsonschema/v5.
Changes
Schema compilation caching
sync.Onceto compile schema once per process instead of per validationgetOrCompileSchema()handles thread-safe lazy initializationDocumentation of Draft 7 workarounds
fetchAndFixSchema()transforms negative lookahead patterns(?!...)in all implementationspattern: "^(?!stdio$|http$).*"→not: { enum: ["stdio", "http"] }Schema URL configuration
schemaURLconstantCode quality
fetchErr,parseErr,addErr)TestSchemaCaching,TestSchemaURLConfigurationWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/githubnext/gh-aw/commitsOriginal prompt
This section details on the original issue you should resolve
<issue_title>[go-fan] Go Module Review: jsonschema/v5 - v6 Upgrade & Performance Optimizations</issue_title>
<issue_description># 🐹 Go Fan Report: jsonschema/v5
Module Overview
github.com/santhosh-tekuri/jsonschema is a comprehensive JSONSchema validation library for Go that supports multiple draft specifications (draft-4 through draft/2020-12). It provides schema compilation, validation, and rich error formatting capabilities.
Repository: https://github.com/santhosh-tekuri/jsonschema
Stars: 1,193 ⭐
Current Version: v5.3.1
Latest Version: v6.0.2 (major upgrade available!)
Last Updated: 2026-01-22T02:59:27Z (updated today! 🔥)
Current Usage in gh-aw-mcpg
The module is used exclusively for MCP Gateway configuration validation in
internal/config/validation_schema.go.Files Using This Module
internal/config/validation_schema.go- Schema compilation and validation logicinternal/config/validation_schema_test.go- Comprehensive test suite (21 test cases)Key APIs Used
jsonschema.NewCompiler()- Create schema compilerCompiler.Draft = jsonschema.Draft7- Set JSON Schema draft versionCompiler.AddResource()- Register schema resourcesCompiler.Compile()- Compile schemaSchema.Validate()- Validate configuration dataValidationError- Detailed error type with nested causesCurrent Pattern
Research Findings
Recent Updates
v6.0.0 (June 2024) - Major Release
$vocabularysupport - extend JSON Schema with custom keywordssemverformat validator - useful for version validation--insecure,--cacert,--quietflagsv6.0.2 (May 2025) - Latest
OutputError.String()method for better error formattingTypes.Add()methodBest Practices from Repository
compiler.Draftfor consistent behaviorImprovement Opportunities
🏃 Quick Wins
1. Add Schema Compiler Reuse
Problem: Creates a new compiler for every validation call
Solution: Compile schema once, cache for reuse
Impact: ⚡ Performance improvement - avoid recompiling schema on every validation
2. Document Regex Workaround
Problem: Schema modification code lacks clear documentation
Solution: Add comprehensive comments
Impact: 📖 Better code maintainability and future developer onboarding
3. Add Schema Version Locking
Problem: Fetches schema from remote URL without version control
Solution: Pin schema version or embed it