{"modulePath":"github.com/oapi-codegen/echo-v5-middleware","version":"v0.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package echomiddleware\n\nProvide HTTP middleware functionality to validate that incoming requests conform to a given OpenAPI 3.x specification.\n\nThis provides middleware for an echo/v5 HTTP server.\n\nThis package is a lightweight wrapper over [https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3filter](https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3filter) from [https://pkg.go.dev/github.com/getkin/kin-openapi](https://pkg.go.dev/github.com/getkin/kin-openapi).\n\nThis is \\_intended\\_ to be used with code that's generated through [https://pkg.go.dev/github.com/oapi-codegen/oapi-codegen](https://pkg.go.dev/github.com/oapi-codegen/oapi-codegen), but should work otherwise.\n\n## Constants\n\n```go\nconst (\n\tEchoContextKey = \"oapi-codegen/echo-context\"\n\tUserDataKey    = \"oapi-codegen/user-data\"\n)\n```\n\n## Functions\n\n```go\nfunc GetEchoContext(c context.Context) *echo.Context\n```\nGetEchoContext gets the echo context from within requests. It returns nil if not found or wrong type.\n\n```go\nfunc GetUserData(c context.Context) any\n```\n\n```go\nfunc OapiRequestValidator(spec *openapi3.T) echo.MiddlewareFunc\n```\nOapiRequestValidator Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, with a default set of configuration.\n\n```go\nfunc OapiRequestValidatorWithOptions(spec *openapi3.T, options *Options) echo.MiddlewareFunc\n```\nOapiRequestValidatorWithOptions Creates the middleware to validate that incoming requests match the given OpenAPI 3.x spec, allowing explicit configuration.\n\nNOTE that this may panic if the OpenAPI spec isn't valid, or if it cannot be used to create the middleware\n\n```go\nfunc OapiValidatorFromYamlFile(path string) (echo.MiddlewareFunc, error)\n```\nOapiValidatorFromYamlFile is an Echo 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. Create validator middleware from a YAML file path\n\n```go\nfunc ValidateRequestFromContext(ctx *echo.Context, router routers.Router, options *Options) *echo.HTTPError\n```\nValidateRequestFromContext is called from the middleware above and actually does the work of validating a request.\n\n## Types\n\n```go\ntype ErrorHandler func(c *echo.Context, err *echo.HTTPError) error\n```\nErrorHandler is called when there is an error in validation\n\n```go\ntype MultiErrorHandler func(openapi3.MultiError) *echo.HTTPError\n```\nMultiErrorHandler is called when the OpenAPI filter returns an openapi3.MultiError ([https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError](https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError))\n\n```go\ntype Options struct {\n\t// ErrorHandler is called when a validation error occurs.\n\t//\n\t// If not provided, `http.Error` will be called\n\tErrorHandler ErrorHandler\n\t// Options contains any configuration for the underlying `openapi3filter`\n\tOptions openapi3filter.Options\n\t// ParamDecoder is the openapi3filter.ContentParameterDecoder to be used for the decoding of the request body\n\t//\n\t// If unset, a default will be used\n\tParamDecoder openapi3filter.ContentParameterDecoder\n\t// UserData is any user-specified data to inject into the context.Context, which is then passed in to the validation function.\n\t//\n\t// Set on the Context with the key `UserDataKey`.\n\tUserData any\n\t// Skipper an echo Skipper to allow skipping the middleware.\n\tSkipper echomiddleware.Skipper\n\t// MultiErrorHandler is called when there is an openapi3.MultiError (https://pkg.go.dev/github.com/getkin/kin-openapi/openapi3#MultiError) returned by the `openapi3filter`.\n\t//\n\t// If not provided `defaultMultiErrorHandler` will be used.\n\tMultiErrorHandler MultiErrorHandler\n\t// SilenceServersWarning allows silencing a warning for https://github.com/oapi-codegen/oapi-codegen/issues/882 that reports when an OpenAPI spec has `spec.Servers != nil`\n\tSilenceServersWarning bool\n\t// DoNotValidateServers ensures that there is no Host validation performed (see `SilenceServersWarning` and https://github.com/deepmap/oapi-codegen/issues/882 for more details)\n\tDoNotValidateServers bool\n\t// Prefix is stripped from the request path before validation. This is useful when the API is mounted under a sub-path\n\t// (e.g. \"/api\") that isn't part of the OpenAPI spec's paths. The prefix must start with \"/\" if set.\n\tPrefix string\n\t// DiscardValidatedValue turns off openapi3filter.Options.KeepValidatedValue,\n\t// which this middleware enables by default. With it enabled, the request body\n\t// seen by handlers exposes the value that was validated through a\n\t// ValidatedValue() method, so a handler (for example an oapi-codegen strict\n\t// server) can bind that value instead of decoding the body a second time.\n\t// Set this to drop the decoded value after validation, for instance to limit\n\t// memory retention for very large request bodies.\n\t//\n\t// Options.Options.KeepValidatedValue is overridden by this setting.\n\tDiscardValidatedValue bool\n}\n```\nOptions to customize request validation. These are passed through to openapi3filter.\n\n","path":"github.com/oapi-codegen/echo-v5-middleware","name":"echomiddleware","synopsis":"Provide HTTP middleware functionality to validate that incoming requests conform to a given OpenAPI 3.x specification.","isRedistributable":true}
