No description
  • Go 97.8%
  • Makefile 2.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Alexander Neonxp Kiryukhin 3f30371221
Some checks failed
Build project / Build (push) Failing after 42s
Build project / Build-1 (push) Failing after 1m10s
Build project / Build-2 (push) Failing after 1m10s
Build project / Build-3 (push) Failing after 1m12s
Build project / Build-4 (push) Failing after 1m10s
Build project / Build-5 (push) Failing after 1m10s
Ensure generated files are up-to-date / Build (push) Failing after 39s
Ensure generated files are up-to-date / Build-1 (push) Successful in 1m10s
Ensure generated files are up-to-date / Build-2 (push) Successful in 1m10s
Ensure generated files are up-to-date / Build-3 (push) Successful in 1m11s
Ensure generated files are up-to-date / Build-4 (push) Successful in 1m12s
Ensure generated files are up-to-date / Build-5 (push) Successful in 1m12s
Lint project / Build-2 (push) Failing after 53s
Lint project / Build-3 (push) Failing after 54s
Lint project / Build-4 (push) Failing after 54s
Ensure `go mod tidy` has been run / Build-3 (push) Successful in 1m23s
Lint project / Build (push) Failing after 42s
Lint project / Build-1 (push) Failing after 54s
Lint project / Build-5 (push) Failing after 55s
Ensure `go mod tidy` has been run / Build (push) Failing after 49s
Ensure `go mod tidy` has been run / Build-1 (push) Successful in 1m22s
Ensure `go mod tidy` has been run / Build-2 (push) Successful in 1m22s
Ensure `go mod tidy` has been run / Build-4 (push) Successful in 1m25s
Ensure `go mod tidy` has been run / Build-5 (push) Successful in 1m26s
Revert "chore(ci): добавление forgejo workflow проверки тестов"
This reverts commit 7082736887.
2026-08-30 12:04:34 +03:00
.github Modernize + make more consistent with net/http (#38) 2026-02-07 09:24:48 -08:00
.gitignore Add gitignore 2023-08-31 21:19:49 +01:00
go.mod echo v5 support 2026-06-27 17:51:50 +03:00
go.sum echo v5 support 2026-06-27 17:51:50 +03:00
LICENSE Initialise project 2023-08-31 21:15:47 +01:00
Makefile refactor: rename v5 to echov5 2026-04-15 18:24:15 +05:30
oapi_validate.go context keys 2026-06-28 13:09:59 +03:00
oapi_validate_example_test.go echo v5 support 2026-06-27 17:51:50 +03:00
oapi_validate_test.go echo v5 support 2026-06-27 17:51:50 +03:00
README.md Modernize + make more consistent with net/http (#38) 2026-02-07 09:24:48 -08:00
renovate.json Add GitHub Actions Workflows + Renovate configuration 2023-08-31 21:19:49 +01:00
test_spec.yaml fix: unescape URL-encoded path params before OpenAPI validation (#43) 2026-02-07 10:24:09 -08:00

OpenAPI Validation Middleware for labstack/echo servers

Middleware for the Echo web server to perform validation of incoming requests via an OpenAPI specification.

This project is a lightweight wrapper over the excellent kin-openapi library's openapi3filter package.

This is intended to be used with code that's generated through oapi-codegen, but should work otherwise.

⚠️ This README may be for the latest development version, which may contain unreleased changes. Please ensure you're looking at the README for the latest release version.

Usage

You can add the middleware to your project with:

go get github.com/oapi-codegen/echo-middleware

There is a full example of usage in the Go doc for this project.

A simplified version of this code is as follows:

rawSpec := `
openapi: "3.0.0"
# ...
`
spec, _ := openapi3.NewLoader().LoadFromData([]byte(rawSpec))

// NOTE that we need to make sure that the `Servers` aren't set, otherwise the OpenAPI validation middleware will validate that the `Host` header (of incoming requests) are targeting known `Servers` in the OpenAPI spec
// See also: Options#SilenceServersWarning
spec.Servers = nil

e := echo.New()
e.POST("/resource", func(c echo.Context) error {
    fmt.Printf("%s /resource was called\n", c.Request().Method)

    return c.NoContent(http.StatusNoContent)
})

// create middleware
mw := middleware.OapiRequestValidatorWithOptions(spec, &middleware.Options{
    Options: openapi3filter.Options{
        AuthenticationFunc: authenticationFunc,
    },
})

e.Use(mw)

// now all HTTP routes will be handled by the middleware, and any requests that are invalid will be rejected

FAQs

What versions of Echo does this support?

Version Supported?
github.com/labstack/echo/v4
github.com/labstack/echo/v5 Issue

"This doesn't support ..." / "I think it's a bug that ..."

As this project is a lightweight wrapper over kin-openapi's openapi3filter package, it's likely that any bugs/features are better sent upstream.

However, it's worth raising an issue here instead, as it'll allow us to triage it before it goes to the kin-openapi maintainers.

Additionally, as oapi-codegen contains a number of middleware modules, we'll very likely want to implement the same functionality across all the middlewares, so it may take a bit more coordination to get the changes in across our middlewares.

I've just updated my version of kin-openapi, and now I can't build my code 😠

The kin-openapi project - which we 💜 for providing a great library and set of tooling for interacting with OpenAPI - is a pre-v1 release, which means that they're within their rights to push breaking changes.

This may lead to breakage in your consuming code, and if so, sorry that's happened!

We'll be aware of the issue, and will work to update both the core oapi-codegen and the middlewares accordingly.