Issue580-feat: add support for referenced schema validation and caching

This commit is contained in:
ameersohel45
2025-12-12 00:32:35 +05:30
parent 33cd3dc31f
commit 94943e63e6
2 changed files with 472 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"strconv"
"strings"
"github.com/beckn-one/beckn-onix/pkg/plugin/definition"
"github.com/beckn-one/beckn-onix/pkg/plugin/implementation/schemav2validator"
@@ -40,6 +41,36 @@ func (vp schemav2ValidatorProvider) New(ctx context.Context, config map[string]s
}
}
// NEW: Parse enableReferencedSchemas
if enableStr, ok := config["enableReferencedSchemas"]; ok {
cfg.EnableReferencedSchemas = enableStr == "true"
}
// NEW: Parse referencedSchemaConfig (if enabled)
if cfg.EnableReferencedSchemas {
if v, ok := config["referencedSchemaConfig.cacheTTL"]; ok {
if ttl, err := strconv.Atoi(v); err == nil && ttl > 0 {
cfg.ReferencedSchemaConfig.CacheTTL = ttl
}
}
if v, ok := config["referencedSchemaConfig.maxCacheSize"]; ok {
if size, err := strconv.Atoi(v); err == nil && size > 0 {
cfg.ReferencedSchemaConfig.MaxCacheSize = size
}
}
if v, ok := config["referencedSchemaConfig.downloadTimeout"]; ok {
if timeout, err := strconv.Atoi(v); err == nil && timeout > 0 {
cfg.ReferencedSchemaConfig.DownloadTimeout = timeout
}
}
if v, ok := config["referencedSchemaConfig.allowedDomains"]; ok && v != "" {
cfg.ReferencedSchemaConfig.AllowedDomains = strings.Split(v, ",")
}
if v, ok := config["referencedSchemaConfig.urlTransform"]; ok && v != "" {
cfg.ReferencedSchemaConfig.URLTransform = v
}
}
return schemav2validator.New(ctx, cfg)
}