Module: Swaggard

Defined in:
lib/swaggard.rb,
lib/swaggard/engine.rb,
lib/swaggard/version.rb,
lib/swaggard/swagger/tag.rb,
lib/swaggard/parsers/type.rb,
lib/swaggard/swagger/path.rb,
lib/swaggard/swagger/type.rb,
lib/swaggard/configuration.rb,
lib/swaggard/api_definition.rb,
lib/swaggard/parsers/models.rb,
lib/swaggard/parsers/routes.rb,
lib/swaggard/parsers/property.rb,
lib/swaggard/swagger/property.rb,
lib/swaggard/swagger/response.rb,
lib/swaggard/swagger/operation.rb,
lib/swaggard/parsers/controller.rb,
lib/swaggard/swagger/definition.rb,
lib/swaggard/swagger/parameters/base.rb,
lib/swaggard/swagger/parameters/body.rb,
lib/swaggard/swagger/parameters/form.rb,
lib/swaggard/swagger/parameters/list.rb,
lib/swaggard/swagger/parameters/path.rb,
lib/swaggard/swagger/response_header.rb,
lib/swaggard/swagger/parameters/query.rb,
lib/generators/swaggard/install_generator.rb,
app/controllers/swaggard/swagger_controller.rb,
app/controllers/swaggard/application_controller.rb

Defined Under Namespace

Modules: Parsers, Swagger Classes: ApiDefinition, ApplicationController, Configuration, Engine, InstallGenerator, SwaggerController

Constant Summary collapse

VERSION =
'4.0.4'

Class Method Summary collapse

Class Method Details

.configurationObject



19
20
21
# File 'lib/swaggard.rb', line 19

def configuration
  @configuration ||= Swaggard::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/swaggard.rb', line 15

def configure
  yield configuration
end

.get_doc(host = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/swaggard.rb', line 51

def get_doc(host = nil)
  load!

  doc = @api.to_doc

  if host && configuration.host.blank?
    doc['servers'] = [{ 'url' => "#{configuration.schemes.first}://#{host}#{configuration.api_base_path}" }]
  end

  doc
end

.ref_name(name) ⇒ Object

Sanitize a name for use as an OpenAPI component key and $ref fragment. Keys must match ^[a-zA-Z0-9.-_]+$ per the OAS 3.1 spec.



47
48
49
# File 'lib/swaggard.rb', line 47

def ref_name(name)
  name.to_s.gsub('::', '.').gsub('#', '_')
end

.register_custom_yard_tags!Object

Register some custom yard tags



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/swaggard.rb', line 24

def register_custom_yard_tags!
  ::YARD::Tags::Library.define_tag('Controller\'s tag', :tag)
  ::YARD::Tags::Library.define_tag('Operation id', :operation_id)
  ::YARD::Tags::Library.define_tag('Query parameter', :query_parameter)
  ::YARD::Tags::Library.define_tag('Form parameter', :form_parameter)
  ::YARD::Tags::Library.define_tag('Body required', :body_required)
  ::YARD::Tags::Library.define_tag('Body description', :body_description)
  ::YARD::Tags::Library.define_tag('Body title', :body_title)
  ::YARD::Tags::Library.define_tag('Body definition', :body_definition)
  ::YARD::Tags::Library.define_tag('Body content type', :body_content_type)
  ::YARD::Tags::Library.define_tag('Body parameter', :body_parameter)
  ::YARD::Tags::Library.define_tag('Parameter list', :parameter_list)
  ::YARD::Tags::Library.define_tag('Response class', :response_class)
  ::YARD::Tags::Library.define_tag('Response root', :response_root)
  ::YARD::Tags::Library.define_tag('Response status', :response_status)
  ::YARD::Tags::Library.define_tag('Response description', :response_description)
  ::YARD::Tags::Library.define_tag('Response example', :response_example)
  ::YARD::Tags::Library.define_tag('Response header', :response_header)
  ::YARD::Tags::Library.define_tag('Ignore inherited attributes', :ignore_inherited)
end