elasticsearch-api 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +16 -23
- data/elasticsearch-api.gemspec +1 -1
- data/lib/elasticsearch/api/actions/abort_benchmark.rb +1 -2
- data/lib/elasticsearch/api/actions/benchmark.rb +2 -3
- data/lib/elasticsearch/api/actions/bulk.rb +35 -68
- data/lib/elasticsearch/api/actions/cat/aliases.rb +30 -52
- data/lib/elasticsearch/api/actions/cat/allocation.rb +36 -50
- data/lib/elasticsearch/api/actions/cat/count.rb +25 -46
- data/lib/elasticsearch/api/actions/cat/fielddata.rb +31 -33
- data/lib/elasticsearch/api/actions/cat/health.rb +27 -37
- data/lib/elasticsearch/api/actions/cat/help.rb +14 -10
- data/lib/elasticsearch/api/actions/cat/indices.rb +45 -62
- data/lib/elasticsearch/api/actions/cat/master.rb +24 -34
- data/lib/elasticsearch/api/actions/cat/nodeattrs.rb +20 -16
- data/lib/elasticsearch/api/actions/cat/nodes.rb +34 -46
- data/lib/elasticsearch/api/actions/cat/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/cat/pending_tasks.rb +29 -35
- data/lib/elasticsearch/api/actions/cat/plugins.rb +21 -18
- data/lib/elasticsearch/api/actions/cat/recovery.rb +40 -56
- data/lib/elasticsearch/api/actions/cat/repositories.rb +21 -24
- data/lib/elasticsearch/api/actions/cat/segments.rb +29 -22
- data/lib/elasticsearch/api/actions/cat/shards.rb +38 -59
- data/lib/elasticsearch/api/actions/cat/snapshots.rb +32 -27
- data/lib/elasticsearch/api/actions/cat/tasks.rb +25 -19
- data/lib/elasticsearch/api/actions/cat/templates.rb +26 -18
- data/lib/elasticsearch/api/actions/cat/thread_pool.rb +36 -46
- data/lib/elasticsearch/api/actions/clear_scroll.rb +21 -8
- data/lib/elasticsearch/api/actions/cluster/allocation_explain.rb +15 -13
- data/lib/elasticsearch/api/actions/cluster/get_settings.rb +18 -18
- data/lib/elasticsearch/api/actions/cluster/health.rb +42 -44
- data/lib/elasticsearch/api/actions/cluster/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +15 -17
- data/lib/elasticsearch/api/actions/cluster/put_settings.rb +20 -17
- data/lib/elasticsearch/api/actions/cluster/remote_info.rb +8 -6
- data/lib/elasticsearch/api/actions/cluster/reroute.rb +25 -37
- data/lib/elasticsearch/api/actions/cluster/state.rb +37 -41
- data/lib/elasticsearch/api/actions/cluster/stats.rb +20 -12
- data/lib/elasticsearch/api/actions/count.rb +52 -39
- data/lib/elasticsearch/api/actions/create.rb +25 -26
- data/lib/elasticsearch/api/actions/delete.rb +43 -36
- data/lib/elasticsearch/api/actions/delete_by_query.rb +74 -62
- data/lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb +39 -0
- data/lib/elasticsearch/api/actions/delete_by_rethrottle.rb +4 -3
- data/lib/elasticsearch/api/actions/delete_script.rb +19 -13
- data/lib/elasticsearch/api/actions/exists.rb +44 -34
- data/lib/elasticsearch/api/actions/exists_source.rb +43 -25
- data/lib/elasticsearch/api/actions/explain.rb +46 -51
- data/lib/elasticsearch/api/actions/field_caps.rb +27 -20
- data/lib/elasticsearch/api/actions/get.rb +42 -41
- data/lib/elasticsearch/api/actions/get_script.rb +19 -14
- data/lib/elasticsearch/api/actions/get_source.rb +38 -44
- data/lib/elasticsearch/api/actions/index.rb +60 -89
- data/lib/elasticsearch/api/actions/indices/analyze.rb +19 -48
- data/lib/elasticsearch/api/actions/indices/clear_cache.rb +29 -41
- data/lib/elasticsearch/api/actions/indices/clone.rb +50 -0
- data/lib/elasticsearch/api/actions/indices/close.rb +28 -32
- data/lib/elasticsearch/api/actions/indices/create.rb +22 -70
- data/lib/elasticsearch/api/actions/indices/delete.rb +23 -35
- data/lib/elasticsearch/api/actions/indices/delete_alias.rb +24 -20
- data/lib/elasticsearch/api/actions/indices/delete_template.rb +18 -20
- data/lib/elasticsearch/api/actions/indices/exists.rb +32 -34
- data/lib/elasticsearch/api/actions/indices/exists_alias.rb +33 -29
- data/lib/elasticsearch/api/actions/indices/exists_template.rb +21 -16
- data/lib/elasticsearch/api/actions/indices/exists_type.rb +29 -29
- data/lib/elasticsearch/api/actions/indices/flush.rb +28 -28
- data/lib/elasticsearch/api/actions/indices/flush_synced.rb +23 -12
- data/lib/elasticsearch/api/actions/indices/forcemerge.rb +26 -41
- data/lib/elasticsearch/api/actions/indices/freeze.rb +7 -8
- data/lib/elasticsearch/api/actions/indices/get.rb +25 -19
- data/lib/elasticsearch/api/actions/indices/get_alias.rb +31 -23
- data/lib/elasticsearch/api/actions/indices/get_field_mapping.rb +42 -38
- data/lib/elasticsearch/api/actions/indices/get_mapping.rb +39 -31
- data/lib/elasticsearch/api/actions/indices/get_settings.rb +34 -37
- data/lib/elasticsearch/api/actions/indices/get_template.rb +21 -23
- data/lib/elasticsearch/api/actions/indices/get_upgrade.rb +48 -0
- data/lib/elasticsearch/api/actions/indices/open.rb +24 -21
- data/lib/elasticsearch/api/actions/indices/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/indices/put_alias.rb +25 -27
- data/lib/elasticsearch/api/actions/indices/put_mapping.rb +40 -39
- data/lib/elasticsearch/api/actions/indices/put_settings.rb +30 -37
- data/lib/elasticsearch/api/actions/indices/put_template.rb +23 -23
- data/lib/elasticsearch/api/actions/indices/recovery.rb +20 -23
- data/lib/elasticsearch/api/actions/indices/refresh.rb +22 -26
- data/lib/elasticsearch/api/actions/indices/rollover.rb +28 -19
- data/lib/elasticsearch/api/actions/indices/segments.rb +24 -17
- data/lib/elasticsearch/api/actions/indices/shard_stores.rb +27 -15
- data/lib/elasticsearch/api/actions/indices/shrink.rb +23 -17
- data/lib/elasticsearch/api/actions/indices/split.rb +23 -17
- data/lib/elasticsearch/api/actions/indices/stats.rb +53 -104
- data/lib/elasticsearch/api/actions/indices/unfreeze.rb +7 -7
- data/lib/elasticsearch/api/actions/indices/update_aliases.rb +15 -32
- data/lib/elasticsearch/api/actions/indices/upgrade.rb +26 -16
- data/lib/elasticsearch/api/actions/indices/validate_query.rb +46 -59
- data/lib/elasticsearch/api/actions/info.rb +9 -6
- data/lib/elasticsearch/api/actions/ingest/delete_pipeline.rb +18 -12
- data/lib/elasticsearch/api/actions/ingest/get_pipeline.rb +21 -11
- data/lib/elasticsearch/api/actions/ingest/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/ingest/processor_grok.rb +12 -13
- data/lib/elasticsearch/api/actions/ingest/put_pipeline.rb +19 -14
- data/lib/elasticsearch/api/actions/ingest/simulate.rb +23 -13
- data/lib/elasticsearch/api/actions/mget.rb +37 -44
- data/lib/elasticsearch/api/actions/msearch.rb +54 -54
- data/lib/elasticsearch/api/actions/msearch_template.rb +46 -35
- data/lib/elasticsearch/api/actions/mtermvectors.rb +39 -35
- data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +30 -25
- data/lib/elasticsearch/api/actions/nodes/info.rb +29 -63
- data/lib/elasticsearch/api/actions/nodes/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/nodes/reload_secure_settings.rb +24 -22
- data/lib/elasticsearch/api/actions/nodes/shutdown.rb +4 -4
- data/lib/elasticsearch/api/actions/nodes/stats.rb +43 -36
- data/lib/elasticsearch/api/actions/nodes/usage.rb +31 -10
- data/lib/elasticsearch/api/actions/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/ping.rb +12 -13
- data/lib/elasticsearch/api/actions/put_script.rb +26 -30
- data/lib/elasticsearch/api/actions/rank_eval.rb +24 -15
- data/lib/elasticsearch/api/actions/reindex.rb +25 -48
- data/lib/elasticsearch/api/actions/reindex_rethrottle.rb +18 -12
- data/lib/elasticsearch/api/actions/remote/info.rb +1 -2
- data/lib/elasticsearch/api/actions/render_search_template.rb +17 -15
- data/lib/elasticsearch/api/actions/scripts_painless_execute.rb +8 -6
- data/lib/elasticsearch/api/actions/scroll.rb +28 -51
- data/lib/elasticsearch/api/actions/search.rb +104 -165
- data/lib/elasticsearch/api/actions/search_shards.rb +31 -28
- data/lib/elasticsearch/api/actions/search_template.rb +48 -40
- data/lib/elasticsearch/api/actions/snapshot/cleanup_repository.rb +44 -0
- data/lib/elasticsearch/api/actions/snapshot/create.rb +22 -29
- data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +19 -24
- data/lib/elasticsearch/api/actions/snapshot/delete.rb +20 -22
- data/lib/elasticsearch/api/actions/snapshot/delete_repository.rb +16 -18
- data/lib/elasticsearch/api/actions/snapshot/get.rb +22 -31
- data/lib/elasticsearch/api/actions/snapshot/get_repository.rb +21 -25
- data/lib/elasticsearch/api/actions/snapshot/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/snapshot/restore.rb +21 -32
- data/lib/elasticsearch/api/actions/snapshot/status.rb +23 -24
- data/lib/elasticsearch/api/actions/snapshot/verify_repository.rb +18 -13
- data/lib/elasticsearch/api/actions/tasks/cancel.rb +19 -13
- data/lib/elasticsearch/api/actions/tasks/get.rb +16 -13
- data/lib/elasticsearch/api/actions/tasks/list.rb +20 -18
- data/lib/elasticsearch/api/actions/tasks/params_registry.rb +0 -1
- data/lib/elasticsearch/api/actions/termvectors.rb +52 -70
- data/lib/elasticsearch/api/actions/update.rb +53 -98
- data/lib/elasticsearch/api/actions/update_by_query.rb +77 -66
- data/lib/elasticsearch/api/actions/update_by_query_rethrottle.rb +17 -11
- data/lib/elasticsearch/api/version.rb +1 -1
- data/spec/elasticsearch/api/actions/cat/segments_spec.rb +9 -11
- data/spec/elasticsearch/api/actions/cluster/put_settings_spec.rb +1 -1
- data/spec/elasticsearch/api/actions/count_spec.rb +8 -8
- data/spec/elasticsearch/api/actions/delete_by_query_spec.rb +12 -7
- data/spec/elasticsearch/api/actions/delete_script_spec.rb +0 -14
- data/spec/elasticsearch/api/actions/exists_document_spec.rb +1 -1
- data/spec/elasticsearch/api/actions/get_document_source_spec.rb +1 -1
- data/spec/elasticsearch/api/actions/index_document_spec.rb +6 -15
- data/spec/elasticsearch/api/actions/indices/analyze_spec.rb +0 -4
- data/spec/elasticsearch/api/actions/indices/clear_cache_spec.rb +1 -5
- data/spec/elasticsearch/api/actions/indices/clone_spec.rb +109 -0
- data/spec/elasticsearch/api/actions/indices/delete_alias_spec.rb +2 -2
- data/spec/elasticsearch/api/actions/indices/get_spec.rb +0 -11
- data/spec/elasticsearch/api/actions/indices/put_alias_spec.rb +3 -3
- data/spec/elasticsearch/api/actions/indices/put_mapping_spec.rb +3 -3
- data/spec/elasticsearch/api/actions/indices/stats_spec.rb +0 -1
- data/spec/elasticsearch/api/actions/nodes/hot_threads_spec.rb +3 -3
- data/spec/elasticsearch/api/actions/put_script_spec.rb +20 -15
- data/spec/elasticsearch/api/actions/render_search_template_spec.rb +23 -7
- data/spec/elasticsearch/api/actions/scroll_spec.rb +37 -0
- data/spec/elasticsearch/api/actions/search_spec.rb +0 -15
- data/spec/elasticsearch/api/actions/tasks/list_spec.rb +0 -11
- data/spec/elasticsearch/api/actions/update_document_spec.rb +3 -7
- data/spec/elasticsearch/api/rest_api_yaml_spec.rb +1 -1
- data/spec/rest_yaml_tests_helper.rb +12 -0
- data/utils/Gemfile +1 -0
- data/utils/Thorfile +0 -1
- data/utils/thor/generate_source.rb +192 -85
- data/utils/thor/generator/endpoint_specifics.rb +157 -0
- data/utils/thor/generator/files_helper.rb +37 -0
- data/utils/thor/lister.rb +3 -4
- data/utils/thor/templates/_documentation_top.erb +27 -0
- data/utils/thor/templates/_method_setup.erb +35 -0
- data/utils/thor/templates/_params_registry.erb +12 -0
- data/utils/thor/templates/_perform_request.erb +37 -0
- data/utils/thor/templates/method.erb +59 -0
- data/utils/thor/templates/{ruby/test.erb → test.erb} +0 -0
- data/utils/thor/templates/{ruby/test_helper.rb → test_helper.rb} +0 -0
- metadata +31 -14
- data/spec/elasticsearch/api/actions/scoll_spec.rb +0 -21
- data/utils/thor/generate_api.rb +0 -193
- data/utils/thor/templates/ruby/method.erb +0 -62
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<%- if @endpoint_name == 'indices.stats' %>
|
|
2
|
+
method = HTTP_GET
|
|
3
|
+
parts = Utils.__extract_parts arguments, ParamsRegistry.get(:stats_parts)
|
|
4
|
+
path = Utils.__pathify Utils.__listify(arguments[:index]), '_stats', Utils.__listify(parts)
|
|
5
|
+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(:stats_params)
|
|
6
|
+
params[:fields] = Utils.__listify(params[:fields], :escape => false) if params[:fields]
|
|
7
|
+
params[:groups] = Utils.__listify(params[:groups], :escape => false) if params[:groups]
|
|
8
|
+
<%- else %>
|
|
9
|
+
<%= ' '*(@namespace_depth+4) %>arguments = arguments.clone
|
|
10
|
+
<%- if @method_name == 'mtermvectors' -%>
|
|
11
|
+
ids = arguments.delete(:ids)
|
|
12
|
+
<%- end -%>
|
|
13
|
+
<%- if @method_name == 'search' -%>
|
|
14
|
+
arguments[:index] = UNDERSCORE_ALL if ! arguments[:index] && arguments[:type]
|
|
15
|
+
<%- end -%>
|
|
16
|
+
<%- @parts.each do |name, _| %>
|
|
17
|
+
<%- unless @method_name == 'get_field_mapping' && name == 'fields' %>
|
|
18
|
+
<%= ' '*(@namespace_depth+3) + "_#{name}" %> = arguments.delete(:<%=name %>)
|
|
19
|
+
<%- end -%>
|
|
20
|
+
<%- end -%>
|
|
21
|
+
|
|
22
|
+
<%= ' '*(@namespace_depth+4) %>method = <%= @http_method %>
|
|
23
|
+
<%- if @method_name == 'termvectors' %>
|
|
24
|
+
endpoint = arguments.delete(:endpoint) || '_termvectors'
|
|
25
|
+
<%- end -%>
|
|
26
|
+
<%= ' '*(@namespace_depth+4) %>path = <%= @http_path %>
|
|
27
|
+
<%- unless @params.empty? -%>
|
|
28
|
+
<%= ' '*(@namespace_depth+4) %>params = <%= __utils %>.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
|
|
29
|
+
<%- else -%>
|
|
30
|
+
<%= ' '*(@namespace_depth+4) %>params = {}
|
|
31
|
+
<%- end -%>
|
|
32
|
+
<%- @specific_params.each do |param| -%>
|
|
33
|
+
<%= param %>
|
|
34
|
+
<%- end -%>
|
|
35
|
+
<%- end -%>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<%- unless @params.empty? -%>
|
|
2
|
+
<%= ' '*(@namespace_depth+3) %># Register this action with its valid params when the module is loaded.
|
|
3
|
+
<%= ' '*(@namespace_depth+3) %>#
|
|
4
|
+
<%= ' '*(@namespace_depth+3) %># @since 6.2.0
|
|
5
|
+
<%- if @endpoint_name == 'indices.stats' -%>
|
|
6
|
+
<%= indices_stats_params_registry %>
|
|
7
|
+
<%- else -%>
|
|
8
|
+
<%= ' '*(@namespace_depth+3) %>ParamsRegistry.register(:<%= @method_name %>, [
|
|
9
|
+
<%= ' '*(@namespace_depth+4) %><%= @params.keys.map { |k| ":#{k}" }.join(",\n#{' '*(@namespace_depth+4)}") %>
|
|
10
|
+
<%= ' '*(@namespace_depth+3) %>].freeze)
|
|
11
|
+
<%- end -%>
|
|
12
|
+
<%- end -%>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<%-
|
|
2
|
+
case @endpoint_name
|
|
3
|
+
when 'mtermvectors'
|
|
4
|
+
-%>
|
|
5
|
+
if ids
|
|
6
|
+
body = { :ids => ids }
|
|
7
|
+
else
|
|
8
|
+
body = arguments[:body]
|
|
9
|
+
end
|
|
10
|
+
<%- when 'cluster.reroute', 'cluster.put_settings' %>
|
|
11
|
+
body = arguments[:body] || {}
|
|
12
|
+
<%- when 'ml.find_file_structure' %>
|
|
13
|
+
body = <%= __utils %>.__bulkify(arguments.delete(:body))
|
|
14
|
+
<%- else -%>
|
|
15
|
+
<%= ' '*(@namespace_depth+3) %>body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %>
|
|
16
|
+
<%- end -%>
|
|
17
|
+
<%- if ['bulk', 'msearch', 'msearch_template'].include? @method_name -%>
|
|
18
|
+
<%= self.send("#{@method_name}_body_helper".to_s) %>
|
|
19
|
+
<%= ' '*(@namespace_depth+4) %>perform_request(method, path, params, payload, {"Content-Type" => "application/x-ndjson"}).body
|
|
20
|
+
<%- elsif @method_name == 'ping' -%>
|
|
21
|
+
<%= ping_perform_request %>
|
|
22
|
+
<%- else -%>
|
|
23
|
+
<%- if needs_ignore_404?(@endpoint_name) %>
|
|
24
|
+
<%= __utils %>.__rescue_from_not_found do
|
|
25
|
+
perform_request(method, path, params, body).status == 200 ? true : false
|
|
26
|
+
end
|
|
27
|
+
<%- elsif needs_complex_ignore_404?(@endpoint_name) -%>
|
|
28
|
+
if Array(arguments[:ignore]).include?(404)
|
|
29
|
+
<%= __utils %>.__rescue_from_not_found { perform_request(method, path, params, body).body }
|
|
30
|
+
else
|
|
31
|
+
perform_request(method, path, params, body).body
|
|
32
|
+
end
|
|
33
|
+
<%- else -%>
|
|
34
|
+
perform_request(method, path, params, body).body
|
|
35
|
+
<%- end -%>
|
|
36
|
+
<%- end -%>
|
|
37
|
+
<%= ' '*(@namespace_depth+3) %>end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
3
|
+
# See the LICENSE file in the project root for more information
|
|
4
|
+
|
|
5
|
+
module Elasticsearch
|
|
6
|
+
<%- if @xpack -%>
|
|
7
|
+
<%= ' '*(@namespace_depth) %>module XPack
|
|
8
|
+
<%- end %>
|
|
9
|
+
<%= ' '*(@namespace_depth) %>module API
|
|
10
|
+
<%- @module_namespace.each_with_index do |name, i| -%>
|
|
11
|
+
<%= ' '*i %>module <%= name.split("_").map(&:capitalize).join %>
|
|
12
|
+
<%- end -%>
|
|
13
|
+
<%= ' '*(@namespace_depth+2) %>module Actions
|
|
14
|
+
<%= ERB.new(File.new("./thor/templates/_documentation_top.erb").read, trim_mode: '-').result(binding) -%>
|
|
15
|
+
<%# Method definition -%>
|
|
16
|
+
<%= ' '*(@namespace_depth+3) -%>def <%= @method_name %>(arguments={})
|
|
17
|
+
<%- if @endpoint_name == 'create' -%>
|
|
18
|
+
<%= ' '*(@namespace_depth+3) %>if arguments[:id]
|
|
19
|
+
<%= ' '*(@namespace_depth+3) %> index arguments.update op_type: 'create'
|
|
20
|
+
<%= ' '*(@namespace_depth+3) %>else
|
|
21
|
+
<%= ' '*(@namespace_depth+3) %> index arguments
|
|
22
|
+
<%= ' '*(@namespace_depth+3) %>end
|
|
23
|
+
<%= ' '*(@namespace_depth+2) %>end
|
|
24
|
+
<%- else -%>
|
|
25
|
+
<%- if @method_name == 'get_field_mapping' %>
|
|
26
|
+
_fields = arguments.delete(:field) || arguments.delete(:fields)
|
|
27
|
+
raise ArgumentError, "Required argument 'field' missing" unless _fields
|
|
28
|
+
<%- else -%>
|
|
29
|
+
<%- @required_parts.each do |required| %><%# Arguments -%>
|
|
30
|
+
<%= ' '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument '#{required}' missing\" unless arguments[:#{required}]" + "\n" -%>
|
|
31
|
+
<%- end -%>
|
|
32
|
+
<%- end -%>
|
|
33
|
+
<%- # Method setup -%>
|
|
34
|
+
<%= ERB.new(File.new("./thor/templates/_method_setup.erb").read, trim_mode: '-').result(binding) %>
|
|
35
|
+
<%- # Perform request -%>
|
|
36
|
+
<%= ERB.new(File.new("./thor/templates/_perform_request.erb").read, trim_mode: '-').result(binding) %>
|
|
37
|
+
<%- end -%>
|
|
38
|
+
<%- if @method_name.match?(/^exists\S*/) -%>
|
|
39
|
+
alias_method :<%= @method_name %>?, :<%= @method_name %>
|
|
40
|
+
<%- end -%>
|
|
41
|
+
<%- if @method_name == 'termvectors' %>
|
|
42
|
+
|
|
43
|
+
# Deprecated: Use the plural version, {#termvectors}
|
|
44
|
+
#
|
|
45
|
+
def termvector(arguments={})
|
|
46
|
+
termvectors(arguments.merge endpoint: '_termvector')
|
|
47
|
+
end
|
|
48
|
+
<%- end -%>
|
|
49
|
+
<%# Params Registry Template -%>
|
|
50
|
+
<%- unless @endpoint_name == 'create' -%>
|
|
51
|
+
<%= ERB.new(File.new("./thor/templates/_params_registry.erb").read, trim_mode: '-').result(binding) %>
|
|
52
|
+
<%- end -%>
|
|
53
|
+
|
|
54
|
+
<%- @namespace_depth.downto(1) do |i| -%>
|
|
55
|
+
<%= ' '*(i-1) %>end
|
|
56
|
+
<%- end if @namespace_depth > 0 -%>
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
File without changes
|
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elasticsearch-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Karel Minarik
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: multi_json
|
|
@@ -266,16 +266,22 @@ dependencies:
|
|
|
266
266
|
name: simplecov
|
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
|
268
268
|
requirements:
|
|
269
|
-
- - "
|
|
269
|
+
- - "~>"
|
|
270
270
|
- !ruby/object:Gem::Version
|
|
271
|
-
version: '0'
|
|
271
|
+
version: '0.17'
|
|
272
|
+
- - "<"
|
|
273
|
+
- !ruby/object:Gem::Version
|
|
274
|
+
version: '0.18'
|
|
272
275
|
type: :development
|
|
273
276
|
prerelease: false
|
|
274
277
|
version_requirements: !ruby/object:Gem::Requirement
|
|
275
278
|
requirements:
|
|
276
|
-
- - "
|
|
279
|
+
- - "~>"
|
|
277
280
|
- !ruby/object:Gem::Version
|
|
278
|
-
version: '0'
|
|
281
|
+
version: '0.17'
|
|
282
|
+
- - "<"
|
|
283
|
+
- !ruby/object:Gem::Version
|
|
284
|
+
version: '0.18'
|
|
279
285
|
- !ruby/object:Gem::Dependency
|
|
280
286
|
name: simplecov-rcov
|
|
281
287
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -334,7 +340,7 @@ dependencies:
|
|
|
334
340
|
version: '2'
|
|
335
341
|
description: 'Ruby API for Elasticsearch. See the `elasticsearch` gem for full integration.
|
|
336
342
|
|
|
337
|
-
|
|
343
|
+
'
|
|
338
344
|
email:
|
|
339
345
|
- karel.minarik@elasticsearch.org
|
|
340
346
|
executables: []
|
|
@@ -390,6 +396,7 @@ files:
|
|
|
390
396
|
- lib/elasticsearch/api/actions/create.rb
|
|
391
397
|
- lib/elasticsearch/api/actions/delete.rb
|
|
392
398
|
- lib/elasticsearch/api/actions/delete_by_query.rb
|
|
399
|
+
- lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb
|
|
393
400
|
- lib/elasticsearch/api/actions/delete_by_rethrottle.rb
|
|
394
401
|
- lib/elasticsearch/api/actions/delete_script.rb
|
|
395
402
|
- lib/elasticsearch/api/actions/exists.rb
|
|
@@ -402,6 +409,7 @@ files:
|
|
|
402
409
|
- lib/elasticsearch/api/actions/index.rb
|
|
403
410
|
- lib/elasticsearch/api/actions/indices/analyze.rb
|
|
404
411
|
- lib/elasticsearch/api/actions/indices/clear_cache.rb
|
|
412
|
+
- lib/elasticsearch/api/actions/indices/clone.rb
|
|
405
413
|
- lib/elasticsearch/api/actions/indices/close.rb
|
|
406
414
|
- lib/elasticsearch/api/actions/indices/create.rb
|
|
407
415
|
- lib/elasticsearch/api/actions/indices/delete.rb
|
|
@@ -421,6 +429,7 @@ files:
|
|
|
421
429
|
- lib/elasticsearch/api/actions/indices/get_mapping.rb
|
|
422
430
|
- lib/elasticsearch/api/actions/indices/get_settings.rb
|
|
423
431
|
- lib/elasticsearch/api/actions/indices/get_template.rb
|
|
432
|
+
- lib/elasticsearch/api/actions/indices/get_upgrade.rb
|
|
424
433
|
- lib/elasticsearch/api/actions/indices/open.rb
|
|
425
434
|
- lib/elasticsearch/api/actions/indices/params_registry.rb
|
|
426
435
|
- lib/elasticsearch/api/actions/indices/put_alias.rb
|
|
@@ -470,6 +479,7 @@ files:
|
|
|
470
479
|
- lib/elasticsearch/api/actions/search.rb
|
|
471
480
|
- lib/elasticsearch/api/actions/search_shards.rb
|
|
472
481
|
- lib/elasticsearch/api/actions/search_template.rb
|
|
482
|
+
- lib/elasticsearch/api/actions/snapshot/cleanup_repository.rb
|
|
473
483
|
- lib/elasticsearch/api/actions/snapshot/create.rb
|
|
474
484
|
- lib/elasticsearch/api/actions/snapshot/create_repository.rb
|
|
475
485
|
- lib/elasticsearch/api/actions/snapshot/delete.rb
|
|
@@ -547,6 +557,7 @@ files:
|
|
|
547
557
|
- spec/elasticsearch/api/actions/index_document_spec.rb
|
|
548
558
|
- spec/elasticsearch/api/actions/indices/analyze_spec.rb
|
|
549
559
|
- spec/elasticsearch/api/actions/indices/clear_cache_spec.rb
|
|
560
|
+
- spec/elasticsearch/api/actions/indices/clone_spec.rb
|
|
550
561
|
- spec/elasticsearch/api/actions/indices/close_spec.rb
|
|
551
562
|
- spec/elasticsearch/api/actions/indices/create_spec.rb
|
|
552
563
|
- spec/elasticsearch/api/actions/indices/delete_alias_spec.rb
|
|
@@ -602,7 +613,7 @@ files:
|
|
|
602
613
|
- spec/elasticsearch/api/actions/reindex_spec.rb
|
|
603
614
|
- spec/elasticsearch/api/actions/remote/info_spec.rb
|
|
604
615
|
- spec/elasticsearch/api/actions/render_search_template_spec.rb
|
|
605
|
-
- spec/elasticsearch/api/actions/
|
|
616
|
+
- spec/elasticsearch/api/actions/scroll_spec.rb
|
|
606
617
|
- spec/elasticsearch/api/actions/search_shards_spec.rb
|
|
607
618
|
- spec/elasticsearch/api/actions/search_spec.rb
|
|
608
619
|
- spec/elasticsearch/api/actions/search_template_spec.rb
|
|
@@ -631,12 +642,17 @@ files:
|
|
|
631
642
|
- test/test_helper.rb
|
|
632
643
|
- utils/Gemfile
|
|
633
644
|
- utils/Thorfile
|
|
634
|
-
- utils/thor/generate_api.rb
|
|
635
645
|
- utils/thor/generate_source.rb
|
|
646
|
+
- utils/thor/generator/endpoint_specifics.rb
|
|
647
|
+
- utils/thor/generator/files_helper.rb
|
|
636
648
|
- utils/thor/lister.rb
|
|
637
|
-
- utils/thor/templates/
|
|
638
|
-
- utils/thor/templates/
|
|
639
|
-
- utils/thor/templates/
|
|
649
|
+
- utils/thor/templates/_documentation_top.erb
|
|
650
|
+
- utils/thor/templates/_method_setup.erb
|
|
651
|
+
- utils/thor/templates/_params_registry.erb
|
|
652
|
+
- utils/thor/templates/_perform_request.erb
|
|
653
|
+
- utils/thor/templates/method.erb
|
|
654
|
+
- utils/thor/templates/test.erb
|
|
655
|
+
- utils/thor/templates/test_helper.rb
|
|
640
656
|
homepage: https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-api
|
|
641
657
|
licenses:
|
|
642
658
|
- Apache-2.0
|
|
@@ -657,7 +673,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
657
673
|
- !ruby/object:Gem::Version
|
|
658
674
|
version: '0'
|
|
659
675
|
requirements: []
|
|
660
|
-
rubygems_version: 3.0.
|
|
676
|
+
rubygems_version: 3.0.6
|
|
661
677
|
signing_key:
|
|
662
678
|
specification_version: 4
|
|
663
679
|
summary: Ruby API for Elasticsearch.
|
|
@@ -710,6 +726,7 @@ test_files:
|
|
|
710
726
|
- spec/elasticsearch/api/actions/index_document_spec.rb
|
|
711
727
|
- spec/elasticsearch/api/actions/indices/analyze_spec.rb
|
|
712
728
|
- spec/elasticsearch/api/actions/indices/clear_cache_spec.rb
|
|
729
|
+
- spec/elasticsearch/api/actions/indices/clone_spec.rb
|
|
713
730
|
- spec/elasticsearch/api/actions/indices/close_spec.rb
|
|
714
731
|
- spec/elasticsearch/api/actions/indices/create_spec.rb
|
|
715
732
|
- spec/elasticsearch/api/actions/indices/delete_alias_spec.rb
|
|
@@ -765,7 +782,7 @@ test_files:
|
|
|
765
782
|
- spec/elasticsearch/api/actions/reindex_spec.rb
|
|
766
783
|
- spec/elasticsearch/api/actions/remote/info_spec.rb
|
|
767
784
|
- spec/elasticsearch/api/actions/render_search_template_spec.rb
|
|
768
|
-
- spec/elasticsearch/api/actions/
|
|
785
|
+
- spec/elasticsearch/api/actions/scroll_spec.rb
|
|
769
786
|
- spec/elasticsearch/api/actions/search_shards_spec.rb
|
|
770
787
|
- spec/elasticsearch/api/actions/search_spec.rb
|
|
771
788
|
- spec/elasticsearch/api/actions/search_template_spec.rb
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more agreements.
|
|
2
|
-
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
3
|
-
# See the LICENSE file in the project root for more information
|
|
4
|
-
|
|
5
|
-
require 'spec_helper'
|
|
6
|
-
|
|
7
|
-
describe 'client#scroll' do
|
|
8
|
-
|
|
9
|
-
let(:expected_args) do
|
|
10
|
-
[
|
|
11
|
-
'GET',
|
|
12
|
-
'_search/scroll',
|
|
13
|
-
{ scroll_id: 'cXVlcn...' },
|
|
14
|
-
nil
|
|
15
|
-
]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'performs the request' do
|
|
19
|
-
expect(client_double.scroll(scroll_id: 'cXVlcn...')).to eq({})
|
|
20
|
-
end
|
|
21
|
-
end
|
data/utils/thor/generate_api.rb
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more agreements.
|
|
2
|
-
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
3
|
-
# See the LICENSE file in the project root for more information
|
|
4
|
-
|
|
5
|
-
require 'thor'
|
|
6
|
-
|
|
7
|
-
require 'pathname'
|
|
8
|
-
require 'active_support/core_ext/hash/deep_merge'
|
|
9
|
-
require 'active_support/inflector/methods'
|
|
10
|
-
require 'rest_client'
|
|
11
|
-
require 'json'
|
|
12
|
-
require 'pry'
|
|
13
|
-
|
|
14
|
-
module Elasticsearch
|
|
15
|
-
|
|
16
|
-
module API
|
|
17
|
-
module Utils
|
|
18
|
-
# controller.registerHandler(RestRequest.Method.GET, "/_cluster/health", this);
|
|
19
|
-
PATTERN_REST = /.*controller.registerHandler\(.*(?<method>GET|POST|PUT|DELETE|HEAD|OPTIONS|PATCH)\s*,\s*"(?<url>.*)"\s*,\s*.+\);/
|
|
20
|
-
# request.param("index"), request.paramAsBoolean("docs", indicesStatsRequest.docs()), etc
|
|
21
|
-
PATTERN_URL_PARAMS = /request.param.*\("(?<param>[a-z_]+)".*/
|
|
22
|
-
# controller.registerHandler(GET, "/{index}/_refresh", this)
|
|
23
|
-
PATTERN_URL_PARTS = /\{(?<part>[a-zA-Z0-9\_\-]+)\}/
|
|
24
|
-
# request.hasContent()
|
|
25
|
-
PATTERN_HAS_BODY = /request\.hasContent()/
|
|
26
|
-
|
|
27
|
-
# Parses the Elasticsearch source code and returns a Hash of REST API information/specs.
|
|
28
|
-
#
|
|
29
|
-
# Example:
|
|
30
|
-
#
|
|
31
|
-
# {
|
|
32
|
-
# "cluster.health" => [
|
|
33
|
-
# { "method" => "GET",
|
|
34
|
-
# "path" => "/_cluster/health",
|
|
35
|
-
# "parts" => ["index"],
|
|
36
|
-
# "params" => ["index", "local", ... ],
|
|
37
|
-
# "body" => false
|
|
38
|
-
# }
|
|
39
|
-
#
|
|
40
|
-
def __parse_java_source(path)
|
|
41
|
-
path += '/' unless path =~ /\/$/ # Add trailing slash if missing
|
|
42
|
-
prefix = "src/main/java/org/elasticsearch/rest/action"
|
|
43
|
-
|
|
44
|
-
java_rest_files = Dir["#{path}#{prefix}/**/*.java"]
|
|
45
|
-
|
|
46
|
-
map = {}
|
|
47
|
-
|
|
48
|
-
java_rest_files.sort.each do |file|
|
|
49
|
-
content = File.read(file)
|
|
50
|
-
parts = file.gsub(path+prefix, '').split('/')
|
|
51
|
-
name = parts[0, parts.size-1].reject { |p| p =~ /^\s*$/ }.join('.')
|
|
52
|
-
|
|
53
|
-
# Remove the `admin` namespace
|
|
54
|
-
name.gsub! /admin\./, ''
|
|
55
|
-
|
|
56
|
-
# Extract params
|
|
57
|
-
url_params = content.scan(PATTERN_URL_PARAMS).map { |n| n.first }.sort
|
|
58
|
-
|
|
59
|
-
# Extract parts
|
|
60
|
-
url_parts = content.scan(PATTERN_URL_PARTS).map { |n| n.first }.sort
|
|
61
|
-
|
|
62
|
-
# Extract if body allowed
|
|
63
|
-
has_body = !!content.match(PATTERN_HAS_BODY)
|
|
64
|
-
|
|
65
|
-
# Extract HTTP method and path
|
|
66
|
-
content.scan(PATTERN_REST) do |method, path|
|
|
67
|
-
(map[name] ||= []) << { 'method' => method,
|
|
68
|
-
'path' => path,
|
|
69
|
-
'parts' => url_parts,
|
|
70
|
-
'params' => url_params,
|
|
71
|
-
'body' => has_body }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
map
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
extend self
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Contains a generator which will parse the Elasticsearch *.java source files,
|
|
83
|
-
# extract information about REST API endpoints (URLs, HTTP methods, URL parameters, etc),
|
|
84
|
-
# and create a skeleton of the JSON API specification file for each endpoint.
|
|
85
|
-
#
|
|
86
|
-
# Usage:
|
|
87
|
-
#
|
|
88
|
-
# $ thor help api:generate:spec
|
|
89
|
-
#
|
|
90
|
-
# Example:
|
|
91
|
-
#
|
|
92
|
-
# time thor api:generate:spec \
|
|
93
|
-
# --force \
|
|
94
|
-
# --verbose \
|
|
95
|
-
# --crawl \
|
|
96
|
-
# --elasticsearch=/path/to/elasticsearch/source/code
|
|
97
|
-
#
|
|
98
|
-
# Features:
|
|
99
|
-
#
|
|
100
|
-
# * Extract the API name from the source filename (eg. `admin/cluster/health/RestClusterHealthAction.java` -> `cluster.health`)
|
|
101
|
-
# * Extract the URLs from the `registerHandler` statements
|
|
102
|
-
# * Extract the URL parts (eg. `{index}`) from the URLs
|
|
103
|
-
# * Extract the URL parameters (eg. `{timeout}`) from the `request.param("ABC")` statements
|
|
104
|
-
# * Detect whether HTTP body is allowed for the API from `request.hasContent()` statements
|
|
105
|
-
# * Search the <http://elasticsearch.org> website to get proper documentation URLs
|
|
106
|
-
# * Assemble the JSON format for the API spec
|
|
107
|
-
#
|
|
108
|
-
class JsonGenerator < Thor
|
|
109
|
-
namespace 'api:spec'
|
|
110
|
-
|
|
111
|
-
include Thor::Actions
|
|
112
|
-
|
|
113
|
-
__root = Pathname( File.expand_path('../../..', __FILE__) )
|
|
114
|
-
|
|
115
|
-
# Usage: thor help api:generate:spec
|
|
116
|
-
#
|
|
117
|
-
desc "generate", "Generate JSON API spec files from Elasticsearch source code"
|
|
118
|
-
method_option :force, type: :boolean, default: false, desc: 'Overwrite the output'
|
|
119
|
-
method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
|
|
120
|
-
method_option :output, default: __root.join('tmp/out'), desc: 'Path to output directory'
|
|
121
|
-
method_option :elasticsearch, default: __root.join('tmp/elasticsearch'), desc: 'Path to directory with Elasticsearch source code'
|
|
122
|
-
method_option :crawl, type: :boolean, default: false, desc: 'Extract URLs from Elasticsearch website'
|
|
123
|
-
|
|
124
|
-
def generate
|
|
125
|
-
self.class.source_root File.expand_path('../', __FILE__)
|
|
126
|
-
|
|
127
|
-
@output = Pathname(options[:output])
|
|
128
|
-
|
|
129
|
-
rest_actions = Utils.__parse_java_source(options[:elasticsearch].to_s)
|
|
130
|
-
|
|
131
|
-
if rest_actions.empty?
|
|
132
|
-
say_status 'ERROR', 'Cannot find Elasticsearch source in ' + options[:elasticsearch].to_s, :red
|
|
133
|
-
exit(1)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
rest_actions.each do |name, info|
|
|
137
|
-
doc_url = ""
|
|
138
|
-
parts = info.reduce([]) { |sum, n| sum |= n['parts']; sum }.reduce({}) { |sum, n| sum[n] = {}; sum }
|
|
139
|
-
params = info.reduce([]) { |sum, n| sum |= n['params']; sum }.reduce({}) { |sum, n| sum[n] = {}; sum }
|
|
140
|
-
|
|
141
|
-
if options[:crawl]
|
|
142
|
-
begin
|
|
143
|
-
response = RestClient.get "http://search.elasticsearch.org/elastic-search-website/guide/_search?q=#{URI.escape(name.gsub(/\./, ' '))}"
|
|
144
|
-
hits = JSON.load(response)['hits']['hits']
|
|
145
|
-
if hit = hits.first
|
|
146
|
-
if hit['_score'] > 0.2
|
|
147
|
-
doc_title = hit['fields']['title']
|
|
148
|
-
doc_url = "http://elasticsearch.org" + hit['fields']['url']
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
rescue Exception => e
|
|
152
|
-
puts "[!] ERROR: #{e.inspect}"
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
spec = {
|
|
157
|
-
name => {
|
|
158
|
-
'documentation' => doc_url,
|
|
159
|
-
|
|
160
|
-
'methods' => info.map { |n| n['method'] }.uniq,
|
|
161
|
-
|
|
162
|
-
'url' => {
|
|
163
|
-
'path' => info.first['path'],
|
|
164
|
-
'paths' => info.map { |n| n['path'] }.uniq,
|
|
165
|
-
'parts' => parts,
|
|
166
|
-
'params' => params
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
'body' => info.first['body'] ? {} : nil
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
json = JSON.pretty_generate(spec, indent: ' ', array_nl: '', object_nl: "\n", space: ' ', space_before: ' ')
|
|
174
|
-
|
|
175
|
-
# Fix JSON array formatting
|
|
176
|
-
json.gsub!(/\[\s+/, '[')
|
|
177
|
-
json.gsub!(/, {2,}"/, ', "')
|
|
178
|
-
|
|
179
|
-
create_file @output.join( "#{name}.json" ), json + "\n"
|
|
180
|
-
|
|
181
|
-
if options[:verbose]
|
|
182
|
-
lines = json.split("\n")
|
|
183
|
-
say_status 'JSON',
|
|
184
|
-
lines.first + "\n" + lines[1, lines.size].map { |l| ' '*14 + l }.join("\n")
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
private
|
|
190
|
-
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more agreements.
|
|
2
|
-
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
3
|
-
# See the LICENSE file in the project root for more information
|
|
4
|
-
|
|
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 -%>
|
|
21
|
-
<%= ' '*(@namespace_depth+3) + '# @option arguments [Hash] :body ' + (@spec['body']['description'] ? @spec['body']['description'].strip : 'TODO: Description') + (@spec['body']['required'] ? ' (*Required*)' : '') + "\n" if @spec['body'] -%>
|
|
22
|
-
<%# 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 -%>#
|
|
29
|
-
<%# Documentation link -%>
|
|
30
|
-
<%= ' '*@namespace_depth %># @see <%= @spec['documentation'] ? @spec['documentation'] : "[TODO]" %>
|
|
31
|
-
<%= ' '*@namespace_depth %>#
|
|
32
|
-
<%# 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 -%>
|
|
38
|
-
<%- if @spec['body'] && @spec['body']['required'] -%>
|
|
39
|
-
<%= ' '*(@namespace_depth+1) + "raise ArgumentError, \"Required argument 'body' missing\" unless arguments[:body]" + "\n" -%>
|
|
40
|
-
<%- 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]' %>
|
|
54
|
-
<%# 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 -%>
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|