Fix array schema generation to include required 'items' property#10
Merged
Conversation
Contributor
Author
|
closes #9 |
Tatsinnit
approved these changes
Jun 26, 2025
| MaxLength *int `json:"maxLength,omitempty"` | ||
| Pattern string `json:"pattern,omitempty"` | ||
| Default interface{} `json:"default,omitempty"` | ||
| Type string `json:"type"` |
There was a problem hiding this comment.
💡Observation so looks fine: Cool, this all seems formatting only
Owner
|
Awesome! Thanks for the addition and fix. |
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.
Problem
When generating JSON schemas for Go structs containing slice or array fields, the schema generator was producing invalid JSON Schema that violated the specification. Array types were missing the required
itemsproperty, causing downstream validators (notably GitHub Copilot) to reject the schemas with:Solution
Updated the schema generation logic in
util/schema/schema.goto properly handle array and slice types by:Itemsfield to thePropertyDetailstruct to support nested schema definitionsitemsschema[][]float64) with proper nesteditemsdefinitionsChanges
Modified
util/schema/schema.go:Items *PropertyDetailfield toPropertyDetailstructFromStruct()to generateitemsschemas for array/slice typesAdded tests in
util/schema/schema_test.go:TestArraySchemaGeneratesItems: Verifies various array types generate correctitemsTestArraySchemaValidation: Ensures generated schemas work correctlyExample
Before this fix:
{ "some_slice": { "type": "array", "description": "List of strings" // Missing "items" property! } }After this fix:
{ "some_slice": { "type": "array", "description": "List of strings", "items": { "type": "string" } } }Testing
All tests pass:
go test ./util/schema/The fix handles:
[]string→{"type": "array", "items": {"type": "string"}}[]int→{"type": "array", "items": {"type": "integer"}}[][]float64→{"type": "array", "items": {"type": "array", "items": {"type": "number"}}}[]CustomType→{"type": "array", "items": {"type": "object"}}Impact
This fix ensures that all GoMCP-generated schemas are valid according to the JSON Schema specification, enabling proper integration with tools that validate schemas strictly (like GitHub Copilot, OpenAPI validators, etc.).