Class: OasCore::Spec::Components
- Inherits:
-
Object
- Object
- OasCore::Spec::Components
- Includes:
- Specable
- Defined in:
- lib/oas_core/spec/components.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#examples ⇒ Object
Returns the value of attribute examples.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#links ⇒ Object
Returns the value of attribute links.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#request_bodies ⇒ Object
Returns the value of attribute request_bodies.
-
#responses ⇒ Object
Returns the value of attribute responses.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
-
#security_schemes ⇒ Object
Returns the value of attribute security_schemes.
Instance Method Summary collapse
- #add_example(example) ⇒ Object
- #add_parameter(parameter) ⇒ Object
- #add_request_body(request_body) ⇒ Object
- #add_response(response) ⇒ Object
- #add_schema(schema) ⇒ Object
- #create_reference(type, name) ⇒ Object
- #example_reference(name) ⇒ Object
-
#initialize(specification) ⇒ Components
constructor
A new instance of Components.
- #parameter_reference(name) ⇒ Object
- #request_body_reference(name) ⇒ Object
- #response_reference(name) ⇒ Object
- #schema_reference(name) ⇒ Object
- #to_spec ⇒ Object
Methods included from Specable
Constructor Details
#initialize(specification) ⇒ Components
Returns a new instance of Components.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/oas_core/spec/components.rb', line 11 def initialize(specification) @specification = specification @schemas = {} @parameters = {} @security_schemes = OasCore.config.security_schemas @request_bodies = {} @responses = {} @headers = {} @examples = {} @links = {} @callbacks = {} end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def callbacks @callbacks end |
#examples ⇒ Object
Returns the value of attribute examples.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def examples @examples end |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def headers @headers end |
#links ⇒ Object
Returns the value of attribute links.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def links @links end |
#parameters ⇒ Object
Returns the value of attribute parameters.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def parameters @parameters end |
#request_bodies ⇒ Object
Returns the value of attribute request_bodies.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def request_bodies @request_bodies end |
#responses ⇒ Object
Returns the value of attribute responses.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def responses @responses end |
#schemas ⇒ Object
Returns the value of attribute schemas.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def schemas @schemas end |
#security_schemes ⇒ Object
Returns the value of attribute security_schemes.
8 9 10 |
# File 'lib/oas_core/spec/components.rb', line 8 def security_schemes @security_schemes end |
Instance Method Details
#add_example(example) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/oas_core/spec/components.rb', line 66 def add_example(example) key = Hashable.generate_hash(example) @examples[key] = example if @examples[key].nil? example_reference(key) end |
#add_parameter(parameter) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/oas_core/spec/components.rb', line 45 def add_parameter(parameter) key = parameter.hash_key @parameters[key] = parameter unless @parameters.key? key parameter_reference(key) end |
#add_request_body(request_body) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/oas_core/spec/components.rb', line 52 def add_request_body(request_body) key = request_body.hash_key @request_bodies[key] = request_body unless @request_bodies.key? key request_body_reference(key) end |
#add_response(response) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/oas_core/spec/components.rb', line 38 def add_response(response) key = response.hash_key @responses[key] = response unless @responses.key? key response_reference(key) end |
#add_schema(schema) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/oas_core/spec/components.rb', line 59 def add_schema(schema) key = Hashable.generate_hash(schema) @schemas[key] = schema if @schemas[key].nil? schema_reference(key) end |
#create_reference(type, name) ⇒ Object
73 74 75 |
# File 'lib/oas_core/spec/components.rb', line 73 def create_reference(type, name) "#/components/#{type}/#{name}" end |
#example_reference(name) ⇒ Object
89 90 91 |
# File 'lib/oas_core/spec/components.rb', line 89 def example_reference(name) Reference.new(create_reference('examples', name)) end |
#parameter_reference(name) ⇒ Object
85 86 87 |
# File 'lib/oas_core/spec/components.rb', line 85 def parameter_reference(name) Reference.new(create_reference('parameters', name)) end |
#request_body_reference(name) ⇒ Object
93 94 95 |
# File 'lib/oas_core/spec/components.rb', line 93 def request_body_reference(name) Reference.new(create_reference('requestBodies', name)) end |
#response_reference(name) ⇒ Object
81 82 83 |
# File 'lib/oas_core/spec/components.rb', line 81 def response_reference(name) Reference.new(create_reference('responses', name)) end |
#schema_reference(name) ⇒ Object
77 78 79 |
# File 'lib/oas_core/spec/components.rb', line 77 def schema_reference(name) Reference.new(create_reference('schemas', name)) end |
#to_spec ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/oas_core/spec/components.rb', line 24 def to_spec { schemas: @schemas, responses: @responses.transform_values(&:to_spec), parameters: @parameters.transform_values(&:to_spec), requestBodies: @request_bodies.transform_values(&:to_spec), securitySchemes: @security_schemes, headers: @headers.transform_values(&:to_spec), examples: @examples, links: @links.transform_values(&:to_spec), callbacks: @callbacks.transform_values(&:to_spec) }.compact end |