Class: R2OAS::Schema::V3::Components::RequestBodyObject

Inherits:
Dynamic::Schema::V3::HookableBaseObject show all
Defined in:
lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb

Instance Attribute Summary

Attributes inherited from Dynamic::Schema::V3::HookableBaseObject

#doc

Instance Method Summary collapse

Methods inherited from Dynamic::Schema::V3::HookableBaseObject

execute_hook, has_hook?, hook, hook=, hooks, inherited, off, on, #use_superclass_hook

Methods inherited from BaseObject

#components_object_class, #components_request_body_object_class, #components_schema_object_class, #external_document_object_class, #info_object_class, #path_item_object_class, #paths_object_class

Constructor Details

#initialize(route_data, path, opts = {}) ⇒ RequestBodyObject

Returns a new instance of RequestBodyObject.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb', line 11

def initialize(route_data, path, opts = {})
  super(opts)
  @path_comp   = Routing::PathComponent.new(path)
  @path        = @path_comp.symbol_to_brace
  @route_data  = route_data
  @verb        = route_data[:verb]
  @tag_name    = route_data[:tag_name]
  @schema_name = route_data[:schema_name]
  # MEMO:
  # Allow primitive types that cannot be passed by reference to be passed by reference
  # This is Compromise
  @ref         = { schema_name: @schema_name, tag_name: @tag_name, verb: @verb }
end

Instance Method Details

#components_request_body_name(_doc, _path_component, _tag_name, _verb, schema_name) ⇒ Object

MEMO: please override in inherited class.



60
61
62
# File 'lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb', line 60

def components_request_body_name(_doc, _path_component, _tag_name, _verb, schema_name)
  schema_name
end

#components_schema_name(_doc, _path_component, _tag_name, _verb, schema_name) ⇒ Object

MEMO: please override in inherited class.



54
55
56
# File 'lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb', line 54

def components_schema_name(_doc, _path_component, _tag_name, _verb, schema_name)
  schema_name
end

#generate?Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb', line 64

def generate?
  file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
  (@verb.in? http_methods_when_generate_request_body) && !file_manager.skip_save?
end

#to_docObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb', line 25

def to_doc
  execute_before_create(@schema_name)
  create_doc do
    child_file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
    schema_object = components_schema_object_class.new(@route_data, @path, @opts)

    unless child_file_manager.skip_save?
      result = {
        'components' => {
          'schemas' => {
            _components_schema_name => schema_object.to_doc
          }
        }
      }
      doc.deep_merge!(
        'has_one' => {
          'type' => 'schema',
          'original_path' => child_file_manager.original_path,
          'data' => result
        }
      )
    end
  end
  execute_after_create(@schema_name)
  doc
end