Class: DoctorSwagger::SwaggerDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/doctor_swagger/swagger_doc.rb

Direct Known Subclasses

RootSwaggerDoc

Instance Method Summary collapse

Constructor Details

#initialize(resource_path, options = {}, &block) ⇒ SwaggerDoc

Returns a new instance of SwaggerDoc.


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/doctor_swagger/swagger_doc.rb', line 4

def initialize(resource_path, options = {}, &block)
  @resource_path   = resource_path
  options[:swagger_version] ||= DoctorSwagger.swagger_version
  options[:api_version]     ||= DoctorSwagger.api_version
  options[:base_path]       ||= DoctorSwagger.base_path
  @swagger_version = options[:swagger_version]
  @api_version     = options[:api_version]
  @base_path       = options[:base_path]
  @endpoints       = []
  instance_eval(&block)
end

Instance Method Details

#as_jsonObject

TODO: add DSL for


21
22
23
24
25
26
27
28
29
# File 'lib/doctor_swagger/swagger_doc.rb', line 21

def as_json(*)
  {
    'apiVersion'     => try_call(@api_version),
    'swaggerVersion' => try_call(@swagger_version),
    'basePath'       => try_call(@base_path),
    'resourcePath'   => @resource_path,
    'apis'           => @endpoints.map(&:as_json)
  }
end

#endpoint(path, &block) ⇒ Object


16
17
18
# File 'lib/doctor_swagger/swagger_doc.rb', line 16

def endpoint(path, &block)
  @endpoints << Endpoint.new(path, &block)
end