@@ -9,56 +9,57 @@ module Elasticsearch
99<%- end -%>
1010<%= ' '*(@namespace_depth+2) %> module Actions
1111<%- if @spec['documentation']['description'] %>
12- <%= ' '*(@namespace_depth+3) %> # <%= @spec['documentation']['description'].gsub("\n", "\n#{' '*(@namespace_depth+3)}# ") %>
12+ <%= ' '*(@namespace_depth+3) %> # <%= @spec['documentation']['description'].gsub("\n", "\n#{' '*(@namespace_depth+3)}# ") %>
1313<%- else %>
14- <%= ' '*(@namespace_depth+3) %> # TODO: Description % >
14+ <%= ' '*(@namespace_depth+3) %> # TODO: Description
1515<%- end %>
1616<%= ' '*(@namespace_depth+3) %> #
1717<%- unless @parts.nil? || @parts.empty? %> <%# URL parts -%>
18- <%- @parts . each do |name , info | -%>
19- <%- info [ 'type' ] = 'String' if info [ 'type' ] == 'enum' # Rename 'enums' to 'strings' -%>
20- <%= ' '*(@namespace_depth+3) + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" + ( info['required'] ? ' (*Required*)' : '' ) -%>
21- <%= " (options: #{info['options'].join(', '.strip)})" if info['options'] -%>
22- <%= "\n" -%>
23- <%- end -%>
18+ <%- @parts.each do |name, info| -%>
19+ <%- info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings' -%>
20+ <%= ' '*(@namespace_depth+3) + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" + ( info['required'] ? ' (*Required*)' : '' ) -%>
21+ <%= " (options: #{info['options'].join(', '.strip)})" if info['options'] -%>
22+ <%= "\n" -%>
23+ <%- end -%>
2424<%- end -%> <%# Body -%>
2525<%= ' '*(@namespace_depth+3) + '# @option arguments [Hash] :body ' + (@spec['body']['description'] ? @spec['body']['description'].strip : 'TODO: Description') + (@spec['body']['required'] ? ' (*Required*)' : '') + "\n" if @spec['body'] -%>
2626
2727<%# URL parameters -%>
2828<%- @params.each do |name,info| -%>
29- <%- info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings' -%>
30- <%= ' '*(@namespace_depth+5) + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" -%>
31- <%= ' '*(@namespace_depth+5) +" (options: #{info['options'].join(', ')})" if info['options'] -%>
32- <%= "\n" -%>
29+ <%- info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings' -%>
30+ <%= ' '*(@namespace_depth+5) + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" -%>
31+ <%= ' '*(@namespace_depth+5) +" (options: #{info['options'].join(', ')})" if info['options'] -%>
32+ <%= "\n" -%>
3333<%- end if @spec['url']['parts'] -%>
3434<%= ' '*(@namespace_depth+3) -%> #
3535<%# Documentation link -%>
3636<%= ' '*(@namespace_depth+3) %> # @see <%= @spec['documentation']['url'] ? @spec['documentation']['url'] : "[TODO]" %>
3737<%= ' '*(@namespace_depth+3) %> #
3838<%# Method definition -%>
3939<%= ' '*(@namespace_depth+3) -%> def <%= @method_name %> (arguments={})
40- <%# Arguments -%>
40+ <%- @required_parts.each do |required| %> <%# Arguments -%>
41+ <%= ' '*(@namespace_depth+4) + "raise ArgumentError, \"Required argument '#{required}' missing\" unless arguments[:#{required}]" + "\n" -%>
42+ <%- end -%>
4143<%= ' '*(@namespace_depth+4) %> arguments = arguments.clone
4244<%- @parts.each do |name, info| %>
43- <%- if info['required'] %>
44- <%= ' '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument '#{name}' missing\" unless arguments[:#{name}]" + "\n" -%>
45- <%- end -%>
46- <%= ' '*(@namespace_depth+4) + "_#{name}" %> = arguments.delete(:<%= name %> )
47- <%- end -%>
48- <%- if @spec['body'] && @spec['body']['required'] -%>
49- <%= ' '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument 'body' missing\" unless arguments[:body]" + "\n" -%>
45+ <%= ' '*(@namespace_depth+3) + "_#{name}" %> = arguments.delete(:<%= name %> )
5046<%- end -%>
5147
48+ <%# This is where I need to check what's available %>
5249<%= ' '*(@namespace_depth+4) %> method = <%= @http_method %>
53- <%= ' '*(@namespace_depth+4) %> path = Utils.__pathify " <%= @http_path %> " <%= @http_path_params %>
50+ <%= ' '*(@namespace_depth+4) %> path = <%= @http_path %>
5451<%- unless @params.empty? -%>
55- <%= ' '*(@namespace_depth+4) %> params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
52+ <%= ' '*(@namespace_depth+4) %> params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
5653<%- else -%>
57- <%= ' '*(@namespace_depth+4) %> params = {}
54+ <%= ' '*(@namespace_depth+4) %> params = {}
5855<%- end -%>
5956<%= ' '*(@namespace_depth+4) %> body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %>
6057<%# Perform request %>
61- <%= ' '*(@namespace_depth+4) %> perform_request(method, path, params, body).body
58+ <% if ['bulk', 'msearch', 'msearch_template'].include? @method_name %>
59+ <%= ' '*(@namespace_depth+3) %> perform_request(method, path, params, body, {"Content-Type" => "application/x-ndjson"}).body
60+ <% else %>
61+ <%= ' '*(@namespace_depth+3) %> perform_request(method, path, params, body).body
62+ <% end %>
6263<%= ' '*(@namespace_depth+3) %> end
6364
6465<%# Method, path, params, body -%>
@@ -68,7 +69,7 @@ module Elasticsearch
6869<%= ' '*(@namespace_depth+3) %> # @since 6.2.0
6970<%- unless @params.empty? -%>
7071<%= ' '*(@namespace_depth+3) %> ParamsRegistry.register(:<%= @method_name %> , [
71- <%= ' '*(@namespace_depth+4) %> <%= @params.keys.map { |k| ":#{k}" }.join(",\n#{' '*(@namespace_depth+5 )}") %>
72+ <%= ' '*(@namespace_depth+4) %> <%= @params.keys.map { |k| ":#{k}" }.join(",\n#{' '*(@namespace_depth+4 )}") %>
7273<%= ' '*(@namespace_depth+3) %> ].freeze)
7374<%- end -%>
7475
0 commit comments