|
3 | 3 | # See the LICENSE file in the project root for more information |
4 | 4 |
|
5 | 5 | module Elasticsearch |
6 | | - module API |
7 | | - <%- @module_namespace.each_with_index do |name, i| -%> |
8 | | - <%= ' '*i %>module <%= name == 'xpack' ? 'XPack' : name.capitalize %> |
9 | | - <%- end -%> |
10 | | - <%= ' '*@namespace_depth %>module Actions |
11 | | - |
12 | | - <%= ' '*@namespace_depth %># <%= @spec['description'] || 'TODO: Description' %> |
13 | | - <%= ' '*@namespace_depth %># |
14 | | -<%# URL parts -%> |
15 | | - <%- @spec['url']['parts'].each do |name,info| -%> |
16 | | - <%- info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings' -%> |
17 | | - <%= ' '*@namespace_depth + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" + ( info['required'] ? ' (*Required*)' : '' ) -%><%= " (options: #{info['options'].join(', '.strip)})" if info['options'] -%> |
18 | | - <%= "\n" -%> |
19 | | - <%- end -%> |
20 | | -<%# Body -%> |
| 6 | +<%= ' '*(@namespace_depth+1) %>module API |
| 7 | +<%- @module_namespace.each_with_index do |name, i| -%> |
| 8 | + <%= ' '*i %>module <%= name == 'xpack' ? 'XPack' : name.capitalize %> |
| 9 | +<%- end -%> |
| 10 | +<%= ' '*(@namespace_depth+2) %>module Actions |
| 11 | +<%- if @spec['documentation']['description'] %> |
| 12 | +<%= ' '*(@namespace_depth+3) %># <%= @spec['documentation']['description'].gsub("\n", "\n#{' '*(@namespace_depth+3)}# ") %> |
| 13 | +<%- else %> |
| 14 | +<%= ' '*(@namespace_depth+3) %># TODO: Description %> |
| 15 | +<%- end %> |
| 16 | +<%= ' '*(@namespace_depth+3) %># |
| 17 | +<%- 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 -%> |
| 24 | +<%- end -%><%# Body -%> |
21 | 25 | <%= ' '*(@namespace_depth+3) + '# @option arguments [Hash] :body ' + (@spec['body']['description'] ? @spec['body']['description'].strip : 'TODO: Description') + (@spec['body']['required'] ? ' (*Required*)' : '') + "\n" if @spec['body'] -%> |
| 26 | +
|
22 | 27 | <%# URL parameters -%> |
23 | | - <%- @spec['url']['params'].each do |name,info| -%> |
24 | | - <%- info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings' -%> |
25 | | - <%= ' '*@namespace_depth + "# @option arguments [#{info['type'] ? info['type'].capitalize : 'String'}] :#{name} #{info['description'] ? info['description'].strip : '[TODO]'}" -%><%= " (options: #{info['options'].join(', ')})" if info['options'] -%> |
26 | | - <%= "\n" -%> |
27 | | - <%- end if @spec['url']['parts'] -%> |
28 | | - <%= ' '*@namespace_depth -%># |
| 28 | +<%- @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" -%> |
| 33 | +<%- end if @spec['url']['parts'] -%> |
| 34 | +<%= ' '*(@namespace_depth+3) -%># |
29 | 35 | <%# Documentation link -%> |
30 | | - <%= ' '*@namespace_depth %># @see <%= @spec['documentation'] ? @spec['documentation'] : "[TODO]" %> |
31 | | - <%= ' '*@namespace_depth %># |
| 36 | +<%= ' '*(@namespace_depth+3) %># @see <%= @spec['documentation']['url'] ? @spec['documentation']['url'] : "[TODO]" %> |
| 37 | +<%= ' '*(@namespace_depth+3) %># |
32 | 38 | <%# Method definition -%> |
33 | | - <%= ' '*@namespace_depth -%>def <%= @method_name %>(arguments={}) |
34 | | -<%# Required arguments -%> |
35 | | - <%- @spec['url']['parts'].select { |name, info| info['required'] }.each do |name, info| -%> |
36 | | - <%= ' '*(@namespace_depth+1) + "raise ArgumentError, \"Required argument '#{name}' missing\" unless arguments[:#{name}]" + "\n" -%> |
37 | | - <%- end -%> |
| 39 | +<%= ' '*(@namespace_depth+3) -%>def <%= @method_name %>(arguments={}) |
| 40 | +<%# Arguments -%> |
| 41 | +<%= ' '*(@namespace_depth+4) %>arguments = arguments.clone |
| 42 | +<%- @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 -%> |
38 | 48 | <%- if @spec['body'] && @spec['body']['required'] -%> |
39 | | - <%= ' '*(@namespace_depth+1) + "raise ArgumentError, \"Required argument 'body' missing\" unless arguments[:body]" + "\n" -%> |
| 49 | + <%= ' '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument 'body' missing\" unless arguments[:body]" + "\n" -%> |
40 | 50 | <%- end -%> |
41 | | -<%# Method, path, params, body -%> |
42 | | - <%- unless @spec['url']['params'].empty? -%> |
43 | | - <%= ' '*@namespace_depth %> valid_params = [ |
44 | | - <%= ' '*(@namespace_depth+2) %><%= @spec['url']['params'].keys.map { |k| ":#{k}" }.join(",\n#{' '*(@namespace_depth+5)}") %> ] |
45 | | - <%- end -%> |
46 | | - <%= ' '*@namespace_depth %> method = <%= @http_method %> |
47 | | - <%= ' '*@namespace_depth %> path = "<%= @http_path %>" |
48 | | - <%- unless @spec['url']['params'].empty? -%> |
49 | | - <%= ' '*@namespace_depth %> params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, valid_params |
50 | | - <%- else -%> |
51 | | - <%= ' '*@namespace_depth %> params = {} |
52 | | - <%- end -%> |
53 | | - <%= ' '*@namespace_depth %> body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %> |
| 51 | +
|
| 52 | +<%= ' '*(@namespace_depth+4) %>method = <%= @http_method %> |
| 53 | +<%= ' '*(@namespace_depth+4) %>path = Utils.__pathify "<%= @http_path %>"<%= @http_path_params %> |
| 54 | +<%- unless @params.empty? -%> |
| 55 | +<%= ' '*(@namespace_depth+4) %>params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) |
| 56 | +<%- else -%> |
| 57 | +<%= ' '*(@namespace_depth+4) %>params = {} |
| 58 | +<%- end -%> |
| 59 | +<%= ' '*(@namespace_depth+4) %>body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %> |
54 | 60 | <%# Perform request %> |
55 | | - <%= ' '*@namespace_depth %> perform_request(method, path, params, body).body |
56 | | - <%= ' '*@namespace_depth %>end |
57 | | - <%- @namespace_depth.downto(1) do |i| -%> |
58 | | - <%= ' '*(i-1) %>end |
59 | | - <%- end if @namespace_depth > 0 -%> |
| 61 | +<%= ' '*(@namespace_depth+4) %>perform_request(method, path, params, body).body |
| 62 | +<%= ' '*(@namespace_depth+3) %>end |
| 63 | +
|
| 64 | +<%# Method, path, params, body -%> |
| 65 | +
|
| 66 | +<%= ' '*(@namespace_depth+3) %># Register this action with its valid params when the module is loaded. |
| 67 | +<%= ' '*(@namespace_depth+3) %># |
| 68 | +<%= ' '*(@namespace_depth+3) %># @since 6.2.0 |
| 69 | +<%- unless @params.empty? -%> |
| 70 | +<%= ' '*(@namespace_depth+3) %>ParamsRegistry.register(:<%= @method_name %>, [ |
| 71 | +<%= ' '*(@namespace_depth+4) %><%= @params.keys.map { |k| ":#{k}" }.join(",\n#{' '*(@namespace_depth+5)}") %> |
| 72 | +<%= ' '*(@namespace_depth+3) %>].freeze) |
| 73 | +<%- end -%> |
| 74 | +
|
| 75 | +<%- @namespace_depth.downto(1) do |i| -%> |
| 76 | +<%= ' '*(i-1) %>end |
| 77 | +<%- end if @namespace_depth > 0 -%> |
60 | 78 | end |
61 | 79 | end |
62 | 80 | end |
0 commit comments