parameters

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 20 Imported by: 1

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

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

func ValidateSingleParameterSchema added in v0.0.43

func ValidateSingleParameterSchema(
	schema *base.Schema,
	rawObject any,
	entity string,
	reasonEntity string,
	name string,
	validationType string,
	subValType string,
) (validationErrors []*errors.ValidationError)

Types

type ParameterValidator

type ParameterValidator interface {
	// 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)

	// ValidateQueryParamsWithPathItem 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.
	ValidateQueryParamsWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (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)

	// ValidateHeaderParamsWithPathItem 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.
	ValidateHeaderParamsWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (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)

	// ValidateCookieParamsWithPathItem 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.
	ValidateCookieParamsWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (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)

	// ValidatePathParamsWithPathItem 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.
	ValidatePathParamsWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (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)

	// ValidateSecurityWithPathItem 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.
	ValidateSecurityWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (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
ValidateCookieParamsWithPathItem 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

Jump to

Keyboard shortcuts

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