|
| 1 | +# Swagger 2.0 [](https://ci.vmware.run/go-swagger/go-swagger) [](https://ci.appveyor.com/project/casualjim/go-swagger/branch/master) [](https://coverage.vmware.run/go-swagger/go-swagger) [](https://slackin.goswagger.io) |
| 2 | + |
| 3 | +[](https://raw.githubusercontent.com/swagger-api/swagger-spec/master/LICENSE) [](http://godoc.org/github.com/go-swagger/go-swagger) [](https://badge.fury.io/gh/go-swagger%2Fgo-swagger) [](https://quay.io/repository/goswagger/swagger) |
| 4 | + |
| 5 | +Development of this toolkit is sponsored by VMware:<br>[](https://vmware.github.io) |
| 6 | + |
| 7 | +Contains an implementation of Swagger 2.0. It knows how to serialize and deserialize swagger specifications. |
| 8 | + |
| 9 | +Swagger is a simple yet powerful representation of your RESTful API.<br>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. |
| 10 | + |
| 11 | +With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability. We created Swagger to help fulfill the promise of APIs. |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +## Migrating |
| 16 | + |
| 17 | +### From 0.5.0 to 0.6.0 |
| 18 | + |
| 19 | +You will have to rename some imports: |
| 20 | + |
| 21 | +``` |
| 22 | +github.com/go-swagger/go-swagger/httpkit/validate to github.com/go-openapi/validate |
| 23 | +github.com/go-swagger/go-swagger/httpkit to github.com/go-openapi/runtime |
| 24 | +github.com/naoina/denco to github.com/go-openapi/runtime/middleware/denco |
| 25 | +github.com/go-swagger/go-swagger to github.com/go-openapi |
| 26 | +``` |
| 27 | + |
| 28 | +## Docs |
| 29 | + |
| 30 | +<https://goswagger.io> |
| 31 | + |
| 32 | +### Binary distribution |
| 33 | + |
| 34 | +go-swagger is distributed as binaries that are built of signed tags. It is published as github release, rpm, deb and docker image. |
| 35 | + |
| 36 | +#### Docker image |
| 37 | + |
| 38 | +```shell |
| 39 | +docker pull quay.io/goswagger/swagger |
| 40 | + |
| 41 | +alias swagger="docker run --rm -it -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger" |
| 42 | +swagger version |
| 43 | +``` |
| 44 | + |
| 45 | +#### Homebrew/Linuxbrew |
| 46 | + |
| 47 | +```shell |
| 48 | +brew tap go-swagger/go-swagger |
| 49 | +brew install go-swagger |
| 50 | +``` |
| 51 | + |
| 52 | +#### Static binary |
| 53 | + |
| 54 | +You can download a binary for your platform from github: |
| 55 | + |
| 56 | +<https://github.com/go-swagger/go-swagger/releases/latest> |
| 57 | + |
| 58 | +```shell |
| 59 | +latestv=$(curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/latest | jq -r .tag_name) |
| 60 | +curl -o /usr/local/bin/swagger -L'#' https://github.com/go-swagger/go-swagger/releases/download/$latestv/swagger_$(echo `uname`|tr '[:upper:]' '[:lower:]')_amd64 |
| 61 | +chmod +x /usr/local/bin/swagger |
| 62 | +``` |
| 63 | + |
| 64 | +#### Debian packages [  ](https://bintray.com/go-swagger/goswagger-debian/swagger/_latestVersion) |
| 65 | + |
| 66 | +This repo will work for any debian, the only file it contains gets copied to /usr/bin |
| 67 | + |
| 68 | +```shell |
| 69 | +echo "deb https://dl.bintray.com/go-swagger/goswagger-debian ubuntu main" | sudo tee -a /etc/apt/sources.list |
| 70 | +``` |
| 71 | + |
| 72 | +#### RPM packages [  ](https://bintray.com/go-swagger/goswagger-rpm/swagger/_latestVersion) |
| 73 | + |
| 74 | +This repo should work on any distro that wants rpm packages, the only file it contains gets copied to /usr/bin/ |
| 75 | + |
| 76 | +```shell |
| 77 | +wget https://bintray.com/go-swagger/goswagger-rpm/rpm -O bintray-go-swagger-goswagger-rpm.repo |
| 78 | +``` |
| 79 | + |
| 80 | +### From source |
| 81 | + |
| 82 | +Install or update from source: |
| 83 | + |
| 84 | +``` |
| 85 | +go get -u github.com/go-swagger/go-swagger/cmd/swagger |
| 86 | +``` |
| 87 | + |
| 88 | +The implementation also provides a number of command line tools to help working with swagger. |
| 89 | + |
| 90 | +Currently there is a [spec validator tool](http://goswagger.io/usage/validate/): |
| 91 | + |
| 92 | +``` |
| 93 | +swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json |
| 94 | +``` |
| 95 | + |
| 96 | +To generate a server for a swagger spec document: |
| 97 | + |
| 98 | +``` |
| 99 | +swagger generate server [-f ./swagger.json] -A [application-name [--principal [principal-name]] |
| 100 | +``` |
| 101 | + |
| 102 | +To generate a [client for a swagger spec](http://goswagger.io/generate/client/) document: |
| 103 | + |
| 104 | +``` |
| 105 | +swagger generate client [-f ./swagger.json] -A [application-name [--principal [principal-name]] |
| 106 | +``` |
| 107 | + |
| 108 | +To generate a [swagger spec document for a go application](http://goswagger.io/generate/spec/): |
| 109 | + |
| 110 | +``` |
| 111 | +swagger generate spec -o ./swagger.json |
| 112 | +``` |
| 113 | + |
| 114 | +## Licensing |
| 115 | + |
| 116 | +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. |
| 117 | + |
| 118 | +## What's inside? |
| 119 | + |
| 120 | +For a V1 I want to have this feature set completed: |
| 121 | + |
| 122 | +- [x] Documentation site |
| 123 | +- [x] Play nice with golint, go vet etc. |
| 124 | +- [x] An object model that serializes to swagger yaml or json |
| 125 | +- [x] A tool to work with swagger: |
| 126 | + |
| 127 | + - [x] validate a swagger spec document: |
| 128 | + - [x] validate against jsonschema |
| 129 | + - [ ] validate extra rules outlined [here](https://github.com/apigee-127/sway/blob/master/docs/versions/2.0.md#semantic-validation) |
| 130 | + |
| 131 | + - [x] definition can't declare a property that's already defined by one of its ancestors (Error) |
| 132 | + - [x] definition's ancestor can't be a descendant of the same model (Error) |
| 133 | + - [x] each api path should be non-verbatim (account for path param names) unique per method (Error) |
| 134 | + - [ ] each security reference should contain only unique scopes (Warning) |
| 135 | + - [x] each path parameter should correspond to a parameter placeholder and vice versa (Error) |
| 136 | + - [x] path parameter declarations do not allow empty names _(`/path/{}` is not valid)_ (Error) |
| 137 | + - [x] each definition property listed in the required array must be defined in the properties of the model (Error) |
| 138 | + - [x] each parameter should have a unique `name` and `in` combination (Error) |
| 139 | + - [x] each operation should have at most 1 parameter of type body (Error) |
| 140 | + - [x] each operation cannot have both a body parameter and a formData parameter (Error) |
| 141 | + - [x] each operation must have an unique `operationId` (Error) |
| 142 | + - [x] each reference must point to a valid object (Error) |
| 143 | + - [x] each referencable definition must have references (Warning) |
| 144 | + - [x] every default value that is specified must validate against the schema for that property (Error) |
| 145 | + - [x] every example that is specified must validate against the schema for that property (Error) |
| 146 | + - [x] items property is required for all schemas/definitions of type `array` (Error) |
| 147 | + |
| 148 | + - [x] serve swagger UI for any swagger spec file |
| 149 | + - [x] code generation |
| 150 | + - [x] generate api based on swagger spec |
| 151 | + - [x] generate go client from a swagger spec |
| 152 | + - [x] spec generation |
| 153 | + - [x] generate spec document based on the code |
| 154 | + |
| 155 | + - [x] generate meta data (top level swagger properties) from package docs |
| 156 | + - [x] generate definition entries for models |
| 157 | + - [x] support composed structs out of several embeds |
| 158 | + - [x] support allOf for composed structs |
| 159 | + - [x] generate path entries for routes |
| 160 | + - [x] generate responses from structs |
| 161 | + - [x] support composed structs out of several embeds |
| 162 | + - [x] generate parameters from structs |
| 163 | + - [x] support composed structs out of several embeds |
| 164 | + |
| 165 | +- [x] Middlewares: |
| 166 | + |
| 167 | + - [x] serve spec |
| 168 | + - [x] routing |
| 169 | + - [x] validation |
| 170 | + - [x] additional validation through an interface |
| 171 | + - [x] authorization |
| 172 | + |
| 173 | + - [x] basic auth |
| 174 | + - [x] api key auth |
| 175 | + - [x] oauth2 bearer auth |
| 176 | + |
| 177 | + - [x] swagger docs UI |
| 178 | + |
| 179 | +- [x] Typed JSON Schema implementation |
| 180 | + |
| 181 | + - [x] JSON Pointer that knows about structs |
| 182 | + - [x] JSON Reference that knows about structs |
| 183 | + - [x] Passes current json schema test suite |
| 184 | + |
| 185 | +- [x] extended string formats |
| 186 | + |
| 187 | + - [x] uuid, uuid3, uuid4, uuid5 |
| 188 | + - [x] email |
| 189 | + - [x] uri (absolute) |
| 190 | + - [x] hostname |
| 191 | + - [x] ipv4 |
| 192 | + - [x] ipv6 |
| 193 | + - [x] mac |
| 194 | + - [x] credit card |
| 195 | + - [x] isbn, isbn10, isbn13 |
| 196 | + - [x] social security number |
| 197 | + - [x] hexcolor |
| 198 | + - [x] rgbcolor |
| 199 | + - [x] date |
| 200 | + - [x] date-time |
| 201 | + - [x] duration |
| 202 | + - [x] password |
| 203 | + - [x] custom string formats |
0 commit comments