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 CookieParameterMissing(param *v3.Parameter, pathTemplate string, operation string, ...) *ValidationError
- func HeaderParameterCannotBeDecoded(param *v3.Parameter, val string, pathTemplate string, operation string, ...) *ValidationError
- func HeaderParameterMissing(param *v3.Parameter, pathTemplate string, operation string, ...) *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, pathTemplate string, ...) *ValidationError
- func IncorrectCookieParamEnum(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *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, pathTemplate string, ...) *ValidationError
- func IncorrectHeaderParamEnum(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *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, pathTemplate string, ...) *ValidationError
- func IncorrectParamEncodingJSON(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *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, pathTemplate string, ...) *ValidationError
- func IncorrectPathParamEnum(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func IncorrectPathParamInteger(param *v3.Parameter, item string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func IncorrectPathParamNumber(param *v3.Parameter, item string, sch *base.Schema, pathTemplate string, ...) *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, pathTemplate string, ...) *ValidationError
- func IncorrectQueryParamEnum(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func IncorrectQueryParamEnumArray(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func IncorrectReservedValues(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func IncorrectSpaceDelimiting(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
- func InvalidCookieParamInteger(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidCookieParamNumber(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidDeepObject(param *v3.Parameter, qp *helpers.QueryParam) *ValidationError
- func InvalidHeaderParamInteger(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidHeaderParamNumber(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidNamespace(schema *base.Schema, namespace, expectedNamespace, prefix string) *ValidationError
- func InvalidPrefix(schema *base.Schema, prefix string) *ValidationError
- func InvalidQueryParamInteger(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidQueryParamNumber(param *v3.Parameter, ef string, sch *base.Schema, pathTemplate string, ...) *ValidationError
- func InvalidTypeEncoding(schema *base.Schema, name, contentType string) *ValidationError
- func InvalidURLEncodedParsing(reason, referenceObject string) *ValidationError
- func InvalidXMLParsing(reason, referenceObject string) *ValidationError
- func MissingNamespace(schema *base.Schema, namespace string) *ValidationError
- func MissingPrefix(schema *base.Schema, prefix string) *ValidationError
- func OperationNotFound(pathItem *v3.PathItem, request *http.Request, method string, specPath string) *ValidationError
- func PathParameterMissing(param *v3.Parameter, pathTemplate string, actualPath string) *ValidationError
- func QueryParameterMissing(param *v3.Parameter, pathTemplate string, operation string, ...) *ValidationError
- func RequestContentTypeNotFound(op *v3.Operation, request *http.Request, specPath string) *ValidationError
- func ReservedURLEncodedValue(schema *base.Schema, name, value 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
- func UndeclaredCookieError(path string, name string, value any, declaredCookies []string, ...) *ValidationError
- func UndeclaredHeaderError(name string, value string, declaredHeaders []string, direction string, ...) *ValidationError
- func UndeclaredPropertyError(path string, name string, value any, declaredProperties []string, ...) *ValidationError
- func UndeclaredQueryParamError(path string, name string, value any, declaredParams []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'" HowToFixInvalidXml string = "Ensure xml is well-formed and matches schema structure" HowToFixXmlPrefix string = "Make sure to prepend the correct prefix '%s' to the declared fields" HowToFixXmlNamespace string = "Make sure to declare the 'xmlns:%s' with the correct namespace URI" HowToFixFormDataReservedCharacters string = "Make sure to correcly encode specials characters to percent encoding, or set allowReserved to true" HowToFixInvalidSchema string = "Ensure that the object being submitted, matches the schema correctly" HowToFixInvalidTypeEncoding string = "Ensure that the object being submitted matches the property encoding Content-Type" 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" HowToFixInvalidUrlEncoded string = "Ensure URL Encoded submitted is well-formed and matches schema structure" HowToFixDecodingError string = "The object can't be decoded, so make sure it's being encoded correctly according to the spec." HowToFixInvalidContentType string = "The content type is invalid, Use one of the %d supported types for this operation: %s" HowToFixInvalidResponseCode string = "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 string = "Ensure the correct encoding has been used on the object" HowToFixMissingValue string = "Ensure the value has been set" HowToFixPath string = "Check the path is correct, and check that the correct HTTP method has been used (e.g. GET, POST, PUT, DELETE)" HowToFixPathMethod string = "Add the missing operation to the contract for the path" HowToFixInvalidMaxItems string = "Reduce the number of items in the array to %d or less" HowToFixInvalidMinItems string = "Increase the number of items in the array to %d or more" HowToFixMissingHeader string = "Make sure the service responding sets the required headers with this response code" HowToFixInvalidRenderedSchema string = "Check the request schema for circular references or invalid structures" HowToFixInvalidJsonSchema string = "Check the request schema for invalid JSON Schema syntax, complex regex patterns, or unsupported schema constructs" )
const ( StrictSubTypeProperty = "undeclared-property" StrictSubTypeHeader = "undeclared-header" StrictSubTypeQuery = "undeclared-query-param" StrictSubTypeCookie = "undeclared-cookie" )
StrictValidationSubTypes for different kinds of undeclared values.
const StrictValidationType = "strict"
StrictValidationType is the validation type for strict mode errors.
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"`
// InstancePath is the raw path segments from the root to the failing field
InstancePath []string `json:"instancePath,omitempty" yaml:"instancePath,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 that failed validation (e.g., "$.user.email")
FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
// KeywordLocation is the JSON Pointer (RFC 6901) path to the schema keyword that failed validation
// (e.g., "/properties/age/minimum")
KeywordLocation string `json:"keywordLocation,omitempty" yaml:"keywordLocation,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 failed schema validation
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 jsonschema.ValidationError object, if the schema failure originated from the jsonschema library.
OriginalJsonSchemaError *jsonschema.ValidationError `json:"-" yaml:"-"`
// Context is the raw schema object that failed validation (for programmatic access)
Context interface{} `json:"-" yaml:"-"`
}
SchemaValidationFailure describes any failure that occurs when validating data against either an OpenAPI or JSON Schema. It aims to be a more user-friendly representation of the error than what is provided by the jsonschema library.
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 when 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 CookieParameterMissing ¶ added in v0.10.0
func HeaderParameterMissing ¶
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 InvalidNamespace ¶ added in v0.12.0
func InvalidNamespace(schema *base.Schema, namespace, expectedNamespace, prefix string) *ValidationError
func InvalidPrefix ¶ added in v0.12.0
func InvalidPrefix(schema *base.Schema, prefix string) *ValidationError
func InvalidQueryParamInteger ¶ added in v0.4.7
func InvalidQueryParamNumber ¶
func InvalidTypeEncoding ¶ added in v0.12.0
func InvalidTypeEncoding(schema *base.Schema, name, contentType string) *ValidationError
func InvalidURLEncodedParsing ¶ added in v0.12.0
func InvalidURLEncodedParsing(reason, referenceObject string) *ValidationError
func InvalidXMLParsing ¶ added in v0.12.0
func InvalidXMLParsing(reason, referenceObject string) *ValidationError
func MissingNamespace ¶ added in v0.12.0
func MissingNamespace(schema *base.Schema, namespace string) *ValidationError
func MissingPrefix ¶ added in v0.12.0
func MissingPrefix(schema *base.Schema, prefix string) *ValidationError
func OperationNotFound ¶ added in v0.0.39
func PathParameterMissing ¶ added in v0.0.56
func PathParameterMissing(param *v3.Parameter, pathTemplate string, actualPath string) *ValidationError
func QueryParameterMissing ¶
func ReservedURLEncodedValue ¶ added in v0.12.0
func ReservedURLEncodedValue(schema *base.Schema, name, value string) *ValidationError
func ResponseCodeNotFound ¶
func UndeclaredCookieError ¶ added in v0.10.0
func UndeclaredCookieError( path string, name string, value any, declaredCookies []string, requestPath string, requestMethod string, ) *ValidationError
UndeclaredCookieError creates a ValidationError for an undeclared cookie.
func UndeclaredHeaderError ¶ added in v0.10.0
func UndeclaredHeaderError( name string, value string, declaredHeaders []string, direction string, requestPath string, requestMethod string, ) *ValidationError
UndeclaredHeaderError creates a ValidationError for an undeclared header.
func UndeclaredPropertyError ¶ added in v0.10.0
func UndeclaredPropertyError( path string, name string, value any, declaredProperties []string, direction string, requestPath string, requestMethod string, specLine int, specCol int, ) *ValidationError
UndeclaredPropertyError creates a ValidationError for an undeclared property.
func UndeclaredQueryParamError ¶ added in v0.10.0
func UndeclaredQueryParamError( path string, name string, value any, declaredParams []string, requestPath string, requestMethod string, ) *ValidationError
UndeclaredQueryParamError creates a ValidationError for an undeclared query parameter.
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"