[go-fan] Go Module Review: google/jsonschema-go #5187
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/google/jsonschema-go
Module Overview
github.com/google/jsonschema-go is Google's official implementation of the JSON Schema specification for Go. It provides schema creation, validation (draft 2020-12 and draft-07), and automatic schema inference from Go structs with zero dependencies outside the standard library. The module is actively maintained and just released v0.3.0 in September 2025 with significant improvements.
Current Usage in gh-aw
Usage Summary
Key Usage Pattern
The project uses a single helper function
GenerateOutputSchema[T]()inpkg/cli/mcp_schema.gothat wrapsjsonschema.ForType()to generate schemas from Go types. The generated schemas are used to describe MCP tool output structures for LLM consumption.Current implementation:
Files using this module:
pkg/cli/mcp_schema.go:7- Implementationpkg/cli/mcp_schema_test.go- Comprehensive unit testspkg/cli/mcp_tool_schemas_test.go- Integration testsAPIs Utilized
jsonschema.ForType()- Schema inference from reflect.Typejsonschema.Schema- Core schema structurejsonschema.ForOptions- Configuration (currently empty)jsonschema.For[T]()- Not used (but should be!)Research Findings
Repository & Maintenance
Recent Updates (v0.2.0 → v0.3.0)
Breaking Changes
anytoreflect.Type- prevents issues with unmappable typesNew Features
Bug Fixes
Community Requests & Open Issues
The active issue tracker reveals important community needs:
High Priority:
gh aw helpand notice #47: Extended jsonschema tags (minlength, pattern, etc.)Medium Priority:
5. #46: Self-referential structures (currently causes cycle errors)
6. #24: Auto-set $schema during marshaling
7. #20: Simplify verbose validation errors
8. #15: PropertyOrder control for JSON rendering
9. #13: Expose True()/False() schema constructors
Best Practices from Maintainers
Based on documentation and issue discussions:
Improvement Opportunities
🏃 Quick Wins
Simplify GenerateOutputSchema Implementation
jsonschema.For[T](nil)pkg/cli/mcp_schema.go:32-38Add End-to-End Validation Tests
pkg/cli/mcp_schema_test.goDocument jsonschema Tag Conventions
Verify Nil Options Safety
&jsonschema.ForOptions{}nil✨ Feature Opportunities
Implement TypeSchemas for Custom Types
pkg/cli/mcp_type_schemas.goAdd Schema Validation Middleware
schema.Resolve()andresolved.Validate()on tool outputspkg/cli/mcp_schema_validator.goEnable Default Value Application
resolved.ApplyDefaults()for MCP tool parametersImplement Schema Caching
Enhance Schema Descriptions
📐 Best Practice Alignment
Consistent jsonschema Tag Usage
Verify Nullable Field Handling
Avoid Circular References
Structured Error Types
🔧 General Improvements
Schema Generation Simplification
Before:
After:
Add Schema Test Fixtures
testdata/schemas/Schema Linting in CI
Monitor Upstream Development
gh aw helpand notice #47 (extended tags) - Would simplify validationEvaluate Library Consolidation
google/jsonschema-go(this one) - Schema generationsanthosh-tekuri/jsonschema/v6- MCP SDK validationRecommendations
Priority 1: Immediate Actions
For[T]()directlyPriority 2: Short-term Enhancements
Priority 3: Long-term Considerations
gh aw helpand notice #47) - adopt when availableNext Steps
GenerateOutputSchemaimplementation for simplificationModule summary saved to:
specs/mods/jsonschema-go.mdKey Insight: gh-aw's current usage is minimal but correct. The module offers significant untapped potential for schema validation, custom type mapping, and performance optimization. The biggest opportunity is implementing schema validation middleware to catch errors before they reach MCP clients. Additionally, clarifying the relationship with the santhosh-tekuri jsonschema library would help maintain architectural clarity.
Beta Was this translation helpful? Give feedback.
All reactions