Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
24 changes: 15 additions & 9 deletions pkg/registry/schema_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strings"

"github.com/santhosh-tekuri/jsonschema/v5"
"github.com/santhosh-tekuri/jsonschema/v6"
)

//go:embed data/schema.json
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/schema_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestRegistrySchemaValidation(t *testing.T) {
}
}`,
expectError: true,
errorContains: "additionalProperties",
errorContains: "additional properties",
},
{
name: "valid remote server",
Expand Down
Loading