Documentation
¶
Index ¶
- Constants
- Variables
- func JSONValidationError(c echo.Context, status int, msg string, errors []string) error
- func OpenAPI(file string) echo.MiddlewareFunc
- func OpenAPIFromBytes(schemaBytes []byte) echo.MiddlewareFunc
- func OpenAPIWithConfig(config Config) echo.MiddlewareFunc
- type Config
- type Handler
- type HandlerConfig
- type ValidationError
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 OpenAPIFromBytes ¶ added in v1.2.0
func OpenAPIFromBytes(schemaBytes []byte) echo.MiddlewareFunc
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 // SchemaBytes allows loading the OpenAPI specification directly // from a byte slice ([]byte). This is useful for embedding the // OpenAPI spec in the binary using Go's embed package, or if the // spec is obtained dynamically at runtime. // Required unless Schema is provided. // // If both Schema and SchemaBytes are provided, SchemaBytes takes precedence. SchemaBytes []byte // 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.