Class: Rspec::Autoswagger::Parts::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/autoswagger/parts/definition.rb

Constant Summary collapse

DEFAULT_OUTPUT_PATH =
'./tmp'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#jsonObject (readonly)

Returns the value of attribute json.



8
9
10
# File 'lib/rspec/autoswagger/parts/definition.rb', line 8

def json
  @json
end

#output_pathObject (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_nameObject (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_definitionsObject



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_fileObject



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_definitionsObject



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_definitionsObject



25
26
27
# File 'lib/rspec/autoswagger/parts/definition.rb', line 25

def generate_response_definitions
  generate_hash_and_file['responses']
end