criteria

package
v0.0.0-...-5ab778b Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrMissingRoutes is returned when a Criteria does not have any route criteria
	ErrMissingRoutes ParserErr = "missing routes matching criteria array"
	// ErrMissingRequest is returned when a Criteria does not have any request criteria
	ErrMissingRequest ParserErr = "missing request matching criteria array"
	// ErrMissingResponse is returned when a Criteria does not have any response criteria
	ErrMissingResponse ParserErr = "missing response matching criteria array"
	// ErrInvalidRoute is returned when a Criteria contains an invalid route criteria
	ErrInvalidRoute ParserErr = "invalid route criteria"
	// MIMEApplicationJSON is the application/json mime
	MIMEApplicationJSON = "application/json"
	// RequiredValidation is the swagger required validation
	RequiredValidation = "required"
	// ExclusiveMinValidation is the swagger exclusiveMin validation
	ExclusiveMinValidation = "exclusiveMin"
	// ExclusiveMaxValidation is the swagger exclusiveMax validation
	ExclusiveMaxValidation = "exclusiveMax"
	// EnumValidation is the swagger enum validation
	EnumValidation = "enum"
	// MinimumValidation is the swagger minimum validation
	MinimumValidation = "minimum"
	// MaximumValidation is the swagger maximum validation
	MaximumValidation = "maximum"
	// MinLengthValidation is the swagger minLength validation
	MinLengthValidation = "minLength"
	// MaxLengthValidation is the swagger maxLength validation
	MaxLengthValidation = "maxLength"
	// PatternValidation is the swagger pattern validation
	PatternValidation = "pattern"
	// ErrInvalidCallCriteria is returned when a Criteria contains an invalid callCriteria
	ErrInvalidCallCriteria ParserErr = "invalid response criteria"
)

Variables

This section is empty.

Functions

func MatchHTTPMethod

func MatchHTTPMethod(text string) string

MatchHTTPMethod matches an HTTP given a text

func MatchesHTTPMethod

func MatchesHTTPMethod(text string) bool

MatchesHTTPMethod returns true if text contains a known HTTP method

Types

type CallCriteria

type CallCriteria struct {
	Pkg            string                         `yaml:"pkg"`
	FuncName       string                         `yaml:"funcName"`
	ModelExtractor ModelExtractor                 `yaml:"modelExtractor"`
	CodeIndex      int                            `yaml:"codeIndex"`
	Validations    map[string]ValidationExtractor `yaml:"validations"`
	Consumes       string                         `yaml:"consumes"`
	Produces       string                         `yaml:"produces"`
}

CallCriteria contains all the information to match a function call with an argument

type Criteria

type Criteria struct {
	DefinitionPrefix    string                              `yaml:"definitionPrefix"`
	BasePath            string                              `yaml:"basePath"`
	Host                string                              `yaml:"host"`
	Info                Info                                `yaml:"info"`
	Parameters          map[string]*openapi2.Parameter      `yaml:"parameters,omitempty"`
	SecurityDefinitions map[string]*openapi2.SecurityScheme `yaml:"securityDefinitions,omitempty"`
	Routes              []RouteCriteria                     `yaml:"routes"`
	Request             []CallCriteria                      `yaml:"request"`
	Response            []CallCriteria                      `yaml:"response"`
	StaticModels        map[string]*openapi3.Schema         `yaml:"staticModels"`
	VendorFolders       []string                            `yaml:"vendorFolders"`
}

Criteria contains all the information to match a Handler, a request Parser and a Response marshaler

type Decoder

type Decoder struct {
	Logger *log.Logger
}

Decoder is able to decode and validate a Criteria

func NewCriteriaDecoder

func NewCriteriaDecoder(logger *log.Logger) Decoder

NewCriteriaDecoder creates a CriteriaDecoder

func (Decoder) ParseCriteriaFromYAML

func (decoder Decoder) ParseCriteriaFromYAML(r io.Reader, c *Criteria) error

ParseCriteriaFromYAML parses a Criteria from a YAML reader

type FuncRoute

type FuncRoute struct {
	FuncName                    string         `yaml:"funcName"`
	Pkg                         string         `yaml:"pkg"`
	HTTPMethod                  string         `yaml:"httpMethod"`
	NamedPathVarExtractor       string         `yaml:"namedPathVarExtractor"`
	NamedPathVarExtractorRegexp *regexp.Regexp `yaml:"-"`
	PathIndex                   int            `yaml:"pathIndex"`
	HandlerIndex                int            `yaml:"handlerIndex"`
	ChildRoute                  *FuncRoute     `yaml:"childRoute,omitempty"`
}

FuncRoute matches a route that is defined as a function call

type Info

type Info struct {
	Title       string `yaml:"title"`
	Version     string `yaml:"version"`
	Description string `yaml:"description"`
}

Info is the info swagger mapping

type ModelExtractor

type ModelExtractor struct {
	ParamIndex int    `yaml:"paramIndex"`
	Name       string `yaml:"name"`
}

ModelExtractor defines where to extract a model

type ParameterMatcher

type ParameterMatcher struct {
	Always        bool           `yaml:"always"`
	Field         string         `yaml:"field"`
	Matches       string         `yaml:"matches"`
	MatchesRegExp *regexp.Regexp `yaml:"-"`
}

ParameterMatcher matches parameters in a struct route

type ParserErr

type ParserErr string

ParserErr is returned when there is an error parsing a criteria

func (ParserErr) Error

func (p ParserErr) Error() string

type RouteCriteria

type RouteCriteria struct {
	StructRoute *StructRoute `yaml:"structRoute"`
	FuncRoute   *FuncRoute   `yaml:"funcRoute"`
}

RouteCriteria contains all the information to find a Route declaration

type StructRoute

type StructRoute struct {
	Name                        string                      `yaml:"name"`
	Pkg                         string                      `yaml:"pkg"`
	PathField                   string                      `yaml:"pathField"`
	NamedPathVarExtractor       string                      `yaml:"namedPathVarExtractor"`
	NamedPathVarExtractorRegexp *regexp.Regexp              `yaml:"-"`
	HandlerField                string                      `yaml:"handlerField"`
	HTTPMethodField             string                      `yaml:"httpMethodField"`
	Parameters                  map[string]ParameterMatcher `yaml:"parameters"`
	Security                    map[string]ParameterMatcher `yaml:"security"`
}

StructRoute matches a route that is defined as a struct

type ValidationExtractor

type ValidationExtractor struct {
	Validation string `yaml:"validation"`
	// Tag        []string         `yaml:"tag"`
	TagRegexp []*regexp.Regexp `yaml:"-"`
}

ValidationExtractor are slices of regular expression that matches validations

Jump to

Keyboard shortcuts

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