Class: GrapeSwagger::DocMethods::FormatData
- Inherits:
-
Object
- Object
- GrapeSwagger::DocMethods::FormatData
- Defined in:
- lib/grape-swagger/doc_methods/format_data.rb
Class Method Summary collapse
- .add_array(parameter, related_parameters) ⇒ Object
- .add_braces(parameter, related_parameters) ⇒ Object
- .move_down(parameter, related_parameters) ⇒ Object
- .to_format(parameters) ⇒ Object
Class Method Details
.add_array(parameter, related_parameters) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grape-swagger/doc_methods/format_data.rb', line 36 def add_array(parameter, ) .each do |p| next if p.key?(:items) p_type = p[:type] == 'array' ? 'string' : p[:type] p[:items] = { type: p_type, format: p[:format], enum: p[:enum], is_array: p[:is_array] } p[:items].delete_if { |_k, v| v.nil? } p[:type] = 'array' p[:is_array] = parameter[:is_array] p.delete(:format) p.delete(:enum) p.delete_if { |_k, v| v.nil? } end end |
.add_braces(parameter, related_parameters) ⇒ Object
31 32 33 34 |
# File 'lib/grape-swagger/doc_methods/format_data.rb', line 31 def add_braces(parameter, ) param_name = parameter[:name].gsub(/\A(.*)\[\]\z/, '\1') .each { |p| p[:name] = p[:name].gsub(param_name, "#{param_name}[]") } end |
.move_down(parameter, related_parameters) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/grape-swagger/doc_methods/format_data.rb', line 17 def move_down(parameter, ) case parameter[:type] when 'array' add_array(parameter, ) unless .blank? add_braces(parameter, ) if parameter[:name].match?(/\A.*\[\]\z/) return true end when 'object' return true end false end |
.to_format(parameters) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/grape-swagger/doc_methods/format_data.rb', line 7 def to_format(parameters) parameters.reject { |parameter| parameter[:in] == 'body' }.each do |b| = parameters.select do |p| p[:name] != b[:name] && p[:name].to_s.start_with?("#{b[:name].to_s.gsub(/\[\]\z/, '')}[") end parameters.reject! { |p| p[:name] == b[:name] } if move_down(b, ) end parameters end |