Gem Version Build Status CircleCI Maintainability

SwaggerCodegenRails

this plugin generate SWAGGER API document's templates for swagger-blocks, swagger_ui_engine.

Installation

Add this line to your application's Gemfile:

gem 'swagger_codegen_rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install swagger_codegen_rails

Usage

Demo

$ rails g swagger:install
$ rails g swagger:init /api/v1
$ rails g swagger:add /api/v1 get /api/v1/user/:id id:path:integer:true

Create intializer file

$ rails g swagger:install

Modify config/intializers/swagger_codegen_rails.rb, example below

# config/initializers/swagger_codegen_rails.rb

SwaggerCodegenRails.configure do |config|
  config.versions_url = {
    v1: 'api/v1',
    v2: 'api/v2'
  }

  config.concern_dir = "/path/to/your/concern/directory"
  # default: /app/controllers/concerns

  config.schema_dir = "/path/to/your/schema/dir"
  # default: /app/models/concerns
end

Options:

configurations type default description
config.versions_url hash EMPTY define versioned path
config.concern_dir string /app/controllers/concern set root path of endpoint documentations
config.schema_dir string /app/models/concern set root path of response schema documentations

To Create Namespace

$ rails g swagger:init NAMESPACE

To add Endpoint

$ rails g swagger:add NAMESPACE HTTP_METHOD URI [PARAMETERS; name:in:type:required]
$ # If you do NOT want namespace, example below
$ rails g swagger:add . get /users id:path:integer:true

Parameters:

description
name parameter name
in ex) in => /items?id=###, query => parameter is id.
type data type
required required

To show SwaggerUI

Add these lines in your config/application.rb (If you won't create versioned API, it is no needed.)

# config/application.rb
config.paths.add "#{config.root}/app/controllers/**/*", glob: "**/*", eager_load: true

Then start your server with rails command

$ rails s

And access http://localhost:3000/swagger in browser.

Contributing

  1. Fork it ( https://github.com/technobrain/swagger_codegen_rails )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.