helpers

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package helpers contains helper and utility functions used by the validator. Trying to avoid using the package name utils anymore, as it's too generic and can cause conflicts with other packages - however I feel this pattern will suffer the exact same fate with time.

Index

Constants

View Source
const (
	ParameterValidation       = "parameter"
	ParameterValidationPath   = "path"
	ParameterValidationQuery  = "query"
	ParameterValidationHeader = "header"
	ParameterValidationCookie = "cookie"
	RequestBodyValidation     = "requestBody"
	Schema                    = "schema"
	ResponseBodyValidation    = "response"
	RequestBodyContentType    = "contentType"
	ResponseBodyResponseCode  = "statusCode"
	SpaceDelimited            = "spaceDelimited"
	PipeDelimited             = "pipeDelimited"
	DefaultDelimited          = "default"
	MatrixStyle               = "matrix"
	LabelStyle                = "label"
	Pipe                      = "|"
	Comma                     = ","
	Space                     = " "
	SemiColon                 = ";"
	Asterisk                  = "*"
	Period                    = "."
	Equals                    = "="
	Integer                   = "integer"
	Number                    = "number"
	Slash                     = "/"
	Object                    = "object"
	String                    = "string"
	Array                     = "array"
	Boolean                   = "boolean"
	DeepObject                = "deepObject"
	Header                    = "header"
	Cookie                    = "cookie"
	Path                      = "path"
	Form                      = "form"
	Query                     = "query"
	JSONContentType           = "application/json"
	JSONType                  = "json"
	ContentTypeHeader         = "Content-Type"
	Charset                   = "charset"
	Boundary                  = "boundary"
	Preferred                 = "preferred"
	FailSegment               = "**&&FAIL&&**"
)

Variables

This section is empty.

Functions

func CollapseCSVIntoFormStyle

func CollapseCSVIntoFormStyle(key string, value string) string

func CollapseCSVIntoPipeDelimitedStyle

func CollapseCSVIntoPipeDelimitedStyle(key string, values []string) string

func CollapseCSVIntoSpaceDelimitedStyle

func CollapseCSVIntoSpaceDelimitedStyle(key string, values []string) string

func ConstructKVFromCSV

func ConstructKVFromCSV(values string) map[string]interface{}

ConstructKVFromCSV will construct a map from a comma separated value string that denotes key value pairs.

func ConstructKVFromLabelEncoding

func ConstructKVFromLabelEncoding(values string) map[string]interface{}

ConstructKVFromLabelEncoding will construct a map from a comma separated value string that denotes key value pairs.

func ConstructKVFromMatrixCSV

func ConstructKVFromMatrixCSV(values string) map[string]interface{}

ConstructKVFromMatrixCSV will construct a map from a comma separated value string that denotes key value pairs.

func ConstructMapFromCSV

func ConstructMapFromCSV(csv string) map[string]interface{}

ConstructMapFromCSV will construct a map from a comma separated value string.

func ConstructParamMapFromDeepObjectEncoding

func ConstructParamMapFromDeepObjectEncoding(values []*QueryParam) map[string]interface{}

ConstructParamMapFromDeepObjectEncoding will construct a map from the query parameters that are encoded as deep objects. It's kind of a crazy way to do things, but hey, each to their own.

func ConstructParamMapFromFormEncodingArray

func ConstructParamMapFromFormEncodingArray(values []*QueryParam) map[string]interface{}

ConstructParamMapFromFormEncodingArray will construct a map from the query parameters that are encoded as form encoded values.

func ConstructParamMapFromPipeEncoding

func ConstructParamMapFromPipeEncoding(values []*QueryParam) map[string]interface{}

ConstructParamMapFromPipeEncoding will construct a map from the query parameters that are encoded as pipe separated values. Perhaps the most sane way to delimit/encode properties.

func ConstructParamMapFromQueryParamInput

func ConstructParamMapFromQueryParamInput(values map[string][]*QueryParam) map[string]interface{}

ConstructParamMapFromQueryParamInput will construct a param map from an existing map of *QueryParam slices.

func ConstructParamMapFromSpaceEncoding

func ConstructParamMapFromSpaceEncoding(values []*QueryParam) map[string]interface{}

ConstructParamMapFromSpaceEncoding will construct a map from the query parameters that are encoded as space delimited values. This is perhaps the worst way to delimit anything other than a paragraph of text.

func DoesFormParamContainDelimiter

func DoesFormParamContainDelimiter(value, style string) bool

DoesFormParamContainDelimiter will determine if a form parameter contains a delimiter.

func ExplodeQueryValue

func ExplodeQueryValue(value, style string) []string

ExplodeQueryValue will explode a query value based on the style (space, pipe, or form/default).

func ExtractContentType

func ExtractContentType(contentType string) (string, string, string)

ExtractContentType extracts the content type from the request header. First return argument is the content type of the request.The second (optional) argument is the charset of the request. The third (optional) argument is the boundary of the type (only used with forms really).

func ExtractOperation

func ExtractOperation(request *http.Request, item *v3.PathItem) *v3.Operation

ExtractOperation extracts the operation from the path item based on the request method. If there is no matching operation found, then nil is returned.

func ExtractParamsForOperation

func ExtractParamsForOperation(request *http.Request, item *v3.PathItem) []*v3.Parameter

ExtractParamsForOperation will extract the parameters for the operation based on the request method. Both the path level params and the method level params will be returned.

Types

type QueryParam

type QueryParam struct {
	Key      string
	Values   []string
	Property string
}

QueryParam is a struct that holds the key, values and property name for a query parameter it's used for complex query types that need to be parsed and tracked differently depending on the encoding styles used.

Jump to

Keyboard shortcuts

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