Class: OpenApi::DSL::Components
- Inherits:
-
Hash
- Object
- Hash
- OpenApi::DSL::Components
show all
- Includes:
- Helpers
- Defined in:
- lib/open_api/dsl/components.rb
Instance Method Summary
collapse
-
#api_key(scheme_name, field:, in: 'header', **other_info) ⇒ Object
-
#base_auth(scheme_name, other_info = { }) ⇒ Object
-
#bearer_auth(scheme_name, format = 'JWT', other_info = { }) ⇒ Object
-
#example(component_key, examples_hash) ⇒ Object
-
#initialize ⇒ Components
constructor
A new instance of Components.
-
#param(component_key, param_type, name, type, required, schema = { }) ⇒ Object
-
#process_objs ⇒ Object
-
#request_body(component_key, required, media_type, data: { }, desc: '', **options) ⇒ Object
-
#response(component_key, desc, media_type = nil, headers: { }, data: { }, **options) ⇒ Object
(also: #resp, #error)
-
#schema(component_key, type = nil, **schema) ⇒ Object
-
#security_scheme(scheme_name, other_info) ⇒ Object
(also: #auth_scheme)
{ }.
Methods included from Helpers
#_combined_schema, #arrow_writing_support, #process_schema_input
Constructor Details
Returns a new instance of Components.
10
11
12
|
# File 'lib/open_api/dsl/components.rb', line 10
def initialize
merge!(i[ schemas responses parameters examples requestBodies securitySchemes ].map { |k| [ k, { } ] }.to_h)
end
|
Instance Method Details
#api_key(scheme_name, field:, in: 'header', **other_info) ⇒ Object
83
84
85
|
# File 'lib/open_api/dsl/components.rb', line 83
def api_key scheme_name, field:, in: 'header', **other_info
security_scheme scheme_name, { type: 'apiKey', name: field, in: binding.local_variable_get(:in), **other_info }
end
|
#base_auth(scheme_name, other_info = { }) ⇒ Object
71
72
73
|
# File 'lib/open_api/dsl/components.rb', line 71
def base_auth scheme_name, other_info = { }
security_scheme scheme_name, { type: 'http', scheme: 'basic', **other_info }
end
|
#bearer_auth(scheme_name, format = 'JWT', other_info = { }) ⇒ Object
77
78
79
|
# File 'lib/open_api/dsl/components.rb', line 77
def bearer_auth scheme_name, format = 'JWT', other_info = { }
security_scheme scheme_name, { type: 'http', scheme: 'bearer', bearerFormat: format, **other_info }
end
|
#example(component_key, examples_hash) ⇒ Object
21
22
23
|
# File 'lib/open_api/dsl/components.rb', line 21
def example component_key, examples_hash
self[:examples][component_key] = ExampleObj.new(examples_hash, multiple: true).process
end
|
#param(component_key, param_type, name, type, required, schema = { }) ⇒ Object
27
28
29
30
|
# File 'lib/open_api/dsl/components.rb', line 27
def param component_key, param_type, name, type, required, schema = { }
return unless (schema = process_schema_input(type, schema, name))
self[:parameters][component_key] = ParamObj.new(name, param_type, type, required, schema).process
end
|
#process_objs ⇒ Object
89
90
91
92
93
|
# File 'lib/open_api/dsl/components.rb', line 89
def process_objs
self[:requestBodies].each { |key, body| self[:requestBodies][key] = body.process }
self[:responses].each { |code, response| self[:responses][code] = response.process }
self.delete_if { |_, v| v.blank? }
end
|
#request_body(component_key, required, media_type, data: { }, desc: '', **options) ⇒ Object
39
40
41
|
# File 'lib/open_api/dsl/components.rb', line 39
def request_body component_key, required, media_type, data: { }, desc: '', **options
(self[:requestBodies][component_key] ||= RequestBodyObj.new(required, desc)).absorb(media_type, { data: data, **options })
end
|
#response(component_key, desc, media_type = nil, headers: { }, data: { }, **options) ⇒ Object
Also known as:
resp, error
52
53
54
|
# File 'lib/open_api/dsl/components.rb', line 52
def response component_key, desc, media_type = nil, headers: { }, data: { }, **options
(self[:responses][component_key] ||= ResponseObj.new(desc)).absorb(desc, media_type, headers: , data: data, **options)
end
|
#schema(component_key, type = nil, **schema) ⇒ Object
14
15
16
17
|
# File 'lib/open_api/dsl/components.rb', line 14
def schema component_key, type = nil, **schema
return unless (schema = process_schema_input(type, schema, component_key))
self[:schemas][component_key.to_s.to_sym] = schema.process
end
|
#security_scheme(scheme_name, other_info) ⇒ Object
Also known as:
auth_scheme
62
63
64
65
|
# File 'lib/open_api/dsl/components.rb', line 62
def security_scheme scheme_name, other_info
other_info[:description] = other_info.delete(:desc) if other_info[:desc]
self[:securitySchemes][scheme_name] = other_info
end
|