Skip to content

Commit 41e711a

Browse files
committed
[API] Generator: Update code generation for merged specs
1 parent ec8bd3f commit 41e711a

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

elasticsearch-api/utils/Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
source 'https://rubygems.org'
1919

2020
gem 'activesupport'
21-
gem 'rest-client'
21+
gem 'byebug'
2222
gem 'coderay'
23-
gem 'multi_json'
24-
gem 'thor'
2523
gem 'json'
24+
gem 'multi_json'
2625
gem 'pry'
26+
gem 'rest-client'
2727
gem 'rubocop'
28+
gem 'thor'

elasticsearch-api/utils/thor/generate_source.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ def generate
6666

6767
def __generate_source(api)
6868
@current_api = api
69-
@input = FilesHelper.input_dir(api)
7069
@output = FilesHelper.output_dir(api)
7170

7271
FilesHelper.files(api).each do |filepath|
73-
@path = Pathname(@input.join(filepath))
72+
@path = Pathname(filepath)
7473
@json = MultiJson.load(File.read(@path))
7574
@spec = @json.values.first
7675
say_status 'json', @path, :yellow

elasticsearch-api/utils/thor/generator/files_helper.rb

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,52 @@
2121
module Elasticsearch
2222
module API
2323
module FilesHelper
24-
OSS_SRC_PATH = '../../../../../tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/'.freeze
24+
PROJECT_PATH = File.join(File.dirname(__FILE__), '..')
25+
SRC_PATH = File.join(PROJECT_PATH, '..', '..', '..', 'tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/')
2526
OSS_OUTPUT_DIR = '../../elasticsearch-api/lib/elasticsearch/api/actions'.freeze
26-
27-
XPACK_SRC_PATH = '../../../../../tmp/elasticsearch/x-pack/plugin/src/test/resources/rest-api-spec/api'.freeze
2827
XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
2928

30-
# Path to directory with JSON API specs
31-
def self.input_dir(api)
32-
input_dir = if api == :xpack
33-
File.expand_path(XPACK_SRC_PATH, __FILE__)
34-
else
35-
File.expand_path(OSS_SRC_PATH, __FILE__)
36-
end
37-
Pathname(input_dir)
29+
TESTS_DIRECTORIES = {
30+
oss: "#{PROJECT_PATH}/../../../tmp/rest-api-spec/test/free",
31+
xpack: "#{PROJECT_PATH}/../../../tmp/rest-api-spec/test/platinum"
32+
}.freeze
33+
34+
# Only get JSON files and remove hidden files
35+
def self.files(api)
36+
json_files = if api == :xpack
37+
xpack_files
38+
else
39+
Dir.entries(SRC_PATH) - xpack_files
40+
end
41+
json_files.reject do |file|
42+
File.extname(file) != '.json' ||
43+
File.basename(file) == '_common.json'
44+
end.map { |file| "#{SRC_PATH}#{file}" }
45+
end
46+
47+
XPACK_ENDPOINTS = [
48+
'autoscaling', 'cross_cluster_replication', 'ccr', 'data_frame_transform_deprecated',
49+
'enrich', 'eql', 'ilm', 'logstash', 'migration', 'watcher', 'slm'
50+
]
51+
XPACK_ENDPOINTS_REGEXP = /data_stream|ml_|reload_search_analyzers|transform/
52+
53+
def self.xpack_files
54+
xpack_tests = Dir.entries(TESTS_DIRECTORIES[:xpack])
55+
Dir.entries(SRC_PATH).map do |entry|
56+
filename = entry.split('.').first
57+
if xpack_tests.include?(filename) ||
58+
XPACK_ENDPOINTS.include?(filename) ||
59+
entry.match?(XPACK_ENDPOINTS_REGEXP)
60+
entry
61+
end
62+
end.compact
3863
end
3964

4065
# Path to directory to copy generated files
4166
def self.output_dir(api)
4267
api == :xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
4368
end
4469

45-
# Only get JSON files and remove hidden files
46-
def self.files(api)
47-
Dir.entries(input_dir(api).to_s).reject do |f|
48-
f.start_with?('.') ||
49-
f.start_with?('_') ||
50-
File.extname(f) != '.json'
51-
end
52-
end
53-
5470
def self.gem_version
5571
regex = /([0-9]{1,2}\.[0-9x]{1,2})/
5672
Elasticsearch::API::VERSION.match(regex)[0]

0 commit comments

Comments
 (0)