elastic-enterprise-search 7.10.0.beta.1 → 7.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/jobs/elastic+enterprise-search-ruby+7.10.0.beta.1.yml +12 -0
- data/.ci/test-matrix.yml +2 -1
- data/.github/workflows/testing.yml +1 -1
- data/.gitignore +1 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +1 -0
- data/README.md +7 -225
- data/Rakefile +1 -24
- data/docs/guide/app-search-api.asciidoc +172 -0
- data/docs/guide/connecting.asciidoc +125 -0
- data/docs/guide/development.asciidoc +42 -0
- data/docs/guide/enterprise-search-api.asciidoc +46 -0
- data/docs/guide/index.asciidoc +17 -0
- data/docs/guide/installation.asciidoc +18 -0
- data/docs/guide/overview.asciidoc +59 -0
- data/docs/guide/workplace-search-api.asciidoc +121 -0
- data/elastic-enterprise-search.gemspec +5 -4
- data/lib/elastic/app-search/api/add_meta_engine_source.rb +7 -4
- data/lib/elastic/app-search/api/api_logs.rb +15 -16
- data/lib/elastic/app-search/api/count_analytics.rb +7 -5
- data/lib/elastic/app-search/api/create_curation.rb +8 -6
- data/lib/elastic/app-search/api/create_engine.rb +9 -7
- data/lib/elastic/app-search/api/create_synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/curation.rb +6 -5
- data/lib/elastic/app-search/api/delete_curation.rb +6 -5
- data/lib/elastic/app-search/api/delete_documents.rb +7 -4
- data/lib/elastic/app-search/api/delete_engine.rb +5 -3
- data/lib/elastic/app-search/api/delete_meta_engine_source.rb +7 -4
- data/lib/elastic/app-search/api/delete_synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/documents.rb +7 -4
- data/lib/elastic/app-search/api/engine.rb +5 -3
- data/lib/elastic/app-search/api/index_documents.rb +7 -4
- data/lib/elastic/app-search/api/list_curations.rb +7 -5
- data/lib/elastic/app-search/api/list_documents.rb +7 -5
- data/lib/elastic/app-search/api/list_engines.rb +7 -5
- data/lib/elastic/app-search/api/list_synonym_sets.rb +7 -5
- data/lib/elastic/app-search/api/log_clickthrough.rb +10 -7
- data/lib/elastic/app-search/api/multi_search.rb +8 -7
- data/lib/elastic/app-search/api/put_curation.rb +9 -8
- data/lib/elastic/app-search/api/put_documents.rb +7 -4
- data/lib/elastic/app-search/api/put_schema.rb +7 -4
- data/lib/elastic/app-search/api/put_search_settings.rb +6 -3
- data/lib/elastic/app-search/api/put_synonym_set.rb +7 -7
- data/lib/elastic/app-search/api/query_suggestion.rb +8 -6
- data/lib/elastic/app-search/api/reset_search_settings.rb +5 -3
- data/lib/elastic/app-search/api/schema.rb +6 -4
- data/lib/elastic/app-search/api/search.rb +5 -3
- data/lib/elastic/app-search/api/search_settings.rb +6 -4
- data/lib/elastic/app-search/api/synonym_set.rb +6 -5
- data/lib/elastic/app-search/api/top_clicks_analytics.rb +9 -7
- data/lib/elastic/app-search/api/top_queries_analytics.rb +8 -6
- data/lib/elastic/app-search/app_search.rb +19 -2
- data/lib/elastic/enterprise-search/api/health.rb +6 -1
- data/lib/elastic/enterprise-search/api/put_read_only.rb +5 -1
- data/lib/elastic/enterprise-search/api/read_only.rb +6 -1
- data/lib/elastic/enterprise-search/api/stats.rb +6 -2
- data/lib/elastic/enterprise-search/api/version.rb +6 -1
- data/lib/elastic/enterprise-search/client.rb +15 -2
- data/lib/elastic/enterprise-search/request.rb +25 -13
- data/lib/elastic/enterprise-search/utils.rb +5 -6
- data/lib/elastic/enterprise-search/version.rb +1 -1
- data/lib/elastic/enterprise_search.rb +1 -1
- data/lib/elastic/workplace-search/api/add_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/create_analytics_event.rb +59 -0
- data/lib/elastic/workplace-search/api/create_external_identity.rb +9 -7
- data/lib/elastic/workplace-search/api/delete_documents.rb +9 -7
- data/lib/elastic/workplace-search/api/delete_external_identity.rb +10 -6
- data/lib/elastic/workplace-search/api/external_identity.rb +10 -6
- data/lib/elastic/workplace-search/api/index_documents.rb +11 -8
- data/lib/elastic/workplace-search/api/list_external_identities.rb +11 -7
- data/lib/elastic/workplace-search/api/list_permissions.rb +11 -7
- data/lib/elastic/workplace-search/api/put_external_identity.rb +10 -9
- data/lib/elastic/workplace-search/api/put_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/remove_user_permissions.rb +10 -9
- data/lib/elastic/workplace-search/api/search.rb +19 -1
- data/lib/elastic/workplace-search/api/user_permissions.rb +10 -6
- data/lib/elastic/workplace-search/workplace_search.rb +26 -1
- data/spec/app-search/api_curations_spec.rb +97 -0
- data/spec/app-search/api_documents_spec.rb +20 -6
- data/spec/app-search/api_engines_spec.rb +4 -4
- data/{lib/generator/templates/_license.erb → spec/app-search/api_log_clickthrough_spec.rb} +18 -0
- data/spec/app-search/api_meta_engines_spec.rb +72 -0
- data/spec/app-search/api_query_suggestion_spec.rb +39 -0
- data/spec/app-search/api_schema_spec.rb +17 -3
- data/spec/app-search/api_search_settings_spec.rb +76 -0
- data/spec/app-search/api_synonyms_spec.rb +79 -0
- data/spec/app-search/client_spec.rb +20 -0
- data/spec/enterprise-search/client_spec.rb +11 -0
- data/spec/enterprise-search/request_spec.rb +22 -0
- data/spec/enterprise-search/utils_spec.rb +46 -0
- data/spec/fixtures/vcr/app_search/add_meta_engine_source.yml +109 -0
- data/spec/fixtures/vcr/app_search/api_documents.yml +56 -0
- data/spec/fixtures/vcr/app_search/{index_documents.yml → api_index_documents.yml} +11 -10
- data/spec/fixtures/vcr/app_search/api_log_clickthrough.yml +54 -0
- data/spec/fixtures/vcr/app_search/api_put_schema.yml +109 -0
- data/spec/fixtures/vcr/app_search/api_put_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/api_query_suggestion.yml +59 -0
- data/spec/fixtures/vcr/app_search/api_reset_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/{schema.yml → api_schema.yml} +12 -11
- data/spec/fixtures/vcr/app_search/api_search_settings.yml +56 -0
- data/spec/fixtures/vcr/app_search/create_curation.yml +113 -0
- data/spec/fixtures/vcr/{create_engine.yml → app_search/create_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/create_meta_engine.yml +56 -0
- data/spec/fixtures/vcr/app_search/create_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/delete_curation.yml +56 -0
- data/spec/fixtures/vcr/{delete_engine.yml → app_search/delete_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/delete_meta_engine_source.yml +56 -0
- data/spec/fixtures/vcr/app_search/delete_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/get_curation.yml +56 -0
- data/spec/fixtures/vcr/{get_engine.yml → app_search/get_engine.yml} +0 -0
- data/spec/fixtures/vcr/app_search/list_curations.yml +56 -0
- data/spec/fixtures/vcr/{list_engines.yml → app_search/list_engines.yml} +0 -0
- data/spec/fixtures/vcr/app_search/list_synonym_sets.yml +56 -0
- data/spec/fixtures/vcr/app_search/multi_query_search.yml +2 -2
- data/spec/fixtures/vcr/app_search/put_curation.yml +113 -0
- data/spec/fixtures/vcr/app_search/put_synonym_set.yml +56 -0
- data/spec/fixtures/vcr/app_search/synonym_set.yml +56 -0
- data/spec/fixtures/vcr/{add_user_permissions.yml → workplace_search/add_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/{clear_user_permissions.yml → workplace_search/clear_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/create_analytics_event.yml +55 -0
- data/spec/fixtures/vcr/workplace_search/create_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{delete_documents.yml → workplace_search/delete_documents.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/delete_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{index_documents.yml → workplace_search/index_documents.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/list_external_identities.yml +53 -0
- data/spec/fixtures/vcr/{list_permissions.yml → workplace_search/list_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/oauth_request_token.yml +57 -0
- data/spec/fixtures/vcr/workplace_search/put_external_identity.yml +53 -0
- data/spec/fixtures/vcr/{put_user_permissions.yml → workplace_search/put_user_permissions.yml} +22 -18
- data/spec/fixtures/vcr/{remove_user_permissions.yml → workplace_search/remove_user_permissions.yml} +11 -9
- data/spec/fixtures/vcr/workplace_search/retrieve_external_identity.yml +53 -0
- data/spec/fixtures/vcr/workplace_search/search_request.yml +60 -0
- data/spec/fixtures/vcr/{user_permissions_empty.yml → workplace_search/user_permissions_empty.yml} +11 -9
- data/spec/integration/enterprise_search_api_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/workplace-search/client_spec.rb +10 -2
- data/spec/workplace-search/create_analytics_event_spec.rb +59 -0
- data/spec/workplace-search/documents_spec.rb +80 -0
- data/spec/workplace-search/external_identities_spec.rb +84 -0
- data/spec/workplace-search/{api_spec.rb → permissions_spec.rb} +14 -66
- data/spec/workplace-search/search_spec.rb +53 -0
- metadata +96 -36
- data/lib/generator/documentation_helper.rb +0 -94
- data/lib/generator/endpoint_generator.rb +0 -119
- data/lib/generator/parameters_exceptions.rb +0 -40
- data/lib/generator/parameters_helper.rb +0 -144
- data/lib/generator/templates/endpoint_template.erb +0 -29
- data/lib/generator/templates/spec_template.erb +0 -1
- data/lib/generator/utils.rb +0 -70
- data/spec/fixtures/vcr/create_document.yml +0 -54
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with
|
5
|
-
# this work for additional information regarding copyright
|
6
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
7
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
8
|
-
# not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
14
|
-
# software distributed under the License is distributed on an
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
-
# KIND, either express or implied. See the License for the
|
17
|
-
# specific language governing permissions and limitations
|
18
|
-
# under the License.
|
19
|
-
|
20
|
-
module Elastic
|
21
|
-
module Generator
|
22
|
-
# Helper for setting up generated code documentation
|
23
|
-
module DocumentationHelper
|
24
|
-
def setup_documentation(endpoint)
|
25
|
-
description, url = url_and_description(endpoint)
|
26
|
-
docs = []
|
27
|
-
docs << "# #{@module_name} - #{endpoint['summary']}"
|
28
|
-
docs << "# #{description}" if description
|
29
|
-
docs << '#'
|
30
|
-
docs << parameters_documentation if @params && !@params.empty?
|
31
|
-
docs << "# @see #{url}" if url
|
32
|
-
docs << "#\n"
|
33
|
-
docs.join("\n")
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# Description is markdown with [description](external_url)
|
39
|
-
# So we split the string with regexp:
|
40
|
-
def url_and_description(endpoint)
|
41
|
-
if endpoint['description'].nil?
|
42
|
-
description = nil
|
43
|
-
url = endpoint.dig('externalDocs', 'url')
|
44
|
-
else
|
45
|
-
matches = endpoint['description'].match(/\[(.+)\]\((.+)\)/)
|
46
|
-
description = matches[1]
|
47
|
-
url = matches[2]
|
48
|
-
end
|
49
|
-
|
50
|
-
[description, url]
|
51
|
-
end
|
52
|
-
|
53
|
-
def parameters_documentation
|
54
|
-
doc = ['# @param arguments [Hash] endpoint arguments']
|
55
|
-
# Show optional parameters for the `parameters` hash
|
56
|
-
doc = add_required(doc)
|
57
|
-
unless (optional = @params - required_params).empty?
|
58
|
-
optional.each { |param| doc << show_param(param) }
|
59
|
-
end
|
60
|
-
doc << "# @option body - The request body\n#" if body?
|
61
|
-
doc << '#'
|
62
|
-
doc.join("\n")
|
63
|
-
end
|
64
|
-
|
65
|
-
def add_required(doc)
|
66
|
-
# Show required parameters first
|
67
|
-
required_params.each do |param|
|
68
|
-
if in_signature?(param['name'])
|
69
|
-
doc.unshift(show_required_param(param))
|
70
|
-
else
|
71
|
-
doc << show_required_option(param)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
doc
|
75
|
-
end
|
76
|
-
|
77
|
-
def show_param(param)
|
78
|
-
"# @option #{build_param_display(param)}"
|
79
|
-
end
|
80
|
-
|
81
|
-
def show_required_param(param)
|
82
|
-
"# @param #{build_param_display(param)} (*Required*)"
|
83
|
-
end
|
84
|
-
|
85
|
-
def show_required_option(param)
|
86
|
-
"# @option #{build_param_display(param)} (*Required*)"
|
87
|
-
end
|
88
|
-
|
89
|
-
def build_param_display(param)
|
90
|
-
"#{param['name']} [#{param['type']&.capitalize}] #{param['description']}"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with
|
5
|
-
# this work for additional information regarding copyright
|
6
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
7
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
8
|
-
# not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
14
|
-
# software distributed under the License is distributed on an
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
-
# KIND, either express or implied. See the License for the
|
17
|
-
# specific language governing permissions and limitations
|
18
|
-
# under the License.
|
19
|
-
|
20
|
-
require 'json'
|
21
|
-
require 'erb'
|
22
|
-
require_relative './utils'
|
23
|
-
require_relative './documentation_helper'
|
24
|
-
require_relative './parameters_helper'
|
25
|
-
require_relative './parameters_exceptions'
|
26
|
-
|
27
|
-
module Elastic
|
28
|
-
module Generator
|
29
|
-
# Generates code for REST API Endpoints
|
30
|
-
class EndpointGenerator
|
31
|
-
include DocumentationHelper
|
32
|
-
include ParametersHelper
|
33
|
-
include ParametersExceptions
|
34
|
-
CURRENT_PATH = File.dirname(__FILE__).freeze
|
35
|
-
|
36
|
-
def initialize(name)
|
37
|
-
@name = name
|
38
|
-
@spec = load_spec(name)
|
39
|
-
@target_dir = File.expand_path(__dir__ + "../../elastic/#{@name}-search/api").freeze
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate
|
43
|
-
Dir.mkdir(@target_dir) unless File.directory?(@target_dir)
|
44
|
-
Utils.empty_directory(@target_dir)
|
45
|
-
|
46
|
-
# for each endpoint in the spec generate the code
|
47
|
-
@spec['paths'].each do |endpoint|
|
48
|
-
@path = generate_path(endpoint[0])
|
49
|
-
generate_classes(endpoint)
|
50
|
-
end
|
51
|
-
Utils.run_rubocop(@target_dir)
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def namespace
|
57
|
-
return 'EnterpriseSearch' if @name == :enterprise
|
58
|
-
|
59
|
-
"#{@name.capitalize}Search"
|
60
|
-
end
|
61
|
-
|
62
|
-
def load_spec(name)
|
63
|
-
file_path = Pathname.new("./../json-specs/#{name}-search.json")
|
64
|
-
JSON.parse(File.read(file_path))
|
65
|
-
end
|
66
|
-
|
67
|
-
def generate_classes(endpoint)
|
68
|
-
# endpoint is an array with ['path', {'http_method(s)' => 'info'}
|
69
|
-
endpoint.last.each_key do |method|
|
70
|
-
@params = []
|
71
|
-
if method == 'parameters'
|
72
|
-
endpoint.last['parameters'].each { |param| add_parameter(param) }
|
73
|
-
next
|
74
|
-
end
|
75
|
-
@http_method = method
|
76
|
-
setup_values!(endpoint.last[method])
|
77
|
-
write_file(generate_code)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def write_file(code)
|
82
|
-
file_name = "#{@target_dir}/#{@method_name}.rb"
|
83
|
-
Utils.write_file(file_name, code)
|
84
|
-
end
|
85
|
-
|
86
|
-
def generate_path(path_string)
|
87
|
-
path = replace_path_variables(path_string).gsub(/^\//, '')
|
88
|
-
|
89
|
-
path.match?(/\/$/) ? path : "#{path}/"
|
90
|
-
end
|
91
|
-
|
92
|
-
def replace_path_variables(path)
|
93
|
-
# rubocop:disable Lint/InterpolationCheck
|
94
|
-
path.gsub(/{([a-z_]+)}/, '#{\1}')
|
95
|
-
# rubocop:enable Lint/InterpolationCheck
|
96
|
-
end
|
97
|
-
|
98
|
-
def setup_values!(endpoint)
|
99
|
-
@module_name = Utils.module_name(endpoint.fetch('tags'))
|
100
|
-
@method_name = Utils.to_ruby_name(endpoint['operationId'])
|
101
|
-
setup_parameters!(endpoint)
|
102
|
-
@doc = setup_documentation(endpoint)
|
103
|
-
end
|
104
|
-
|
105
|
-
def body?
|
106
|
-
# TODO: Define exactly when we need a body
|
107
|
-
return ['post', 'put', 'patch'].include? @http_method if @name != :app
|
108
|
-
|
109
|
-
true
|
110
|
-
end
|
111
|
-
|
112
|
-
def generate_code
|
113
|
-
template = "#{CURRENT_PATH}/templates/endpoint_template.erb"
|
114
|
-
code = ERB.new(File.read(template), nil, '-')
|
115
|
-
code.result(binding)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Elastic
|
4
|
-
module Generator
|
5
|
-
# This module has the logic for parameter renaming like the friendlier
|
6
|
-
# :to_date to the api's filters[date][to] and any parameter serializing
|
7
|
-
# necessary such as date formatting.
|
8
|
-
module ParametersExceptions
|
9
|
-
PARAMETERS_MAPPING = {
|
10
|
-
name: 'engineName',
|
11
|
-
from_date: 'filters[date][from]',
|
12
|
-
to_date: 'filters[date][to]'
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
DATE_PARAMS = [:from_date, :to_date].freeze
|
16
|
-
|
17
|
-
EXCEPTIONAL_APIS = ['api_logs'].freeze
|
18
|
-
|
19
|
-
def rename_exceptional_parameters
|
20
|
-
return unless EXCEPTIONAL_APIS.include? @method_name
|
21
|
-
|
22
|
-
response = []
|
23
|
-
PARAMETERS_MAPPING.each do |param|
|
24
|
-
next unless @params.map { |p| p['name'] }.include? param[0].to_s
|
25
|
-
|
26
|
-
response << check_date_params(param[0])
|
27
|
-
response << "arguments['#{param[1]}'] = arguments.delete(:#{param[0]})"
|
28
|
-
end
|
29
|
-
|
30
|
-
response.join("\n")
|
31
|
-
end
|
32
|
-
|
33
|
-
def check_date_params(param_name)
|
34
|
-
return unless DATE_PARAMS.include?(param_name)
|
35
|
-
|
36
|
-
"arguments[:#{param_name}] = date_to_rfc3339(arguments[:#{param_name}])"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with
|
5
|
-
# this work for additional information regarding copyright
|
6
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
7
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
8
|
-
# not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
14
|
-
# software distributed under the License is distributed on an
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
-
# KIND, either express or implied. See the License for the
|
17
|
-
# specific language governing permissions and limitations
|
18
|
-
# under the License.
|
19
|
-
|
20
|
-
module Elastic
|
21
|
-
module Generator
|
22
|
-
# Generator Helper for working with parameters
|
23
|
-
module ParametersHelper
|
24
|
-
METHOD_SIGNATURE_PARAMS = [
|
25
|
-
'content_source_key',
|
26
|
-
'engine_name'
|
27
|
-
].freeze
|
28
|
-
|
29
|
-
def setup_parameters!(endpoint)
|
30
|
-
endpoint['parameters']&.each { |param| add_parameter(param) }
|
31
|
-
extract_path_parameters.each do |param|
|
32
|
-
next unless @params.select { |p| p['name'] == param }.empty?
|
33
|
-
|
34
|
-
@params << {
|
35
|
-
'name' => param,
|
36
|
-
'required' => true,
|
37
|
-
'description' => '',
|
38
|
-
'type' => 'String'
|
39
|
-
}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def extract_path_parameters
|
44
|
-
@path.scan(/{(\w+)}/).flatten
|
45
|
-
end
|
46
|
-
|
47
|
-
def add_parameter(param)
|
48
|
-
@params << if param.keys.include?('$ref') && !param['$ref'].empty?
|
49
|
-
parameter_name_and_description(Utils.dig_ref_from_spec(param['$ref'], @spec))
|
50
|
-
else
|
51
|
-
parameter_name_and_description(param)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def parameter_name_and_description(param)
|
56
|
-
param['name'] = parameter_name(param)
|
57
|
-
|
58
|
-
# Check the spec for parameters with a given name and retrieve info
|
59
|
-
param_info = @spec.dig('components', 'parameters').select do |k, _|
|
60
|
-
k == param['name']
|
61
|
-
end.values.first
|
62
|
-
param_info = param if param_info.nil?
|
63
|
-
|
64
|
-
parameter_display(param['name'], param_info)
|
65
|
-
end
|
66
|
-
|
67
|
-
def parameter_display(name, param_info)
|
68
|
-
{
|
69
|
-
'name' => name,
|
70
|
-
'description' => param_info['description'],
|
71
|
-
'type' => param_info.dig('schema', 'type') || param_info['type'],
|
72
|
-
'required' => param_info['required']
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def parameter_name(param)
|
77
|
-
if (name = param['x-codegen-param-name'])
|
78
|
-
if name == 'engineName'
|
79
|
-
'name'
|
80
|
-
else
|
81
|
-
Utils.to_ruby_name(name)
|
82
|
-
end
|
83
|
-
else
|
84
|
-
param['name']
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def required_params
|
89
|
-
return [] unless @params
|
90
|
-
|
91
|
-
@params.select { |param| param['required'] }
|
92
|
-
end
|
93
|
-
|
94
|
-
def required_variables_from_parameters
|
95
|
-
response = []
|
96
|
-
required_params.map do |param|
|
97
|
-
name = param['name']
|
98
|
-
next if in_signature?(name) || !extract_path_parameters.include?(name)
|
99
|
-
|
100
|
-
response << "#{name} = arguments[:#{name}]"
|
101
|
-
end
|
102
|
-
response.join("\n")
|
103
|
-
end
|
104
|
-
|
105
|
-
def method_signature_params
|
106
|
-
return unless @params
|
107
|
-
|
108
|
-
parameters = required_params.select do |param|
|
109
|
-
in_signature?(param['name'])
|
110
|
-
end
|
111
|
-
parameters.map { |param| param['name'] }
|
112
|
-
end
|
113
|
-
|
114
|
-
def in_signature?(param_name)
|
115
|
-
METHOD_SIGNATURE_PARAMS.include?(param_name)
|
116
|
-
end
|
117
|
-
|
118
|
-
def raise_for_required_params
|
119
|
-
errors = []
|
120
|
-
required_params.map do |param|
|
121
|
-
name = param['name']
|
122
|
-
parameter = in_signature?(name) ? name : "arguments[:#{name}]"
|
123
|
-
errors << "raise ArgumentError, \"Required parameter '#{name}' missing\" unless #{parameter}"
|
124
|
-
end
|
125
|
-
errors.join("\n")
|
126
|
-
end
|
127
|
-
|
128
|
-
# Display the parameters that should be in the method signature
|
129
|
-
def display_signature_params
|
130
|
-
params = method_signature_params
|
131
|
-
params << 'arguments = {}'
|
132
|
-
"(#{params.join(', ')})"
|
133
|
-
end
|
134
|
-
|
135
|
-
def request_method_params
|
136
|
-
params = []
|
137
|
-
params += [":#{@http_method}", "\"#{@path}\""]
|
138
|
-
params << 'arguments'
|
139
|
-
params << (body? ? 'body' : {})
|
140
|
-
params.join(",\n")
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<%= ERB.new(File.read(CURRENT_PATH + "/templates/_license.erb"), trim_mode: '-').result(binding)%>
|
2
|
-
|
3
|
-
module Elastic
|
4
|
-
module EnterpriseSearch
|
5
|
-
<% if @name != :enterprise -%>
|
6
|
-
module <%= namespace %>
|
7
|
-
<% end -%>
|
8
|
-
module Actions
|
9
|
-
<%= @doc -%>
|
10
|
-
def <%= @method_name %><%= display_signature_params %>
|
11
|
-
<%= raise_for_required_params %>
|
12
|
-
|
13
|
-
<%= required_variables_from_parameters %>
|
14
|
-
<% if body? %>
|
15
|
-
body = arguments.delete(:body) || {}
|
16
|
-
<% end %>
|
17
|
-
|
18
|
-
<%= rename_exceptional_parameters %>
|
19
|
-
|
20
|
-
request(
|
21
|
-
<%= request_method_params %>
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
<% if @name != :enterprise -%>
|
28
|
-
end
|
29
|
-
<% end -%>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= ERB.new(File.read(CURRENT_PATH + "/templates/_license.erb"), trim_mode: '-').result(binding)%>
|
data/lib/generator/utils.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Licensed to Elasticsearch B.V. under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with
|
5
|
-
# this work for additional information regarding copyright
|
6
|
-
# ownership. Elasticsearch B.V. licenses this file to you under
|
7
|
-
# the Apache License, Version 2.0 (the "License"); you may
|
8
|
-
# not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
14
|
-
# software distributed under the License is distributed on an
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
-
# KIND, either express or implied. See the License for the
|
17
|
-
# specific language governing permissions and limitations
|
18
|
-
# under the License.
|
19
|
-
module Elastic
|
20
|
-
module Generator
|
21
|
-
# Utility functions for code generation
|
22
|
-
module Utils
|
23
|
-
def self.empty_directory(dir)
|
24
|
-
FileUtils.remove_dir(dir)
|
25
|
-
Dir.mkdir(dir)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.write_file(file_name, content)
|
29
|
-
File.open(file_name, 'w') { |f| f.puts content }
|
30
|
-
puts colorize(:green, "\nSuccessfully generated #{file_name}\n\n")
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.run_rubocop(dir)
|
34
|
-
system("rubocop -c ./.rubocop.yml --format autogenconf -A #{dir}")
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.module_name(tag)
|
38
|
-
tag.first.gsub(/\s{1}API/, '').gsub(/\s/, '')
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.to_ruby_name(camel_case)
|
42
|
-
camel_case
|
43
|
-
.gsub(/([a-z])([A-Z])+/, '\1_\2') # to camel_case
|
44
|
-
.gsub(/get_/, '') # remove prepended 'get' in method names
|
45
|
-
.downcase
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.colorize(color, message)
|
49
|
-
colors = { red: 31, green: 32 }
|
50
|
-
"\e[#{colors[color]}m#{message}\e[0m"
|
51
|
-
end
|
52
|
-
|
53
|
-
# TODO: Use this for modules
|
54
|
-
def self.setup_tags(tags)
|
55
|
-
tags.map do |tag|
|
56
|
-
{
|
57
|
-
name: tag['name'],
|
58
|
-
description: tag['description'],
|
59
|
-
url: tag['externalDocs']['url']
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.dig_ref_from_spec(ref, spec)
|
65
|
-
path = ref.gsub('#', '').split('/').reject(&:empty?)
|
66
|
-
spec.dig(*path)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|