Schema validator plugin

This commit is contained in:
tanyamadaan
2025-03-19 10:52:42 +05:30
parent d86d23d43d
commit ef816b6e5f
24 changed files with 735 additions and 543 deletions

View File

@@ -0,0 +1,38 @@
package definition
import (
"context"
"fmt"
"net/url"
"strings"
)
// SchemaValError represents a single schema validation failure.
type SchemaValError struct {
Path string
Message string
}
// SchemaValidationErr represents a collection of schema validation failures.
type SchemaValidationErr struct {
Errors []SchemaValError
}
// Validator interface for schema validation.
type SchemaValidator interface {
Validate(ctx context.Context, url *url.URL, payload []byte) error
}
// ValidatorProvider interface for creating validators.
type SchemaValidatorProvider interface {
New(ctx context.Context, config map[string]string) (SchemaValidator, func() error, error)
}
// Error implements the error interface for SchemaValidationErr.
func (e *SchemaValidationErr) Error() string {
var errorMessages []string
for _, err := range e.Errors {
errorMessages = append(errorMessages, fmt.Sprintf("%s: %s", err.Path, err.Message))
}
return strings.Join(errorMessages, "; ")
}