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 JSONSchemaUniqueConstraint = jsonschema.MustCompileString(
"https://governor/json-schemas/unique.json",
`{
"properties": {
"unique": {
"type": "array",
"items": {
"type": "string"
}
}
}
}`,
)
JSONSchemaUniqueConstraint is a JSON schema extension that provides a "unique" property of type array
Functions ¶
This section is empty.
Types ¶
type Compiler ¶
type Compiler struct { jsonschema.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 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 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( _ jsonschema.CompilerContext, m map[string]interface{}, ) (jsonschema.ExtSchema, 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(_ jsonschema.ValidationContext, v interface{}) error
Validate checks the uniqueness of the provided value against a database to ensure the unique constraint is satisfied.