validation

package
v0.0.0-...-04ccfb0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 26 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateValue

func ValidateValue(value interface{}) error

func ValidateValueWithMessage

func ValidateValueWithMessage(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(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(value interface{}) error

type FormatAlpha2

type FormatAlpha2 struct{}

func (FormatAlpha2) CheckFormat

func (FormatAlpha2) CheckFormat(value interface{}) error

type FormatBCP47

type FormatBCP47 struct{}

func (FormatBCP47) CheckFormat

func (f FormatBCP47) CheckFormat(value interface{}) error

type FormatBase64URL

type FormatBase64URL struct{}

func (FormatBase64URL) CheckFormat

func (FormatBase64URL) CheckFormat(value interface{}) error

type FormatBirthdate

type FormatBirthdate struct{}

func (FormatBirthdate) CheckFormat

func (FormatBirthdate) CheckFormat(value interface{}) error

type FormatContractID

type FormatContractID struct{}

func (FormatContractID) CheckFormat

func (FormatContractID) CheckFormat(value interface{}) error

type FormatCustomAttributePointer

type FormatCustomAttributePointer struct{}

func (FormatCustomAttributePointer) CheckFormat

func (FormatCustomAttributePointer) CheckFormat(value interface{}) error

type FormatDurationString

type FormatDurationString struct{}

func (FormatDurationString) CheckFormat

func (FormatDurationString) CheckFormat(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(value interface{}) error

type FormatGoogleTagManagerContainerID

type FormatGoogleTagManagerContainerID struct{}

func (FormatGoogleTagManagerContainerID) CheckFormat

func (FormatGoogleTagManagerContainerID) CheckFormat(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(value interface{}) error

type FormatHTTPOriginSpec

type FormatHTTPOriginSpec struct{}

func (FormatHTTPOriginSpec) CheckFormat

func (FormatHTTPOriginSpec) CheckFormat(value interface{}) error

type FormatHookURI

type FormatHookURI struct{}

func (FormatHookURI) CheckFormat

func (FormatHookURI) CheckFormat(value interface{}) error

type FormatNetworkID

type FormatNetworkID struct{}

func (FormatNetworkID) CheckFormat

func (FormatNetworkID) CheckFormat(value interface{}) error

type FormatPhone

type FormatPhone struct{}

FormatPhone checks if input is a phone number in E.164 format. 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 phone number.

func (FormatPhone) CheckFormat

func (f FormatPhone) CheckFormat(value interface{}) error

type FormatPicture

type FormatPicture struct{}

func (FormatPicture) CheckFormat

func (FormatPicture) CheckFormat(value interface{}) error

type FormatRe2Regex

type FormatRe2Regex struct{}

func (FormatRe2Regex) CheckFormat

func (FormatRe2Regex) CheckFormat(value interface{}) error

type FormatTimezone

type FormatTimezone struct{}

func (FormatTimezone) CheckFormat

func (FormatTimezone) CheckFormat(value interface{}) error

type FormatURI

type FormatURI struct {
}

FormatURI checks if input is an absolute URI.

func (FormatURI) CheckFormat

func (f FormatURI) CheckFormat(value interface{}) error

type FormatWeChatAccountID

type FormatWeChatAccountID struct {
}

FormatWeChatAccountID checks if input start with gh_.

func (FormatWeChatAccountID) CheckFormat

func (f FormatWeChatAccountID) CheckFormat(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) AdditionalPropertiesFalse

func (b SchemaBuilder) AdditionalPropertiesFalse() SchemaBuilder

func (SchemaBuilder) AllOf

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

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) 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(r io.Reader, value interface{}) error

func (*SchemaValidator) ParseJSONRawMessage

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

func (*SchemaValidator) ParseWithMessage

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

func (*SchemaValidator) Validate

func (v *SchemaValidator) Validate(r io.Reader) error

func (*SchemaValidator) ValidateValue

func (v *SchemaValidator) ValidateValue(value interface{}) error

func (*SchemaValidator) ValidateValueWithMessage

func (v *SchemaValidator) ValidateValueWithMessage(value interface{}, msg string) error

func (*SchemaValidator) ValidateWithMessage

func (v *SchemaValidator) ValidateWithMessage(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)
}

Jump to

Keyboard shortcuts

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