Documentation ¶
Overview ¶
Package parameters contains all the logic, models and interfaces for validating OpenAPI 3+ Parameters. Cookie, Header, Path and Query parameters are all validated.
Index ¶
- func ValidateCookieArray(sch *base.Schema, param *v3.Parameter, value string) []*errors.ValidationError
- func ValidateHeaderArray(sch *base.Schema, param *v3.Parameter, value string) []*errors.ValidationError
- func ValidateParameterSchema(schema *base.Schema, rawObject any, ...) []*errors.ValidationError
- func ValidateQueryArray(sch *base.Schema, param *v3.Parameter, ef string, contentWrapped bool) []*errors.ValidationError
- func ValidateQueryParamStyle(param *v3.Parameter, as []*helpers.QueryParam) []*errors.ValidationError
- type ParameterValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCookieArray ¶
func ValidateCookieArray( sch *base.Schema, param *v3.Parameter, value string) []*errors.ValidationError
ValidateCookieArray will validate a cookie parameter that is an array
func ValidateHeaderArray ¶
func ValidateHeaderArray( sch *base.Schema, param *v3.Parameter, value string) []*errors.ValidationError
ValidateHeaderArray will validate a header parameter that is an array
func ValidateParameterSchema ¶
func ValidateParameterSchema( schema *base.Schema, rawObject any, rawBlob, entity, reasonEntity, name, validationType, subValType string) []*errors.ValidationError
ValidateParameterSchema will validate a parameter against a raw object, or a blob of json/yaml. It will return a list of validation errors, if any.
schema: the schema to validate against rawObject: the object to validate (leave empty if using a blob) rawBlob: the blob to validate (leave empty if using an object) entity: the entity being validated reasonEntity: the entity that caused the validation to be called name: the name of the parameter validationType: the type of validation being performed subValType: the type of sub-validation being performed
func ValidateQueryArray ¶
func ValidateQueryArray( sch *base.Schema, param *v3.Parameter, ef string, contentWrapped bool) []*errors.ValidationError
ValidateQueryArray will validate a query parameter that is an array
func ValidateQueryParamStyle ¶
func ValidateQueryParamStyle(param *v3.Parameter, as []*helpers.QueryParam) []*errors.ValidationError
ValidateQueryParamStyle will validate a query parameter by style
Types ¶
type ParameterValidator ¶
type ParameterValidator interface { // SetPathItem will set the pathItem for the ParameterValidator, all validations will be performed against this pathItem // otherwise if not set, each validation will perform a lookup for the pathItem based on the *http.Request SetPathItem(path *v3.PathItem, pathValue string) // ValidateQueryParams accepts an *http.Request and validates the query parameters against the OpenAPI specification. // The method will locate the correct path, and operation, based on the verb. The parameters for the operation // will be matched and validated against what has been supplied in the http.Request query string. ValidateQueryParams(request *http.Request) (bool, []*errors.ValidationError) // ValidateHeaderParams validates the header parameters contained within *http.Request. It returns a boolean // stating true if validation passed (false for failed), and a slice of errors if validation failed. ValidateHeaderParams(request *http.Request) (bool, []*errors.ValidationError) // ValidateCookieParams validates the cookie parameters contained within *http.Request. // It returns a boolean stating true if validation passed (false for failed), and a slice of errors if validation failed. ValidateCookieParams(request *http.Request) (bool, []*errors.ValidationError) // ValidatePathParams validates the path parameters contained within *http.Request. It returns a boolean stating true // if validation passed (false for failed), and a slice of errors if validation failed. ValidatePathParams(request *http.Request) (bool, []*errors.ValidationError) // ValidateSecurity validates the security requirements for the operation. It returns a boolean stating true // if validation passed (false for failed), and a slice of errors if validation failed. ValidateSecurity(request *http.Request) (bool, []*errors.ValidationError) }
ParameterValidator is an interface that defines the methods for validating parameters There are 4 types of parameters: query, header, cookie and path.
ValidateQueryParams will validate the query parameters for the request ValidateHeaderParams will validate the header parameters for the request ValidateCookieParams will validate the cookie parameters for the request ValidatePathParams will validate the path parameters for the request
Each method accepts an *http.Request and returns true if validation passed, false if validation failed and a slice of ValidationError pointers.
func NewParameterValidator ¶
func NewParameterValidator(document *v3.Document) ParameterValidator
NewParameterValidator will create a new ParameterValidator from an OpenAPI 3+ document