/ mozey.co / blog

go swagger

February 1, 2016

🔗 Go Tools for Swagger

🔗 go-swagger

docs

Install or update

go get -u github.com/go-swagger/go-swagger/cmd/swagger

Validate spec

swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json

Generate server from spec

swagger generate server [-f ./swagger.json] -A [application-name [--principal [principal-name]]

Generate client from spec

swagger generate client [-f ./swagger.json] -A [application-name [--principal [principal-name]]

To generate a swagger spec document for a go application

swagger generate spec -o ./swagger.json

🔗 Tutorial

🔗 server-1

cd $GOPATH/src/github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-1
 
swagger validate ./swagger.yml

swagger generate server -A TodoList -f ./swagger.yml

go install ./cmd/todo-list-server/

todo-list-server --port=1337

curl -i http://127.0.0.1:1337

🔗 server-2

cd $GOPATH/src/github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-2
 
swagger validate ./swagger.yml

swagger generate server -A TodoList -f ./swagger.yml

go run cmd/todo-list-server/main.go --port=1337 

curl -i http://127.0.0.1:1337

🔗 server-complete

cd $GOPATH/src/github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-complete
 
swagger validate ./swagger.yml

swagger generate server -A TodoList -f ./swagger.yml

go run cmd/todo-list-server/main.go --port=1337 

curl -i http://127.0.0.1:1337

🔗 ng-admin

Add an AngularJS admin GUI to any RESTful API

🔗 angular-swagger-ui

🔗 swagger-angular-client

🔗 swagger-test-templates

Does anything like this written in golang exists?

🔗 Swagger 2 specifications

Spec

JSON Schema

golang generator

🔗 Swagger test templates

🔗 OpenAPI/Swagger 3