ashutoshgngwr / goatkeeper

A Golang HTTP middleware to validate requests and their responses based on the OpenAPI specification.

Home Page:https://godoc.org/github.com/ashutoshgngwr/goatkeeper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Goatkeeper

Build status codecov Codacy Badge Latest release Godoc License

GoatKeeper is an HTTP middleware for Golang that validates HTTP requests and their responses according to types defined in OpenAPI Specification.

Goals

  • Single source of truth for APIs using OpenAPI specifications
  • Ensuring request and response conformity to the specification

Installation

$ go get -u github.com/ashutoshgngwr/goatkeeper

Usage

spec, err := ioutil.ReadFile("./openapi-spec.yaml")
if err != nil {
  panic("unable to read openapi spec file")
}

middleware, err := goatkeeper.NewMiddlware(
  &goatkeeper.MiddlewareOptions{
    OpenAPISpec:      spec,
    ValidateResponse: true,
  })

if err != nil {
  panic("unable to initialize goatkeeper middleware")
}

With Gorilla mux

r := mux.NewRouter()
r.Use(middleware)
// r.Handle ...

With vanilla Golang

s := &http.Server{
  Addr:    ":8080",
  Handler: middlware(myAPIHandler),
}

log.Fatal(s.ListenAndServe())

Credits

Built using kin-openapi implementation!

License

Copyright 2019 Ashutosh Gangwar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A Golang HTTP middleware to validate requests and their responses based on the OpenAPI specification.

https://godoc.org/github.com/ashutoshgngwr/goatkeeper

License:Apache License 2.0


Languages

Language:Go 100.0%