Documentation
¶
Overview ¶
Package jsonschema provides a JSON schema validator that is tailored for validations of governor's Extension Resources
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidUniqueProperty is returned when the schema's unique property // is invalid ErrInvalidUniqueProperty = errors.New(`property "unique" is invalid`) // ErrUniqueConstraintViolation is returned when an object violates the unique // constrain ErrUniqueConstraintViolation = errors.New("unique constraint violation") )
var ( // SchemaURL is the URL for the unique constraint JSON schema extension SchemaURL = "https://governor/json-schemas/unique.json" // UniqueConstraintSchemaStr is the JSON schema string for the unique constraint JSON schema extension UniqueConstraintSchemaStr = `{ "properties": { "unique": { "type": "array", "items": { "type": "string" } } } }` )
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler struct {
jsonschemav6.Compiler
// contains filtered or unexported fields
}
Compiler is a struct for a JSON schema compiler
func NewCompiler ¶
NewCompiler configures and creates a new JSON schema compiler
type ErrUniquePropertyViolation ¶ added in v0.4.0
type ErrUniquePropertyViolation struct {
Message string
}
ErrUniquePropertyViolation is a jsonschema/v6 error that is returned when a unique property is violated
func (*ErrUniquePropertyViolation) KeywordPath ¶ added in v0.4.0
func (*ErrUniquePropertyViolation) KeywordPath() []string
KeywordPath returns the keyword path for the unique property violation
func (*ErrUniquePropertyViolation) LocalizedString ¶ added in v0.4.0
func (e *ErrUniquePropertyViolation) LocalizedString(p *message.Printer) string
LocalizedString returns the localized string for the unique property violation
type Option ¶
type Option func(c *Compiler)
Option is a functional configuration option for JSON schema compiler
func WithUniqueConstraint ¶
func WithUniqueConstraint( ctx context.Context, extensionResourceDefinition *models.ExtensionResourceDefinition, resourceID *string, db boil.ContextExecutor, ) Option
WithUniqueConstraint enables the unique constraint extension for a JSON schema. An extra `unique` field can be added to the JSON schema, and the Validator will ensure that the combination of every properties in the array is unique within the given extension resource definition. Note that unique constraint validation will be skipped if db is nil.
type SchemaExtension ¶ added in v0.4.0
type SchemaExtension interface {
// Compile compiles the JSON schema extension
Compile() (*jsonschemav6.Vocabulary, error)
}
SchemaExtension is an interface for JSON schema extensions
type TestErrorHandler ¶ added in v0.4.0
TestErrorHandler is an implementation of the ValidatorErrorHandler interface that is used for testing
func (*TestErrorHandler) AddError ¶ added in v0.4.0
func (t *TestErrorHandler) AddError(_ *schemav6.ValidatorContext, err schemav6.ErrorKind)
AddError saves the error
type UniqueConstraintCompiler ¶
type UniqueConstraintCompiler struct {
ERD *models.ExtensionResourceDefinition
ResourceID *string
// contains filtered or unexported fields
}
UniqueConstraintCompiler is the compiler struct for the unique constraint JSON schema extension
func (*UniqueConstraintCompiler) Compile ¶
func (uc *UniqueConstraintCompiler) Compile() (*jsonschemav6.Vocabulary, error)
Compile compiles the unique constraint JSON schema extension
type UniqueConstraintSchema ¶
type UniqueConstraintSchema struct {
UniqueFieldTypesMap map[string]string
ERD *models.ExtensionResourceDefinition
ResourceID *string
// contains filtered or unexported fields
}
UniqueConstraintSchema is the schema struct for the unique constraint JSON schema extension
func (*UniqueConstraintSchema) Validate ¶
func (s *UniqueConstraintSchema) Validate(ctx *jsonschemav6.ValidatorContext, v interface{})
Validate checks the uniqueness of the provided value against a database to ensure the unique constraint is satisfied.
type V6ValidationContextErrorHandler ¶ added in v0.4.0
type V6ValidationContextErrorHandler struct{}
V6ValidationContextErrorHandler is an implementation of the ValidatorErrorHandler interface for jsonschema/v6
func (*V6ValidationContextErrorHandler) AddError ¶ added in v0.4.0
func (v *V6ValidationContextErrorHandler) AddError(ctx *schemav6.ValidatorContext, err schemav6.ErrorKind)
AddError saves the error in the context
type ValidatorErrorHandler ¶ added in v0.4.0
type ValidatorErrorHandler interface {
AddError(*schemav6.ValidatorContext, schemav6.ErrorKind)
}
ValidatorErrorHandler is an interface to store validation errors