From e48245b00b8faf88952ea6a040a9b4013267ae20 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Mon, 13 Oct 2025 15:13:38 +0300 Subject: [PATCH] Properly upgrade jsonschema library from v5 to v6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit properly handles the major version upgrade of the github.com/santhosh-tekuri/jsonschema library from v5 to v6. In Go, major version upgrades (v2+) require updating the import path to include the new version suffix. PR #2158 attempted this upgrade but only updated go.mod without updating the import paths and adapting to API changes. Changes made: - Update import path from jsonschema/v5 to jsonschema/v6 - Remove v5 dependency from go.mod, keep only v6 - Adapt to v6 API: AddResource() now takes parsed JSON (any) instead of io.Reader - Update error handling to use v6's BasicOutput() and OutputError.String() - Adjust test expectations for v6's error message format All tests pass with the new version. Closes #2158 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- go.mod | 2 +- go.sum | 6 ++++-- pkg/registry/schema_validation.go | 24 +++++++++++++++--------- pkg/registry/schema_validation_test.go | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 3774c55ad..931a2dfbf 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/ory/fosite v0.49.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c github.com/prometheus/client_golang v1.23.2 - github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 + github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 github.com/sigstore/protobuf-specs v0.5.0 github.com/sigstore/sigstore-go v1.1.3 github.com/spf13/viper v1.21.0 diff --git a/go.sum b/go.sum index 4bd038ac8..9f97227d9 100644 --- a/go.sum +++ b/go.sum @@ -822,6 +822,8 @@ github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7 h1:lxmTCgmHE1G github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7/go.mod h1:GvWntX9qiTlOud0WkQ6ewFm0LPy5JUR1Xo0Ngbd1w6Y= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/docker/cli v28.2.2+incompatible h1:qzx5BNUDFqlvyq4AHzdNB7gSyVTmU4cgsyN9SdInc1A= github.com/docker/cli v28.2.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= @@ -1508,8 +1510,8 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/sassoftware/relic v7.2.1+incompatible h1:Pwyh1F3I0r4clFJXkSI8bOyJINGqpgjJU3DYAZeI05A= github.com/sassoftware/relic v7.2.1+incompatible/go.mod h1:CWfAxv73/iLZ17rbyhIEq3K9hs5w6FpNMdUT//qR+zk= github.com/sassoftware/relic/v7 v7.6.2 h1:rS44Lbv9G9eXsukknS4mSjIAuuX+lMq/FnStgmZlUv4= diff --git a/pkg/registry/schema_validation.go b/pkg/registry/schema_validation.go index 9de01707c..c46d86022 100644 --- a/pkg/registry/schema_validation.go +++ b/pkg/registry/schema_validation.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/santhosh-tekuri/jsonschema/v5" + "github.com/santhosh-tekuri/jsonschema/v6" ) //go:embed data/schema.json @@ -20,10 +20,16 @@ func ValidateRegistrySchema(registryData []byte) error { return fmt.Errorf("failed to read embedded registry schema: %w", err) } + // Parse the schema data (v6 requires parsed JSON object) + var schemaDoc interface{} + if err := json.Unmarshal(schemaData, &schemaDoc); err != nil { + return fmt.Errorf("failed to parse schema: %w", err) + } + // Compile the schema compiler := jsonschema.NewCompiler() schemaID := "file://local/registry-schema.json" - if err := compiler.AddResource(schemaID, strings.NewReader(string(schemaData))); err != nil { + if err := compiler.AddResource(schemaID, schemaDoc); err != nil { return fmt.Errorf("failed to add schema resource: %w", err) } schema, err := compiler.Compile(schemaID) @@ -88,15 +94,15 @@ func collectErrors(err *jsonschema.ValidationError, messages *[]string) { return } - // This is a leaf error - add it if it has a meaningful message - if err.Message != "" { + // This is a leaf error - format it with the error kind and instance location + // In v6, BasicOutput provides structured error information + output := err.BasicOutput() + if output != nil && output.Error != nil { // Create a descriptive error message with path context - var pathStr string - if err.InstanceLocation != "" { - pathStr = fmt.Sprintf(" at '%s'", err.InstanceLocation) + errorMsg := output.Error.String() + if output.InstanceLocation != "" { + errorMsg = fmt.Sprintf("%s at '%s'", errorMsg, output.InstanceLocation) } - - errorMsg := fmt.Sprintf("%s%s", err.Message, pathStr) *messages = append(*messages, errorMsg) } } diff --git a/pkg/registry/schema_validation_test.go b/pkg/registry/schema_validation_test.go index 9f43dc432..155ce0de4 100644 --- a/pkg/registry/schema_validation_test.go +++ b/pkg/registry/schema_validation_test.go @@ -250,7 +250,7 @@ func TestRegistrySchemaValidation(t *testing.T) { } }`, expectError: true, - errorContains: "additionalProperties", + errorContains: "additional properties", }, { name: "valid remote server",