Documentation
¶
Overview ¶
Package errors contains all the error types used by the validator
Index ¶
- Constants
- func PopulateValidationErrors(validationErrors []*ValidationError, request *http.Request, path string)
- type SchemaValidationFailure
- type ValidationError
- func HeaderParameterCannotBeDecoded(param *v3.Parameter, val string) *ValidationError
- func HeaderParameterMissing(param *v3.Parameter) *ValidationError
- func IncorrectCookieParamArrayBoolean(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectCookieParamArrayNumber(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectCookieParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectCookieParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectFormEncoding(param *v3.Parameter, qp *helpers.QueryParam, i int) *ValidationError
- func IncorrectHeaderParamArrayBoolean(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectHeaderParamArrayNumber(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectHeaderParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectHeaderParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectParamArrayMaxNumItems(param *v3.Parameter, sch *base.Schema, expected, actual int64) *ValidationError
- func IncorrectParamArrayMinNumItems(param *v3.Parameter, sch *base.Schema, expected, actual int64) *ValidationError
- func IncorrectParamArrayUniqueItems(param *v3.Parameter, sch *base.Schema, duplicates string) *ValidationError
- func IncorrectParamEncodingJSON(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectPathParamArrayBoolean(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectPathParamArrayInteger(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectPathParamArrayNumber(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectPathParamBool(param *v3.Parameter, item string, sch *base.Schema) *ValidationError
- func IncorrectPathParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectPathParamInteger(param *v3.Parameter, item string, sch *base.Schema) *ValidationError
- func IncorrectPathParamNumber(param *v3.Parameter, item string, sch *base.Schema) *ValidationError
- func IncorrectPipeDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
- func IncorrectQueryParamArrayBoolean(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectQueryParamArrayInteger(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectQueryParamArrayNumber(param *v3.Parameter, item string, sch *base.Schema, itemsSchema *base.Schema) *ValidationError
- func IncorrectQueryParamBool(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectQueryParamEnum(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectQueryParamEnumArray(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectReservedValues(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func IncorrectSpaceDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
- func InvalidCookieParamInteger(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func InvalidCookieParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func InvalidDeepObject(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
- func InvalidHeaderParamInteger(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func InvalidHeaderParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func InvalidQueryParamInteger(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func InvalidQueryParamNumber(param *v3.Parameter, ef string, sch *base.Schema) *ValidationError
- func OperationNotFound(pathItem *v3.PathItem, request *http.Request, method string, specPath string) *ValidationError
- func PathParameterMissing(param *v3.Parameter) *ValidationError
- func QueryParameterMissing(param *v3.Parameter) *ValidationError
- func RequestContentTypeNotFound(op *v3.Operation, request *http.Request, specPath string) *ValidationError
- func ResponseCodeNotFound(op *v3.Operation, request *http.Request, code int) *ValidationError
- func ResponseContentTypeNotFound(op *v3.Operation, request *http.Request, response *http.Response, code string, ...) *ValidationError
Constants ¶
const ( HowToFixReservedValues string = "parameter values need to URL Encoded to ensure reserved " + "values are correctly encoded, for example: '%s'" HowToFixParamInvalidInteger string = "Convert the value '%s' into an integer" 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" HowToFixInvalidMaxItems = "Reduce the number of items in the array to %d or less" HowToFixInvalidMinItems = "Increase the number of items in the array to %d or more" HowToFixMissingHeader = "Make sure the service responding sets the required headers with this response code" )
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"`
// FieldName is the name of the specific field that failed validation (last segment of the path)
FieldName string `json:"fieldName,omitempty" yaml:"fieldName,omitempty"`
// FieldPath is the JSONPath representation of the field location (e.g., "$.user.email")
FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
// InstancePath is the raw path segments from the root to the failing field
InstancePath []string `json:"instancePath,omitempty" yaml:"instancePath,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"`
// ParameterName is the name of the parameter that failed validation (for parameter validation errors)
ParameterName string `json:"parameterName,omitempty" yaml:"parameterName,omitempty"`
// 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 IncorrectFormEncoding ¶
func IncorrectFormEncoding(param *v3.Parameter, qp *helpers.QueryParam, i int) *ValidationError
func IncorrectParamArrayMaxNumItems ¶ added in v0.4.3
func IncorrectParamArrayMinNumItems ¶ added in v0.4.3
func IncorrectParamArrayUniqueItems ¶ added in v0.4.3
func IncorrectPathParamArrayInteger ¶ added in v0.4.7
func IncorrectPathParamBool ¶
func IncorrectPathParamEnum ¶
func IncorrectPathParamInteger ¶ added in v0.4.7
func IncorrectPipeDelimiting ¶
func IncorrectPipeDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
func IncorrectQueryParamArrayInteger ¶ added in v0.4.7
func IncorrectQueryParamBool ¶
func IncorrectQueryParamEnum ¶
func IncorrectReservedValues ¶
func IncorrectSpaceDelimiting ¶
func IncorrectSpaceDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
func InvalidCookieParamInteger ¶ added in v0.4.7
func InvalidDeepObject ¶
func InvalidDeepObject(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
func InvalidHeaderParamInteger ¶ added in v0.4.7
func InvalidQueryParamInteger ¶ added in v0.4.7
func InvalidQueryParamNumber ¶
func OperationNotFound ¶ added in v0.0.39
func PathParameterMissing ¶ added in v0.0.56
func PathParameterMissing(param *v3.Parameter) *ValidationError
func QueryParameterMissing ¶
func QueryParameterMissing(param *v3.Parameter) *ValidationError
func ResponseCodeNotFound ¶
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string
Error returns a string representation of the error
func (*ValidationError) IsOperationMissingError ¶ added in v0.1.0
func (v *ValidationError) IsOperationMissingError() bool
IsOperationMissingError returns true if the error has a ValidationType of "request" and a ValidationSubType of "missingOperation"
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"