Documentation
¶
Index ¶
Constants ¶
View Source
const (
ApplicationJSON = echo.MIMEApplicationJSON
)
Variables ¶
View Source
var DefaultConfig = Config{ Skipper: middleware.DefaultSkipper, ContextKey: "validator", }
View Source
var DefaultHandlerConfig = HandlerConfig{ ContentType: ApplicationJSON, ValidatorKey: "validator", ExcludeRequestBody: false, ExcludeResponseBody: false, IncludeResponseStatus: true, }
Functions ¶
func JSONValidationError ¶
func OpenAPIWithConfig ¶
func OpenAPIWithConfig(config Config) echo.MiddlewareFunc
Types ¶
type Config ¶
type Config struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// Schema defines the OpenAPI that will be loaded and
// that the requests and responses will be validated against.
// Required.
Schema string
// ContextKey defines the key that will be used to store the validator
// on the echo.Context when the request is successfully validated.
// Optional. Defaults to "validator".
ContextKey string
// ExemptRoutes defines routes and methods that don't require validation.
// Optional.
ExemptRoutes map[string][]string
}
type Handler ¶
type Handler struct {
Config HandlerConfig
}
func NewHandler ¶
func NewHandler() *Handler
func NewHandlerWithConfig ¶
func NewHandlerWithConfig(config HandlerConfig) *Handler
type HandlerConfig ¶
type HandlerConfig struct {
// ContentType sets the Content-Type header of the response.
// Optional. Defaults to "application/json".
ContentType string
// ValidatorKey defines the key that will be used to read the
// *openapi3filter.RequestValidationInput from the echo.Context
// set by the middleware.
// Optional. Defaults to "validator".
ValidatorKey string
// ExcludeRequestBody makes Validate skips request body validation.
// Optional. Defaults to false.
ExcludeRequestBody bool
// ExcludeResponseBody makes Validate skips response body validation.
// Optional. Defaults to false.
ExcludeResponseBody bool
// IncludeResponseStatus so ValidateResponse fails on response
// statuses not defined in the OpenAPI spec.
// Optional. Defaults to true.
IncludeResponseStatus bool
}
type ValidationError ¶
type ValidationError struct {
echo.HTTPError
Errors []string `json:"errors,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.