Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qustavo/swagger-proxy
Swagger Proxy validates HTTP Responses
https://github.com/qustavo/swagger-proxy
go openapi proxy swagger testing
Last synced: about 18 hours ago
JSON representation
Swagger Proxy validates HTTP Responses
- Host: GitHub
- URL: https://github.com/qustavo/swagger-proxy
- Owner: qustavo
- License: mit
- Created: 2017-05-19T14:36:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-12T05:11:06.000Z (over 5 years ago)
- Last Synced: 2024-06-19T01:45:47.971Z (5 months ago)
- Topics: go, openapi, proxy, swagger, testing
- Language: Go
- Homepage:
- Size: 6.88 MB
- Stars: 20
- Watchers: 2
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# swagger-proxy [![Build Status](https://travis-ci.org/gchaincl/swagger-proxy.svg?branch=master)](https://travis-ci.org/gchaincl/swagger-proxy)
Swagger Proxy ensure HTTP Responses correctness based on swagger specs.# Usage
SwaggerProxy is designed to assist the development process, it can be used as a reverse proxy or as a middleware.## Reverse Proxy
SwaggerProxy sits between the client/integration suite and the server as follows:
```
[Client] ---> [SwaggerProxy] ---> [Server]
```
SwaggerProxy will rely the request and analize the server response.### Install
```bash
go get github.com/gchaincl/swagger-proxy/cmd/swagger-proxy`
```
### Run
```bash
$ swagger-proxy -h
Usage of swagger-proxy:
-bind string
Bind Address (default ":1234")
-spec string
Swagger Spec (default "swagger.yml")
-target string
Target (default "http://localhost:4321")
-verbose
Verbose
```## Middleware
If your server is built in Golang, you can use it as a middleware:
```go
package mainimport (
"log"
"net/http"proxy "github.com/gchaincl/swagger-proxy"
"github.com/go-openapi/loads"
)func main() {
doc, err := loads.Spec("swagger.json")
if err != nil {
log.Fatal(err)
}p, err := proxy.New(doc.Spec(), &proxy.LogReporter{}, proxy.WithVerbose(true))
if err != nil {
log.Fatal(err)
}app := func(w http.ResponseWriter, req *http.Request) {
if req.Method == "POST" {
w.WriteHeader(201)
}
}
log.Printf("Server Running")
http.ListenAndServe(":8989", p.Handler(http.HandlerFunc(app)))
}```