elasticsearch-api 7.4.0 → 7.5.0.pre.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +16 -23
- 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 +21 -21
- 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 +1 -1
- 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/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 +19 -11
- 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
@@ -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
|