Class: OasRails::Spec::Components
- Inherits:
-
Object
- Object
- OasRails::Spec::Components
- Includes:
- Specable
- Defined in:
- lib/oas_rails/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.
- #oas_fields ⇒ Object
- #parameter_reference(name) ⇒ Object
- #request_body_reference(name) ⇒ Object
- #response_reference(name) ⇒ Object
- #schema_reference(name) ⇒ Object
Methods included from Specable
Constructor Details
#initialize(specification) ⇒ Components
Returns a new instance of Components.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/oas_rails/spec/components.rb', line 8 def initialize(specification) @specification = specification @schemas = {} @parameters = {} @security_schemes = OasRails.config.security_schemas @request_bodies = {} @responses = {} @headers = {} @examples = {} @links = {} @callbacks = {} end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def callbacks @callbacks end |
#examples ⇒ Object
Returns the value of attribute examples.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def examples @examples end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def headers @headers end |
#links ⇒ Object
Returns the value of attribute links.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def links @links end |
#parameters ⇒ Object
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def parameters @parameters end |
#request_bodies ⇒ Object
Returns the value of attribute request_bodies.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def request_bodies @request_bodies end |
#responses ⇒ Object
Returns the value of attribute responses.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def responses @responses end |
#schemas ⇒ Object
Returns the value of attribute schemas.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def schemas @schemas end |
#security_schemes ⇒ Object
Returns the value of attribute security_schemes.
6 7 8 |
# File 'lib/oas_rails/spec/components.rb', line 6 def security_schemes @security_schemes end |
Instance Method Details
#add_example(example) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/oas_rails/spec/components.rb', line 53 def add_example(example) key = Hashable.generate_hash(example) @examples[key] = example if @examples[key].nil? example_reference(key) end |
#add_parameter(parameter) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/oas_rails/spec/components.rb', line 32 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
39 40 41 42 43 44 |
# File 'lib/oas_rails/spec/components.rb', line 39 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
25 26 27 28 29 30 |
# File 'lib/oas_rails/spec/components.rb', line 25 def add_response(response) key = response.hash_key @responses[key] = response unless @responses.key? key response_reference(key) end |
#add_schema(schema) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/oas_rails/spec/components.rb', line 46 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
60 61 62 |
# File 'lib/oas_rails/spec/components.rb', line 60 def create_reference(type, name) "#/components/#{type}/#{name}" end |
#example_reference(name) ⇒ Object
76 77 78 |
# File 'lib/oas_rails/spec/components.rb', line 76 def example_reference(name) Reference.new(create_reference('examples', name)) end |
#oas_fields ⇒ Object
21 22 23 |
# File 'lib/oas_rails/spec/components.rb', line 21 def oas_fields [:request_bodies, :examples, :responses, :schemas, :parameters, :security_schemes] end |
#parameter_reference(name) ⇒ Object
72 73 74 |
# File 'lib/oas_rails/spec/components.rb', line 72 def parameter_reference(name) Reference.new(create_reference('parameters', name)) end |
#request_body_reference(name) ⇒ Object
80 81 82 |
# File 'lib/oas_rails/spec/components.rb', line 80 def request_body_reference(name) Reference.new(create_reference('requestBodies', name)) end |