errors

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: MIT Imports: 8 Imported by: 14

Documentation

Overview

Package errors contains all the error types used by the validator

Index

Constants

View Source
const (
	HowToFixReservedValues string = "parameter values need to URL Encoded to ensure reserved " +
		"values are correctly encoded, for example: '%s'"
	HowToFixParamInvalidNumber                      string = "Convert the value '%s' into a number"
	HowToFixParamInvalidString                      string = "Convert the value '%s' into a string (cannot start with a number, or be a floating point)"
	HowToFixParamInvalidBoolean                     string = "Convert the value '%s' into a true/false value"
	HowToFixParamInvalidEnum                        string = "Instead of '%s', use one of the allowed values: '%s'"
	HowToFixParamInvalidFormEncode                  string = "Use a form style encoding for parameter values, for example: '%s'"
	HowToFixInvalidSchema                           string = "Ensure that the object being submitted, matches the schema correctly"
	HowToFixParamInvalidSpaceDelimitedObjectExplode string = "When using 'explode' with space delimited parameters, " +
		"they should be separated by spaces. For example: '%s'"
	HowToFixParamInvalidPipeDelimitedObjectExplode string = "When using 'explode' with pipe delimited parameters, " +
		"they should be separated by pipes '|'. For example: '%s'"
	HowToFixParamInvalidDeepObjectMultipleValues string = "There can only be a single value per property name, " +
		"deepObject parameters should contain the property key in square brackets next to the parameter name. For example: '%s'"
	HowToFixInvalidJSON         string = "The JSON submitted is invalid, please check the syntax"
	HowToFixDecodingError              = "The object can't be decoded, so make sure it's being encoded correctly according to the spec."
	HowToFixInvalidContentType         = "The content type is invalid, Use one of the %d supported types for this operation: %s"
	HowToFixInvalidResponseCode        = "The service is responding with a code that is not defined in the spec, fix the service!"
	HowToFixInvalidEncoding            = "Ensure the correct encoding has been used on the object"
	HowToFixMissingValue               = "Ensure the value has been set"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SchemaValidationFailure

type SchemaValidationFailure struct {
	// Reason is a human-readable message describing the reason for the error.
	Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`

	// Location is the XPath-like location of the validation failure
	Location string `json:"location,omitempty" yaml:"location,omitempty"`

	// Line is the line number where the violation occurred. This may a local line number
	// if the validation is a schema (only schemas are validated locally, so the line number will be relative to
	// the Context object held by the ValidationError object).
	Line int `json:"line,omitempty" yaml:"line,omitempty"`

	// Column is the column number where the violation occurred. This may a local column number
	// if the validation is a schema (only schemas are validated locally, so the column number will be relative to
	// the Context object held by the ValidationError object).
	Column int `json:"column,omitempty" yaml:"column,omitempty"`

	// The original error object, which is a jsonschema.ValidationError object.
	OriginalError *jsonschema.ValidationError `json:"-" yaml:"-"`
}

SchemaValidationFailure is a wrapper around the jsonschema.ValidationError object, to provide a more user-friendly way to break down what went wrong.

func (*SchemaValidationFailure) Error

func (s *SchemaValidationFailure) Error() string

Error returns a string representation of the error

type ValidationError

type ValidationError struct {

	// Message is a human-readable message describing the error.
	Message string `json:"message" yaml:"message"`

	// Reason is a human-readable message describing the reason for the error.
	Reason string `json:"reason" yaml:"reason"`

	// ValidationType is a string that describes the type of validation that failed.
	ValidationType string `json:"validationType" yaml:"validationType"`

	// ValidationSubType is a string that describes the subtype of validation that failed.
	ValidationSubType string `json:"validationSubType" yaml:"validationSubType"`

	// SpecLine is the line number in the spec where the error occurred.
	SpecLine int `json:"specLine" yaml:"specLine"`

	// SpecCol is the column number in the spec where the error occurred.
	SpecCol int `json:"specColumn" yaml:"specColumn"`

	// HowToFix is a human-readable message describing how to fix the error.
	HowToFix string `json:"howToFix" yaml:"howToFix"`

	// SchemaValidationErrors is a slice of SchemaValidationFailure objects that describe the validation errors
	// This is only populated whe the validation type is against a schema.
	SchemaValidationErrors []*SchemaValidationFailure `json:"validationErrors,omitempty" yaml:"validationErrors,omitempty"`

	// Context is the object that the validation error occurred on. This is usually a pointer to a schema
	// or a parameter object.
	Context interface{} `json:"-" yaml:"-"`
}

ValidationError is a struct that contains all the information about a validation error.

func HeaderParameterCannotBeDecoded

func HeaderParameterCannotBeDecoded(param *v3.Parameter, val string) *ValidationError

func HeaderParameterMissing

func HeaderParameterMissing(param *v3.Parameter) *ValidationError

func IncorrectCookieParamArrayBoolean

func IncorrectCookieParamArrayBoolean(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectCookieParamArrayNumber

func IncorrectCookieParamArrayNumber(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectCookieParamBool

func IncorrectCookieParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectCookieParamEnum

func IncorrectCookieParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectFormEncoding

func IncorrectFormEncoding(param *v3.Parameter, qp *helpers.QueryParam, i int) *ValidationError

func IncorrectHeaderParamArrayBoolean

func IncorrectHeaderParamArrayBoolean(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectHeaderParamArrayNumber

func IncorrectHeaderParamArrayNumber(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectHeaderParamBool

func IncorrectHeaderParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectHeaderParamEnum

func IncorrectHeaderParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectParamEncodingJSON

func IncorrectParamEncodingJSON(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectPathParamArrayBoolean

func IncorrectPathParamArrayBoolean(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectPathParamArrayNumber

func IncorrectPathParamArrayNumber(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectPathParamBool

func IncorrectPathParamBool(param *v3.Parameter, item string, sch *base.Schema) *ValidationError

func IncorrectPathParamEnum

func IncorrectPathParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectPathParamNumber

func IncorrectPathParamNumber(param *v3.Parameter, item string, sch *base.Schema) *ValidationError

func IncorrectPipeDelimiting

func IncorrectPipeDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError

func IncorrectQueryParamArrayBoolean

func IncorrectQueryParamArrayBoolean(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectQueryParamArrayNumber

func IncorrectQueryParamArrayNumber(
	param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError

func IncorrectQueryParamBool

func IncorrectQueryParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectQueryParamEnum

func IncorrectQueryParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectQueryParamEnumArray

func IncorrectQueryParamEnumArray(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectReservedValues

func IncorrectReservedValues(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func IncorrectSpaceDelimiting

func IncorrectSpaceDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError

func InvalidCookieParamNumber

func InvalidCookieParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func InvalidDeepObject

func InvalidDeepObject(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError

func InvalidHeaderParamNumber

func InvalidHeaderParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func InvalidQueryParamNumber

func InvalidQueryParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError

func QueryParameterMissing

func QueryParameterMissing(param *v3.Parameter) *ValidationError

func RequestContentTypeNotFound

func RequestContentTypeNotFound(op *v3.Operation, request *http.Request) *ValidationError

func ResponseCodeNotFound

func ResponseCodeNotFound(op *v3.Operation, request *http.Request, code int) *ValidationError

func ResponseContentTypeNotFound

func ResponseContentTypeNotFound(op *v3.Operation,
	request *http.Request,
	response *http.Response,
	code string,
	isDefault bool) *ValidationError

func (*ValidationError) Error

func (v *ValidationError) Error() string

Error returns a string representation of the error

func (*ValidationError) IsPathMissingError added in v0.0.2

func (v *ValidationError) IsPathMissingError() bool

IsPathMissingError returns true if the error has a ValidationType of "path" and a ValidationSubType of "missing"

Jump to

Keyboard shortcuts

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