|
21 | 21 | module Elasticsearch
|
22 | 22 | module API
|
23 | 23 | 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/') |
25 | 26 | 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 |
28 | 27 | XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
|
29 | 28 |
|
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 |
38 | 63 | end
|
39 | 64 |
|
40 | 65 | # Path to directory to copy generated files
|
41 | 66 | def self.output_dir(api)
|
42 | 67 | api == :xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
|
43 | 68 | end
|
44 | 69 |
|
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 |
| - |
54 | 70 | def self.gem_version
|
55 | 71 | regex = /([0-9]{1,2}\.[0-9x]{1,2})/
|
56 | 72 | Elasticsearch::API::VERSION.match(regex)[0]
|
|
0 commit comments