Update jsonschema library

This commit is contained in:
Samuel Lorch 2025-08-18 14:36:58 +02:00
parent 1ffa5a23bd
commit faf74e0156
5 changed files with 51 additions and 39 deletions

View file

@ -1,15 +1,13 @@
package helper
import (
"bytes"
"context"
"encoding/json"
"fmt"
"strings"
"github.com/ProtonMail/gopenpgp/v3/crypto"
"github.com/passbolt/go-passbolt/api"
"github.com/santhosh-tekuri/jsonschema"
"github.com/santhosh-tekuri/jsonschema/v6"
)
func GetResourceMetadata(ctx context.Context, c *api.Client, resource *api.Resource, rType *api.ResourceType) (string, error) {
@ -75,7 +73,7 @@ func validateMetadata(rType *api.ResourceType, metadata string) error {
comp := jsonschema.NewCompiler()
err = comp.AddResource("metadata.json", bytes.NewReader(schemaDefinition.Resource))
err = comp.AddResource("metadata.json", schemaDefinition.Resource)
if err != nil {
return fmt.Errorf("Adding Json Schema: %w", err)
}
@ -85,7 +83,13 @@ func validateMetadata(rType *api.ResourceType, metadata string) error {
return fmt.Errorf("Compiling Json Schema: %w", err)
}
err = schema.Validate(strings.NewReader(metadata))
var parsedMetadata map[string]any
err = json.Unmarshal([]byte(metadata), &parsedMetadata)
if err != nil {
return fmt.Errorf("Unmarshal Secret: %w", err)
}
err = schema.Validate(parsedMetadata)
if err != nil {
return fmt.Errorf("Validating Metadata with Schema: %w", err)
}

View file

@ -1,13 +1,11 @@
package helper
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"github.com/passbolt/go-passbolt/api"
"github.com/santhosh-tekuri/jsonschema"
"github.com/santhosh-tekuri/jsonschema/v6"
)
func validateSecretData(rType *api.ResourceType, secretData string) error {
@ -54,7 +52,7 @@ func validateSecretData(rType *api.ResourceType, secretData string) error {
comp := jsonschema.NewCompiler()
err = comp.AddResource("secret.json", bytes.NewReader(schemaDefinition.Secret))
err = comp.AddResource("secret.json", schemaDefinition.Secret)
if err != nil {
return fmt.Errorf("Adding Json Schema: %w", err)
}
@ -64,9 +62,17 @@ func validateSecretData(rType *api.ResourceType, secretData string) error {
return fmt.Errorf("Compiling Json Schema: %w", err)
}
err = schema.Validate(strings.NewReader(secretData))
var parsedSecretData map[string]any
err = json.Unmarshal([]byte(secretData), &parsedSecretData)
if err != nil {
return fmt.Errorf("Unmarshal Secret: %w", err)
}
err = schema.Validate(parsedSecretData)
if err != nil {
return fmt.Errorf("Validating Secret Data with Schema: %w", err)
}
fmt.Println("Validated Secret data")
return nil
}