swagger

package module
v0.0.0-...-ab5586f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2016 License: Apache-2.0 Imports: 0 Imported by: 0

README

Swagger 2.0 Build Status Build status Coverage Slack Status

license GoDoc GitHub version Docker Repository on Quay

Development of this toolkit is sponsored by VMware:
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.

Migrating

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

Docs

https://goswagger.io

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
Homebrew/Linuxbrew
brew tap go-swagger/go-swagger
brew install go-swagger
Static binary

You can download a binary for your platform from github:

https://github.com/go-swagger/go-swagger/releases/latest

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

Licensing

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

Documentation

Overview

Package swagger (2.0) provides a powerful interface to your API

Contains an implementation of Swagger 2.0. It knows how to serialize, deserialize and validate 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.

Install:

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

There are several other sub commands available for the generate command

Sub command | Description
------------|----------------------------------------------------------------------------------
operation   | generates one or more operations specified in the swagger definition
model       | generates model files for one or more models specified in the swagger definition
support     | generates the api builder and the main method
server      | generates an entire server application
client      | generates a client for a swagger specification
spec        | generates a swagger spec document based on go code

Generating code

You're free to add files to the directories the generated code lands in, but the files generated by the generator itself will be regenerated on following generation runs so any changes to those files will be lost. However extra files you create won't be lost so they are safe to use for customizing the application to your needs.

To generate a server for a swagger spec document:

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

Directories

Path Synopsis
cmd
examples
generated/restapi
Package restapi Swagger Petstore This is a sample server Petstore server.
Package restapi Swagger Petstore This is a sample server Petstore server.
task-tracker/restapi
Package restapi Issue Tracker API This application implements a very simple issue tracker.
Package restapi Issue Tracker API This application implements a very simple issue tracker.
todo-list/restapi
Package restapi Simple To Do List API Schemes: https http Host: localhost BasePath: / Version: 0.1.0 Consumes: - application/io.swagger.examples.todo-list.v1+json Produces: - application/io.swagger.examples.todo-list.v1+json swagger:meta
Package restapi Simple To Do List API Schemes: https http Host: localhost BasePath: / Version: 0.1.0 Consumes: - application/io.swagger.examples.todo-list.v1+json Produces: - application/io.swagger.examples.todo-list.v1+json swagger:meta
tutorials/todo-list/server-1/restapi
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
tutorials/todo-list/server-2/restapi
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
tutorials/todo-list/server-complete/restapi
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
Package restapi A To Do list application The product of a tutorial on goswagger.io Schemes: http Host: localhost BasePath: / Version: 1.0.0 Consumes: - application/io.goswagger.examples.todo-list.v1+json Produces: - application/io.goswagger.examples.todo-list.v1+json swagger:meta
fixtures
bugs/84/restapi
Package restapi AttendList AttendList service.
Package restapi AttendList AttendList service.
goparsing/bookings
Package booking API.
Package booking API.
goparsing/classification
Package classification Petstore API.
Package classification Petstore API.
goparsing/petstore
Package petstore Petstore API.
Package petstore Petstore API.
Package generator provides the code generation library for go-swagger The general idea is that you should rarely see interface{} in the generated code.
Package generator provides the code generation library for go-swagger The general idea is that you should rarely see interface{} in the generated code.
Package scan provides a scanner for go files that produces a swagger spec document.
Package scan provides a scanner for go files that produces a swagger spec document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL