Home

Awesome

sibiro-swagger

Generate a swagger specification for your sibiro routes. It generates a specification according to OpenAPI specification 2.0.

Usage

Add [functionalbytes/sibiro-swagger "0.1.4"] to your dependencies.

The library offers basically one function: swaggerize. It takes your (uncompiled) routes datastructure, and returns a Clojure datastructure holding the specification. It also takes additional keyword arguments. Currently the following are supported:

There are also two functions called swaggerize-json and swaggerize-yaml, which is the same as swaggerize, but returns a JSON or YAML string.

An example

Let's have two simple routes, one with some extra route info:

(def routes [[:get  "/user/:id" {:swagger {:description "Get user by ID"
                                           :parameters [{:name :id :type :integer
                                                         :in :path :required true}]
                                           :responses {200 {:description "User found"}}}}]
             [:post "/user/:id" nil])

(swaggerize-yaml routes :base {:info {:version "0.3"}})

Above results in the following YAML. Note that some defaults are still visibile, such as the title and the responses of the POST operation.

swagger: '2.0'
info:
  title: I'm too lazy to name my API
  version: '0.3'
paths:
  /user/{id}:
    get:
      responses:
        '200':
          description: User found
      parameters:
      - name: id
        type: integer
        in: path
        required: true
      description: Get user by ID
    post:
      responses:
        default:
          description: Default response.
    parameters:
    - name: id
      in: path
      type: string
      required: true

As always, have fun!

Contributing

Patches and ideas welcome.

Master branch: Circle CI

License

Copyright © 2016 Functional Bytes

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.