net/http middleware to validate HTTP requests/responses against OpenAPI 3 schema using kin-openapi.
go get github.com/aereal/go-openapi3-validation-middleware
import (
"net/http"
"github.com/aereal/go-openapi3-validation-middleware"
"github.com/getkin/kin-openapi/routers"
)
func main() {
var router routers.Router // must be built with certain way
mw := openapi3middleware.WithValidation(openapi3middleware.MiddlewareOptions{Router: router})
http.Handle("/", mw(http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
// this handler is called if validation succeeds
})))
}
See LICENSE file.