middleware

package
v0.0.0-...-dc5073b Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GinContextKey = "oapi-codegen/gin-context"
	UserDataKey   = "oapi-codegen/user-data"
)

Variables

This section is empty.

Functions

func GetGinContext

func GetGinContext(c context.Context) *gin.Context

Helper function to get the echo context from within requests. It returns nil if not found or wrong type.

func GetUserData

func GetUserData(c context.Context) interface{}

func OapiRequestValidator

func OapiRequestValidator(swagger *openapi3.T) gin.HandlerFunc

This is an gin middleware function which validates incoming HTTP requests to make sure that they conform to the given OAPI 3.0 specification. When OAPI validation fails on the request, we return an HTTP/400 with error message

func OapiRequestValidatorWithOptions

func OapiRequestValidatorWithOptions(swagger *openapi3.T, options *Options) gin.HandlerFunc

Create a validator from a swagger object, with validation options

func OapiValidatorFromYamlFile

func OapiValidatorFromYamlFile(path string) (gin.HandlerFunc, error)

Create validator middleware from a YAML file path

func ValidateRequestFromContext

func ValidateRequestFromContext(c *gin.Context, router routers.Router, options *Options) error

ValidateRequestFromContext is called from the middleware above and actually does the work of validating a request.

Types

type ErrorHandler

type ErrorHandler func(c *gin.Context, message string, statusCode int)

ErrorHandler is called when there is an error in validation

type MultiErrorHandler

type MultiErrorHandler func(openapi3.MultiError) error

MultiErrorHandler is called when oapi returns a MultiError type

type Options

type Options struct {
	ErrorHandler      ErrorHandler
	Options           openapi3filter.Options
	ParamDecoder      openapi3filter.ContentParameterDecoder
	UserData          interface{}
	MultiErrorHandler MultiErrorHandler
}

Options to customize request validation. These are passed through to openapi3filter.

Jump to

Keyboard shortcuts

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