Class: Openapi::SwaggerRoot

Inherits:
Object
  • Object
show all
Includes:
Swagger::Blocks
Defined in:
lib/openapi/mongoid/spec_builder.rb

Class Method Summary collapse

Class Method Details

.build_specification(config, controller_classes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/openapi/mongoid/spec_builder.rb', line 5

def self.build_specification(config, controller_classes)
  schema = Rails.env.production? ? 'https' : 'http'

  swagger_root do
    key :swagger,  '2.0'
    key :host,     ENV['HOST'] || 'localhost:3000'
    key :basePath, config[:base_path] || '/api'
    key :consumes, %w(application/json)
    key :produces, %w(application/json text/csv)
    key :schemes,  [schema]

    info do
      key :title,       config[:title] || 'Default'
      key :description, config[:description] || ''
      key :version,     config[:version] || '1.0'
    end

    controller_classes.each do |c|
      tag do
        key :name, c.openapi_collection_name
      end
    end
  end
end