Class: Rspec::Autoswagger::Parts::Definition
- Inherits:
-
Object
- Object
- Rspec::Autoswagger::Parts::Definition
- Defined in:
- lib/rspec/autoswagger/parts/definition.rb
Constant Summary collapse
- DEFAULT_OUTPUT_PATH =
'./tmp'
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#response_name ⇒ Object
readonly
Returns the value of attribute response_name.
Instance Method Summary collapse
- #generate_definitions ⇒ Object
- #generate_hash_and_file ⇒ Object
- #generate_model_definitions ⇒ Object
- #generate_response_definitions ⇒ Object
-
#initialize(json, response_name, output_path) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(json, response_name, output_path) ⇒ Definition
Returns a new instance of Definition.
11 12 13 14 15 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 11 def initialize(json, response_name, output_path) @json = json @response_name = response_name @output_path = output_path end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
8 9 10 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 8 def json @json end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
8 9 10 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 8 def output_path @output_path end |
#response_name ⇒ Object (readonly)
Returns the value of attribute response_name.
8 9 10 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 8 def response_name @response_name end |
Instance Method Details
#generate_definitions ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 29 def generate_definitions model_hash = generate_model_definitions response_hash = generate_response_definitions response_hash.merge!(model_hash) response_hash end |
#generate_hash_and_file ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 36 def generate_hash_and_file @definition_hash ||= SwaggerModel::SwaggerV2.create_from_json( json_string: json, output_path: (output_path || DEFAULT_OUTPUT_PATH), response_name: response_name ) end |
#generate_model_definitions ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 17 def generate_model_definitions model_definition_hash = {} generate_hash_and_file['models'].each do |key, value| model_definition_hash.merge!(value) end model_definition_hash end |
#generate_response_definitions ⇒ Object
25 26 27 |
# File 'lib/rspec/autoswagger/parts/definition.rb', line 25 def generate_response_definitions generate_hash_and_file['responses'] end |