Go Shell Other
Latest commit 1f7c5e5 Sep 21, 2017 @casualjim casualjim committed on GitHub Merge pull request #1180 from EleanorRigby/master
Updates vendor dep for go-openapi/validate
Failed to load latest commit information.
.circleci update vendor Sep 6, 2017
.githooks/pre-commit remove some obsolete files [ci skip] Oct 12, 2016
.github Update ISSUE_TEMPLATE.md Jan 22, 2017
cmd/swagger Add skip-flatten flag to generate server, client and operation (#1173) Sep 15, 2017
docs fix a typo in layout description Sep 12, 2017
examples Feature: Add Authorizer support Sep 6, 2017
fixtures Expands spec before generation correctly (#1167) Sep 15, 2017
generator Fix generated codes for tuple (#1179) Sep 19, 2017
hack Bugfix: Handle lint error unused Sep 7, 2017
notes add release notes for 0.12.0 Sep 11, 2017
scan Bugfix: Handle lint error unused Sep 7, 2017
vendor Updates vendor dep for go-openapi/validate Sep 21, 2017
.dockerignore verifies support of strfmt and nested collections in parameters (#725) Nov 7, 2016
.editorconfig Task: Add Makefile and scripts Apr 13, 2017
.gitignore Corrected Path generation for Base Imports Aug 28, 2017
.hound.yml add hound for minimal linting Feb 15, 2016
CODE_OF_CONDUCT.md update code of conduct to 1.4 version Jan 31, 2016
DCO fixes #65 support discriminators for schemas Nov 29, 2015
Dockerfile add build-base to container and clear check warnings Apr 22, 2017
Dockerfile.ci migrate from gvt to golang/dep (#1106) Jul 23, 2017
Dockerfile.dev Task: Add Makefile and scripts Apr 13, 2017
Gopkg.lock Updates vendor dep for go-openapi/validate Sep 21, 2017
Gopkg.toml migrate from gvt to golang/dep (#1106) Jul 23, 2017
LICENSE adds license header Nov 15, 2015
Makefile Task: Add Makefile and scripts Apr 13, 2017
Makefile.variables Task: Add Makefile and scripts Apr 13, 2017
README.md add support for strfmt.ObjectId Aug 4, 2017
appveyor.yml bump windows to 1.8 and reduce build time Apr 13, 2017
book.json Add gitbook for docs Jul 31, 2016
design.md Generates fluent builder methods where appropriate Dec 23, 2015
doc.go reformat Nov 19, 2015


Swagger 2.0 Build Status Build status codecov Slack Status

license GoDoc GitHub version Docker Repository on Quay

Development of this toolkit is sponsored by VMware:

Contains an implementation of Swagger 2.0. It knows how to serialize and deserialize swagger specifications.

Swagger is a simple yet powerful representation of your RESTful API.
With the largest ecosystem of API tooling on the planet, thousands of developers are supporting Swagger in almost every modern programming language and deployment environment.

With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. We created Swagger to help fulfill the promise of APIs.

Swagger helps companies like Apigee, Getty Images, Intuit, LivingSocial, McKesson, Microsoft, Morningstar, and PayPal build the best possible services with RESTful APIs. Now in version 2.0, Swagger is more enabling than ever. And it's 100% open source software.

How is this different from go generator in swagger-codegen

tl;dr The main difference at this moment is that this one will actually work.

The swagger-codegen project only generates a client and even there it will only support flat models.

  • This project supports most features offered by jsonschema including polymorphism.
  • It allows for generating a swagger specification from go code.
  • It allows for generating a server from a swagger definition and to generate an equivalent spec back from that codebase.
  • It allows for generating a client from a swagger definition.
  • It has support for several common swagger vendor extensions.

Why is this not done in the swagger-codegen project? Because:

  • I don't really know java very well and so I'd be learning both java and the object model of the codegen which was in heavy flux as opposed to doing go and I really wanted to go experience of designing a large codebase with it.
  • Go's super limited type system makes it so that it doesn't fit well in the model of swagger-codegen
  • Go's idea of polymorphism doesn't reconcile very well with a solution designed for languages that actually have inheritance and so forth.
  • For supporting types like [][][]map[string][][]int64 I don't think it's possible with mustache
  • I gravely underestimated the amount of work that would be involved in making something useful out of it.
  • My personal mission: I want the jvm to go away, it was great way back when now it's just silly (vm in container on vm in vm in container)

Using 0.5.0

Because 0.5.0 and master have diverged significantly, you should checkout the tag 0.5.0 for go-swagger when you use the currently released version.


From 0.5.0 to 0.6.0

You will have to rename some imports:

github.com/go-swagger/go-swagger/httpkit/validate to github.com/go-openapi/validate
github.com/go-swagger/go-swagger/httpkit to github.com/go-openapi/runtime
github.com/naoina/denco to github.com/go-openapi/runtime/middleware/denco
github.com/go-swagger/go-swagger to github.com/go-openapi



Binary distribution

go-swagger is distributed as binaries that are built of signed tags. It is published as github release, rpm, deb and docker image.

Docker image

docker pull quay.io/goswagger/swagger

alias swagger="docker run --rm -it -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger"
swagger version


brew tap go-swagger/go-swagger
brew install go-swagger

Static binary

You can download a binary for your platform from github:


latestv=$(curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/latest | jq -r .tag_name)
curl -o /usr/local/bin/swagger -L'#' https://github.com/go-swagger/go-swagger/releases/download/$latestv/swagger_$(echo `uname`|tr '[:upper:]' '[:lower:]')_amd64
chmod +x /usr/local/bin/swagger

Debian packages Download

This repo will work for any debian, the only file it contains gets copied to /usr/bin

echo "deb https://dl.bintray.com/go-swagger/goswagger-debian ubuntu main" | sudo tee -a /etc/apt/sources.list

RPM packages Download

This repo should work on any distro that wants rpm packages, the only file it contains gets copied to /usr/bin/

wget https://bintray.com/go-swagger/goswagger-rpm/rpm -O bintray-go-swagger-goswagger-rpm.repo

From source

Install or update from source:

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

The implementation also provides a number of command line tools to help working with swagger.

Currently there is a spec validator tool:

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

To generate a server for a swagger spec document:

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

To generate a client for a swagger spec document:

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

Bash Completion

Bash completion is supported and can be activated as follows:

source ./cmd/swagger/completion/swagger.bash-completion

Note that this does require you already setup bash completion, which can be done in 2 simple steps:

  1. install bash-completion using your favourite package manager;

  2. run source /etc/bash_completion in bash;

Zsh Completion

Zsh completion is supported and can be copied/soft-linked from:


In case you're new to adding auto-completion to zsh completion, here is how you could enable swagger's zsh completion step by step:

  1. create a folder used to store your completions (eg. $HOME/.zsh/completion);

  2. append the following to your $HOME/.zshrc file:

# add auto-completion directory to zsh's fpath
fpath=($HOME/.zsh/completion $fpath)

# compsys initiatlization
autoload -U compinit
  1. copy/soft-link ./cmd/swagger/completion/swagger.zsh-completion to $HOME/.zsh/completion/_swagger;


The toolkit itself is licensed as Apache Software License 2.0. Just like swagger, this does not cover code generated by the toolkit. That code is entirely yours to license however you see fit.

What's inside?

For a V1 I want to have this feature set completed:

  • Documentation site

  • Play nice with golint, go vet etc.

  • An object model that serializes to swagger yaml or json

  • A tool to work with swagger:

    • validate a swagger spec document:

    • validate against jsonschema

    • validate extra rules outlined here

      • definition can't declare a property that's already defined by one of its ancestors (Error)
      • definition's ancestor can't be a descendant of the same model (Error)
      • each api path should be non-verbatim (account for path param names) unique per method (Error)
      • each security reference should contain only unique scopes (Warning)
      • each path parameter should correspond to a parameter placeholder and vice versa (Error)
      • path parameter declarations do not allow empty names (/path/{} is not valid) (Error)
      • each definition property listed in the required array must be defined in the properties of the model (Error)
      • each parameter should have a unique name and in combination (Error)
      • each operation should have at most 1 parameter of type body (Error)
      • each operation cannot have both a body parameter and a formData parameter (Error)
      • each operation must have an unique operationId (Error)
      • each reference must point to a valid object (Error)
      • each referencable definition must have references (Warning)
      • every default value that is specified must validate against the schema for that property (Error)
      • every example that is specified must validate against the schema for that property (Error)
      • items property is required for all schemas/definitions of type array (Error)
    • serve swagger UI for any swagger spec file

    • code generation

    • generate api based on swagger spec

    • generate go client from a swagger spec

    • spec generation

    • generate spec document based on the code

      • generate meta data (top level swagger properties) from package docs
      • generate definition entries for models
      • support composed structs out of several embeds
      • support allOf for composed structs
      • generate path entries for routes
      • generate responses from structs
      • support composed structs out of several embeds
      • generate parameters from structs
      • support composed structs out of several embeds
  • Middlewares:

    • serve spec

    • routing

    • validation

    • additional validation through an interface

    • authorization

      • basic auth
      • api key auth
      • oauth2 bearer auth
    • swagger docs UI

  • Typed JSON Schema implementation

    • JSON Pointer that knows about structs
    • JSON Reference that knows about structs
    • Passes current json schema test suite
  • extended string formats

    • uuid, uuid3, uuid4, uuid5
    • email
    • uri (absolute)
    • hostname
    • ipv4
    • ipv6
    • mac
    • credit card
    • isbn, isbn10, isbn13
    • social security number
    • hexcolor
    • rgbcolor
    • date
    • date-time
    • duration
    • password
    • custom string formats
    • BSON ObjectId