Class: OasRails::Spec::Components

Inherits:
Object
  • Object
show all
Includes:
Specable
Defined in:
lib/oas_rails/spec/components.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Specable

#as_json, #to_spec

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

#callbacksObject

Returns the value of attribute callbacks.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def callbacks
  @callbacks
end

#examplesObject

Returns the value of attribute examples.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def examples
  @examples
end

#headersObject

Returns the value of attribute headers.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def headers
  @headers
end

Returns the value of attribute links.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def links
  @links
end

#parametersObject

Returns the value of attribute parameters.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def parameters
  @parameters
end

#request_bodiesObject

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

#responsesObject

Returns the value of attribute responses.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def responses
  @responses
end

#schemasObject

Returns the value of attribute schemas.



6
7
8
# File 'lib/oas_rails/spec/components.rb', line 6

def schemas
  @schemas
end

#security_schemesObject

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_fieldsObject



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

#response_reference(name) ⇒ Object



68
69
70
# File 'lib/oas_rails/spec/components.rb', line 68

def response_reference(name)
  Reference.new(create_reference('responses', name))
end

#schema_reference(name) ⇒ Object



64
65
66
# File 'lib/oas_rails/spec/components.rb', line 64

def schema_reference(name)
  Reference.new(create_reference('schemas', name))
end