Go API Documentation

github.com/TykTechnologies/tyk/apidef/streams/bento

No package summary is available.

Package

Files: 1. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

const (
	DefaultBentoConfigSchemaName	string		= "bento-config-schema.json"
	DefaultValidator		ValidatorKind	= "default-validator"
	EnableAll			ValidatorKind	= "enable-all"
)

Vars

var (
	schemaOnce	sync.Once

	bentoSchemas	= map[ValidatorKind][]byte{}
)
var schemaDir embed.FS

Types

ConfigValidator

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type ConfigValidator interface {
	Validate(document []byte) error
}

DefaultConfigValidator

This type doesn't have documentation.

Field name Field type Comment
schemaLoader

gojsonschema.JSONLoader

No comment on field.
type DefaultConfigValidator struct {
	schemaLoader gojsonschema.JSONLoader
}

EnableAllConfigValidator

EnableAllConfigValidator is a validator that skips all validation

type EnableAllConfigValidator struct{}

ValidatorKind

This type doesn't have documentation.

Field name Field type Comment
type

string

No comment on field.
type ValidatorKind string

Functions

func NewDefaultConfigValidator

func NewDefaultConfigValidator() (*DefaultConfigValidator, error) {
	err := loadBentoSchemas()	// loads the schemas only one time
	if err != nil {
		return nil, err
	}

	schema := bentoSchemas[DefaultValidator]
	return &DefaultConfigValidator{
		schemaLoader: gojsonschema.NewBytesLoader(schema),
	}, nil
}

Cognitive complexity: 3, Cyclomatic complexity: 2

Uses: gojsonschema.NewBytesLoader.

func NewEnableAllConfigValidator

NewEnableAllConfigValidator creates a new validator that skips all validation

func NewEnableAllConfigValidator() *EnableAllConfigValidator {
	return &EnableAllConfigValidator{}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (*DefaultConfigValidator) Validate

func (v *DefaultConfigValidator) Validate(document []byte) error {
	documentLoader := gojsonschema.NewBytesLoader(document)
	result, err := gojsonschema.Validate(v.schemaLoader, documentLoader)
	if err != nil {
		return err
	}
	if result.Valid() {
		return nil
	}

	combinedErr := &multierror.Error{}
	combinedErr.ErrorFormat = tykerrors.Formatter
	validationErrs := result.Errors()
	for _, validationErr := range validationErrs {
		combinedErr = multierror.Append(combinedErr, errors.New(validationErr.String()))
	}
	return combinedErr.ErrorOrNil()
}

Cognitive complexity: 8, Cyclomatic complexity: 4

Uses: errors.New, gojsonschema.NewBytesLoader, gojsonschema.Validate, multierror.Append, multierror.Error, tykerrors.Formatter.

func (*EnableAllConfigValidator) Validate

Validate always returns nil, effectively enabling all configurations

func (v *EnableAllConfigValidator) Validate(_ []byte) error {
	return nil
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func loadBentoSchemas

loadBentoSchemas () error
References: filepath.Join, fmt.Errorf, strings.HasSuffix.


Tests

Files: 1. Third party imports: 1. Imports from organisation: 0. Tests: 2. Benchmarks: 0.

Test functions

TestValidateBentoConfiguration

References: require.ErrorContains, require.NoError, testing.T.

TestValidateBentoConfiguration_NewEnableAllConfigValidator

References: require.NoError, require.NotNil.