Skip to content

Migrate jsonschema v5→v6, eliminate fixSchemaBytes() workaround#8048

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/go-fan-go-module-review
Draft

Migrate jsonschema v5→v6, eliminate fixSchemaBytes() workaround#8048
Copilot wants to merge 5 commits into
mainfrom
copilot/go-fan-go-module-review

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

jsonschema/v5 with Draft 7 doesn't support negative-lookahead regexes (Go's regexp package limitation), requiring a ~200-line fixSchemaBytes() runtime patcher. jsonschema/v6 with Draft 2020-12 uses dlclark/regexp2 for ECMAScript regex, eliminating the need entirely.

Schema (mcp-gateway-config.schema.json)

  • Bumped $schema to Draft 2020-12
  • Replaced negative-lookahead patterns with not: {enum: [...]} equivalents directly in the schema
  • Added previously-injected fields (registry, guard-policies, headers) directly — they were only in the schema at runtime via fixSchemaBytes()

validation_schema.go

  • Deleted fixSchemaBytes() and newDraft7Compiler()
  • Renamed fetchAndFixSchemafetchSchema (returns raw bytes, no transformation)
  • Updated compiler setup: jsonschema.UnmarshalJSON + compiler.AddResource(url, any) (v6 takes a parsed doc, not io.Reader)
  • Replaced strings.Contains(ve.Message, ...) fallbacks in formatErrorContext with a type-switch on ve.ErrorKind:
// Before (v5, fragile string matching):
if strings.Contains(msg, "additionalProperties") { ... }

// After (v6, type-stable dispatch):
switch ve.ErrorKind.(type) {
case *kind.AdditionalProperties, *kind.AdditionalItems:
    addFromKeyword("additionalProperties")
case *kind.Required, *kind.DependentRequired:
    addFromKeyword("required")
// ...
}
  • InstanceLocation is now []string (joined with / for display); ErrorKind.LocalizedString(schemaErrPrinter) replaces ve.Message

validation.go

  • Import changed to jsonschema/v6; AddResource updated to use bytes.NewReader + jsonschema.UnmarshalJSON

Tests

  • Deleted fetch_and_fix_schema_test.go (~500 lines testing the removed function)
  • Removed 3 fetch tests that validated fixSchemaBytes transformations
  • Updated validation_schema_error_format_test.go: ValidationError construction now uses ErrorKind: &kind.X{} and InstanceLocation: []string{...}; TestKeywordFromLocation removed (helper deleted)
  • Updated validate_server_against_schema_test.go: compileSchemaForTest uses v6 UnmarshalJSON + AddResource

GitHub Advanced Security started work on behalf of lpcox June 24, 2026 14:57 View session
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 14:57
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 15:06 View session
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 15:07
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 15:23 View session
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 15:25
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 15:26 View session
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 15:27
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 15:28 View session
Copilot AI changed the title [WIP] Review and update santhosh-tekuri/jsonschema to v6.0.2 Migrate jsonschema v5→v6, eliminate fixSchemaBytes() workaround Jun 24, 2026
Copilot finished work on behalf of lpcox June 24, 2026 15:29
Copilot AI requested a review from lpcox June 24, 2026 15:29
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants