jsonschema

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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")
)
View Source
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

func NewCompiler(
	extensionID, slugPlural, version string,
	opts ...Option,
) *Compiler

NewCompiler configures and creates a new JSON schema compiler

func (*Compiler) Compile

func (c *Compiler) Compile(schema string) (*jsonschema.Schema, error)

Compile compiles the schema string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL