errors

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 9 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 or add the code to the specification"
	HowToFixInvalidEncoding            = "Ensure the correct encoding has been used on the object"
	HowToFixMissingValue               = "Ensure the value has been set"
	HowToFixPath                       = "Check the path is correct, and check that the correct HTTP method has been used (e.g. GET, POST, PUT, DELETE)"
	HowToFixPathMethod                 = "Add the missing operation to the contract for the path"
)

Variables

This section is empty.

Functions

func PopulateValidationErrors added in v0.0.48

func PopulateValidationErrors(validationErrors []*ValidationError, request *http.Request, path string)

PopulateValidationErrors mutates the provided validation errors with additional useful error information, that is not necessarily available when the ValidationError was created and are standard for all errors. Specifically, the RequestPath, SpecPath and RequestMethod are populated.

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"`

	// DeepLocation is the path to the validation failure as exposed by the jsonschema library.
	DeepLocation string `json:"deepLocation,omitempty" yaml:"deepLocation,omitempty"`

	// AbsoluteLocation is the absolute path to the validation failure as exposed by the jsonschema library.
	AbsoluteLocation string `json:"absoluteLocation,omitempty" yaml:"absoluteLocation,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"`

	// ReferenceSchema is the schema that was referenced in the validation failure.
	ReferenceSchema string `json:"referenceSchema,omitempty" yaml:"referenceSchema,omitempty"`

	// ReferenceObject is the object that was referenced in the validation failure.
	ReferenceObject string `json:"referenceObject,omitempty" yaml:"referenceObject,omitempty"`

	// ReferenceExample is an example object generated from the schema that was referenced in the validation failure.
	ReferenceExample string `json:"referenceExample,omitempty" yaml:"referenceExample,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"`

	// RequestPath is the path of the request
	RequestPath string `json:"requestPath" yaml:"requestPath"`

	// SpecPath is the path from the specification that corresponds to the request
	SpecPath string `json:"specPath" yaml:"specPath"`

	// RequestMethod is the HTTP method of the request
	RequestMethod string `json:"requestMethod" yaml:"requestMethod"`

	// 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 OperationNotFound added in v0.0.39

func OperationNotFound(pathItem *v3.PathItem, request *http.Request, method string, specPath string) *ValidationError

func PathParameterMissing added in v0.0.56

func PathParameterMissing(param *v3.Parameter) *ValidationError

func QueryParameterMissing

func QueryParameterMissing(param *v3.Parameter) *ValidationError

func RequestContentTypeNotFound

func RequestContentTypeNotFound(op *v3.Operation, request *http.Request, specPath string) *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