validation

package
v0.0.0-...-49c1f3c Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 31 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateValue

func ValidateValue(ctx context.Context, value interface{}) error

func ValidateValueWithMessage

func ValidateValueWithMessage(ctx context.Context, value interface{}, msg string) error

Types

type AggregatedError

type AggregatedError struct {
	Message string
	Errors  []Error
}

func (*AggregatedError) Error

func (e *AggregatedError) Error() string

func (*AggregatedError) Subtract

func (e *AggregatedError) Subtract(that *AggregatedError) *AggregatedError

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) AddError

func (c *Context) AddError(err error)

func (*Context) Child

func (c *Context) Child(path ...string) *Context

func (*Context) EmitError

func (c *Context) EmitError(keyword string, info map[string]interface{})

func (*Context) EmitErrorMessage

func (c *Context) EmitErrorMessage(msg string)

func (*Context) Error

func (c *Context) Error(msg string) error

func (*Context) Validate

func (c *Context) Validate(ctx context.Context, value interface{})

type Error

type Error struct {
	Location string                 `json:"location"`
	Keyword  string                 `json:"kind"`
	Info     map[string]interface{} `json:"details,omitempty"`
}

func (*Error) Kind

func (e *Error) Kind() string

func (*Error) String

func (e *Error) String() string

type FormatAbsolutePath

type FormatAbsolutePath struct{}

func (FormatAbsolutePath) CheckFormat

func (FormatAbsolutePath) CheckFormat(ctx context.Context, value interface{}) error

type FormatAlpha2

type FormatAlpha2 struct{}

func (FormatAlpha2) CheckFormat

func (FormatAlpha2) CheckFormat(ctx context.Context, value interface{}) error

type FormatBCP47

type FormatBCP47 struct{}

func (FormatBCP47) CheckFormat

func (f FormatBCP47) CheckFormat(ctx context.Context, value interface{}) error

type FormatBase64URL

type FormatBase64URL struct{}

func (FormatBase64URL) CheckFormat

func (FormatBase64URL) CheckFormat(ctx context.Context, value interface{}) error

type FormatBirthdate

type FormatBirthdate struct{}

func (FormatBirthdate) CheckFormat

func (FormatBirthdate) CheckFormat(ctx context.Context, value interface{}) error

type FormatContractID

type FormatContractID struct{}

func (FormatContractID) CheckFormat

func (FormatContractID) CheckFormat(ctx context.Context, value interface{}) error

type FormatCustomAttributePointer

type FormatCustomAttributePointer struct{}

func (FormatCustomAttributePointer) CheckFormat

func (FormatCustomAttributePointer) CheckFormat(ctx context.Context, value interface{}) error

type FormatDateTime

type FormatDateTime struct{}

func (FormatDateTime) CheckFormat

func (FormatDateTime) CheckFormat(ctx context.Context, value interface{}) error

type FormatDurationString

type FormatDurationString struct{}

func (FormatDurationString) CheckFormat

func (FormatDurationString) CheckFormat(ctx context.Context, value interface{}) error

type FormatEmail

type FormatEmail struct {
	AllowName bool
}

FormatEmail checks if input is an email address. If the input is not a string, it is not an error. To enforce string, use other JSON schema constructs. This design allows this format to validate optional email.

func (FormatEmail) CheckFormat

func (f FormatEmail) CheckFormat(ctx context.Context, value interface{}) error

type FormatGoogleTagManagerContainerID

type FormatGoogleTagManagerContainerID struct{}

func (FormatGoogleTagManagerContainerID) CheckFormat

func (FormatGoogleTagManagerContainerID) CheckFormat(ctx context.Context, value interface{}) error

type FormatHTTPOrigin

type FormatHTTPOrigin struct {
}

FormatHTTPOrigin checks if input is a valid origin with http/https scheme, host and optional port only.

func (FormatHTTPOrigin) CheckFormat

func (f FormatHTTPOrigin) CheckFormat(ctx context.Context, value interface{}) error

type FormatHTTPOriginSpec

type FormatHTTPOriginSpec struct{}

func (FormatHTTPOriginSpec) CheckFormat

func (FormatHTTPOriginSpec) CheckFormat(ctx context.Context, value interface{}) error

type FormatHookURI

type FormatHookURI struct{}

func (FormatHookURI) CheckFormat

func (FormatHookURI) CheckFormat(ctx context.Context, value interface{}) error

type FormatLDAPAttribute

type FormatLDAPAttribute struct{}

func (FormatLDAPAttribute) CheckFormat

func (FormatLDAPAttribute) CheckFormat(ctx context.Context, value interface{}) error

type FormatLDAPDN

type FormatLDAPDN struct{}

func (FormatLDAPDN) CheckFormat

func (FormatLDAPDN) CheckFormat(ctx context.Context, value interface{}) error

type FormatLDAPSearchFilterTemplate

type FormatLDAPSearchFilterTemplate struct{}

func (FormatLDAPSearchFilterTemplate) CheckFormat

func (FormatLDAPSearchFilterTemplate) CheckFormat(ctx context.Context, value interface{}) error

type FormatLDAPURL

type FormatLDAPURL struct{}

func (FormatLDAPURL) CheckFormat

func (FormatLDAPURL) CheckFormat(ctx context.Context, value interface{}) error

type FormatNetworkID

type FormatNetworkID struct{}

func (FormatNetworkID) CheckFormat

func (FormatNetworkID) CheckFormat(ctx context.Context, value interface{}) error

type FormatPicture

type FormatPicture struct{}

func (FormatPicture) CheckFormat

func (FormatPicture) CheckFormat(ctx context.Context, value interface{}) error

type FormatRe2Regex

type FormatRe2Regex struct{}

func (FormatRe2Regex) CheckFormat

func (FormatRe2Regex) CheckFormat(ctx context.Context, value interface{}) error

type FormatTimezone

type FormatTimezone struct{}

func (FormatTimezone) CheckFormat

func (FormatTimezone) CheckFormat(ctx context.Context, value interface{}) error

type FormatURI

type FormatURI struct {
}

FormatURI checks if input is an absolute URI.

func (FormatURI) CheckFormat

func (f FormatURI) CheckFormat(ctx context.Context, value interface{}) error

type FormatWeChatAccountID

type FormatWeChatAccountID struct {
}

FormatWeChatAccountID checks if input start with gh_.

func (FormatWeChatAccountID) CheckFormat

func (f FormatWeChatAccountID) CheckFormat(ctx context.Context, value interface{}) error

type FormatX509CertPem

type FormatX509CertPem struct{}

func (FormatX509CertPem) CheckFormat

func (FormatX509CertPem) CheckFormat(ctx context.Context, value interface{}) error

type MultipartSchema

type MultipartSchema struct {
	// contains filtered or unexported fields
}

func NewMultipartSchema

func NewMultipartSchema(mainPartID string) *MultipartSchema

func (*MultipartSchema) Add

func (s *MultipartSchema) Add(partID string, schema string) *MultipartSchema

func (*MultipartSchema) AddJSON

func (s *MultipartSchema) AddJSON(partID string, schema interface{}) *MultipartSchema

func (*MultipartSchema) DumpSchemaString

func (s *MultipartSchema) DumpSchemaString(pretty bool) (schemaString string, err error)

func (*MultipartSchema) Instantiate

func (s *MultipartSchema) Instantiate() *MultipartSchema

func (*MultipartSchema) PartValidator

func (s *MultipartSchema) PartValidator(partID string) *SchemaValidator

func (*MultipartSchema) RegisterFormat

func (s *MultipartSchema) RegisterFormat(format string, checker jsonschemaformat.FormatChecker)

func (*MultipartSchema) Validator

func (s *MultipartSchema) Validator() *SchemaValidator

type SchemaBuilder

type SchemaBuilder map[string]interface{}

SchemaBuilder is just map[string]interface{} with some convenient methods to build schema interactively. The zero value of a SchemaBuilder is an empty schema (by definition). This is NOT meant to be complete. It just supports the internal use cases we have.

func (SchemaBuilder) AddRequired

func (b SchemaBuilder) AddRequired(keys ...string) SchemaBuilder

func (SchemaBuilder) AddTypeNull

func (b SchemaBuilder) AddTypeNull() SchemaBuilder

func (SchemaBuilder) AdditionalPropertiesFalse

func (b SchemaBuilder) AdditionalPropertiesFalse() SchemaBuilder

func (SchemaBuilder) AllOf

func (b SchemaBuilder) AllOf(builders ...SchemaBuilder) SchemaBuilder

func (SchemaBuilder) Clone

func (b SchemaBuilder) Clone() SchemaBuilder

This function allow copying the schema builder to a reference Expected usage is to avoid mutating original schema builder

func (SchemaBuilder) Const

func (b SchemaBuilder) Const(value interface{}) SchemaBuilder

func (SchemaBuilder) Contains

func (b SchemaBuilder) Contains(builder SchemaBuilder) SchemaBuilder

func (SchemaBuilder) Else

func (b SchemaBuilder) Else(builder SchemaBuilder) SchemaBuilder

func (SchemaBuilder) Enum

func (b SchemaBuilder) Enum(values ...interface{}) SchemaBuilder

func (SchemaBuilder) Format

func (b SchemaBuilder) Format(format string) SchemaBuilder

func (SchemaBuilder) If

func (SchemaBuilder) Items

func (b SchemaBuilder) Items(builder SchemaBuilder) SchemaBuilder

func (SchemaBuilder) MaximumFloat64

func (b SchemaBuilder) MaximumFloat64(maximum float64) SchemaBuilder

func (SchemaBuilder) MaximumInt64

func (b SchemaBuilder) MaximumInt64(maximum int64) SchemaBuilder

func (SchemaBuilder) MinItems

func (b SchemaBuilder) MinItems(n int) SchemaBuilder

func (SchemaBuilder) MinLength

func (b SchemaBuilder) MinLength(minLength int) SchemaBuilder

func (SchemaBuilder) MinimumFloat64

func (b SchemaBuilder) MinimumFloat64(minimum float64) SchemaBuilder

func (SchemaBuilder) MinimumInt64

func (b SchemaBuilder) MinimumInt64(minimum int64) SchemaBuilder

func (SchemaBuilder) OneOf

func (b SchemaBuilder) OneOf(builders ...SchemaBuilder) SchemaBuilder

func (SchemaBuilder) Properties

func (b SchemaBuilder) Properties() SchemaBuilder

func (SchemaBuilder) Property

func (b SchemaBuilder) Property(key string, builder SchemaBuilder) SchemaBuilder

func (SchemaBuilder) Required

func (b SchemaBuilder) Required(keys ...string) SchemaBuilder

func (SchemaBuilder) Then

func (b SchemaBuilder) Then(builder SchemaBuilder) SchemaBuilder

func (SchemaBuilder) ToSimpleSchema

func (b SchemaBuilder) ToSimpleSchema() *SimpleSchema

func (SchemaBuilder) Type

func (b SchemaBuilder) Type(t Type) SchemaBuilder

func (SchemaBuilder) Types

func (b SchemaBuilder) Types(ts ...Type) SchemaBuilder

type SchemaValidator

type SchemaValidator struct {
	Schema    *jsonschema.Collection
	Reference string
}

func (*SchemaValidator) Parse

func (v *SchemaValidator) Parse(ctx context.Context, r io.Reader, value interface{}) error

func (*SchemaValidator) ParseJSONRawMessage

func (v *SchemaValidator) ParseJSONRawMessage(ctx context.Context, msg json.RawMessage, value interface{}) error

func (*SchemaValidator) ParseWithMessage

func (v *SchemaValidator) ParseWithMessage(ctx context.Context, r io.Reader, msg string, value interface{}) error

func (*SchemaValidator) Validate

func (v *SchemaValidator) Validate(ctx context.Context, r io.Reader) error

func (*SchemaValidator) ValidateValue

func (v *SchemaValidator) ValidateValue(ctx context.Context, value interface{}) error

func (*SchemaValidator) ValidateValueWithMessage

func (v *SchemaValidator) ValidateValueWithMessage(ctx context.Context, value interface{}, msg string) error

func (*SchemaValidator) ValidateWithMessage

func (v *SchemaValidator) ValidateWithMessage(ctx context.Context, r io.Reader, msg string) error

type SimpleSchema

type SimpleSchema struct {
	// contains filtered or unexported fields
}

func NewSimpleSchema

func NewSimpleSchema(schema string) *SimpleSchema

func (*SimpleSchema) RegisterFormat

func (s *SimpleSchema) RegisterFormat(format string, checker jsonschemaformat.FormatChecker)

func (*SimpleSchema) Validator

func (s *SimpleSchema) Validator() *SchemaValidator

type Type

type Type string
const (
	TypeNull    Type = "null"
	TypeBoolean Type = "boolean"
	TypeNumber  Type = "number"
	TypeInteger Type = "integer"
	TypeString  Type = "string"
	TypeObject  Type = "object"
	TypeArray   Type = "array"
)

type Validator

type Validator interface {
	Validate(context.Context, *Context)
}

Jump to

Keyboard shortcuts

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