Class: Apress::Documentation::Storage::SwaggerDocument

Inherits:
BaseStorage
  • Object
show all
Includes:
Dsl::SwaggerDocument
Defined in:
lib/apress/documentation/storage/swagger_document.rb

Overview

Protected

Описывает дополнительные данные для swagger_path в SwaggerUI

Алгоритм добавления данных в SwaggerUI:

- записывакем нужные экземпляры этого класса в объекте Document(метод swagger_documents)
- сериализуем данные из swagger_documents во вьюхе в js-переменную (метод as_json в BaseStorage)
- вешаем событие на добавление данных из новосозданной переменной в HTML-таг с id == bind_id
- после отрисовки SwaggerUI, вызываем триггер события, которое добавляет дополнительные данные

Instance Attribute Summary collapse

Attributes inherited from BaseStorage

#slug

Instance Method Summary collapse

Methods included from Dsl::SwaggerDocument

#compile

Methods inherited from BaseStorage

#assign, #dependencies, #eql?, #hash, #inspect, json_attr, json_attr_names, #to_s

Constructor Details

#initialize(document, html_id) ⇒ SwaggerDocument

Returns a new instance of SwaggerDocument.



30
31
32
33
34
# File 'lib/apress/documentation/storage/swagger_document.rb', line 30

def initialize(document, html_id)
  @document = document
  @tag, @operation_id = html_id.split('_')
  @slug = document.slug + '/' + html_id
end

Instance Attribute Details

#documentObject (readonly)

Public: Ссылка на документ(Document) в котором записан данный SwaggerDocument



19
20
21
# File 'lib/apress/documentation/storage/swagger_document.rb', line 19

def document
  @document
end

#operation_idObject (readonly) Also known as: title

Public: tag и openperation_id для SwaggerUI



21
22
23
# File 'lib/apress/documentation/storage/swagger_document.rb', line 21

def operation_id
  @operation_id
end

#tagObject (readonly)

Public: tag и openperation_id для SwaggerUI



21
22
23
# File 'lib/apress/documentation/storage/swagger_document.rb', line 21

def tag
  @tag
end

Instance Method Details

#as_json(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/apress/documentation/storage/swagger_document.rb', line 43

def as_json(options = {})
  json = super(options)

  json[:slug] = slug

  if view = options[:view]
    json[:depends_on] = Apress::Documentation::DependencyPresenter.new(view, self).render_deps
    json[:consumers] = Apress::Documentation::DependencyPresenter.new(view, self).render_deps(reverse: true)
  end

  json
end

#current_moduleObject



56
57
58
# File 'lib/apress/documentation/storage/swagger_document.rb', line 56

def current_module
  Apress::Documentation::Storage::Modules.instance[document.slug.to_s.split('/').first]
end

#swagger_classObject



36
37
38
39
40
41
# File 'lib/apress/documentation/storage/swagger_document.rb', line 36

def swagger_class
  return @swagger_class if defined?(@swagger_class)
  @swagger_class = Class.new(Apress::Documentation::Swagger::Schema)
  @swagger_class.document_slug = document.slug
  @swagger_class
end