@@ -40,7 +40,7 @@ module API
40
40
# here.
41
41
#
42
42
class SourceGenerator < Thor
43
- namespace 'api: code'
43
+ namespace 'code'
44
44
include Thor ::Actions
45
45
include EndpointSpecifics
46
46
@@ -49,26 +49,20 @@ class SourceGenerator < Thor
49
49
desc 'generate' , 'Generate source code and tests from the REST API JSON specification'
50
50
method_option :verbose , type : :boolean , default : false , desc : 'Output more information'
51
51
method_option :tests , type : :boolean , default : false , desc : 'Generate test files'
52
- method_option :api , type : :array , default : %w[ oss xpack ] , desc : 'APIs to generate (oss, x-pack)'
53
52
54
53
def generate
55
54
self . class . source_root File . expand_path ( __dir__ )
56
- @xpack = options [ :api ] . include? 'xpack'
57
- @oss = options [ :api ] . include? 'oss'
58
-
59
- __generate_source ( :xpack ) if @xpack
60
- __generate_source ( :oss ) if @oss
55
+ generate_source
61
56
# -- Tree output
62
57
print_tree if options [ :verbose ]
63
58
end
64
59
65
60
private
66
61
67
- def __generate_source ( api )
68
- @current_api = api
69
- @output = FilesHelper . output_dir ( api )
62
+ def generate_source
63
+ @output = FilesHelper . output_dir
70
64
71
- FilesHelper . files ( api ) . each do |filepath |
65
+ FilesHelper . files . each do |filepath |
72
66
@path = Pathname ( filepath )
73
67
@json = MultiJson . load ( File . read ( @path ) )
74
68
@spec = @json . values . first
@@ -91,7 +85,6 @@ def __generate_source(api)
91
85
@http_path = __http_path
92
86
@required_parts = __required_parts
93
87
94
- @module_namespace . shift if @module_namespace . first == 'xpack'
95
88
@path_to_file = @output . join ( @module_namespace . join ( '/' ) ) . join ( "#{ @method_name } .rb" )
96
89
dir = @output . join ( @module_namespace . join ( '/' ) )
97
90
empty_directory ( dir , verbose : false )
@@ -106,23 +99,18 @@ def __generate_source(api)
106
99
puts
107
100
end
108
101
109
- run_rubocop ( api )
102
+ run_rubocop
110
103
end
111
104
112
105
def __full_namespace
113
106
names = @endpoint_name . split ( '.' )
114
- if @current_api == :xpack
115
- names = ( names . first == 'xpack' ? names : [ 'xpack' , names ] . flatten )
116
- # Return an array to expand 'ccr', 'ilm', 'ml' and 'slm'
117
- names . map do |name |
118
- name
119
- . gsub ( /^ml$/ , 'machine_learning' )
120
- . gsub ( /^ilm$/ , 'index_lifecycle_management' )
121
- . gsub ( /^ccr/ , 'cross_cluster_replication' )
122
- . gsub ( /^slm/ , 'snapshot_lifecycle_management' )
123
- end
124
- else
125
- names
107
+ # Return an array to expand 'ccr', 'ilm', 'ml' and 'slm'
108
+ names . map do |name |
109
+ name
110
+ . gsub ( /^ml$/ , 'machine_learning' )
111
+ . gsub ( /^ilm$/ , 'index_lifecycle_management' )
112
+ . gsub ( /^ccr/ , 'cross_cluster_replication' )
113
+ . gsub ( /^slm/ , 'snapshot_lifecycle_management' )
126
114
end
127
115
end
128
116
@@ -194,7 +182,7 @@ def __http_path
194
182
def __parse_path ( path )
195
183
path . gsub ( /^\/ / , '' )
196
184
. gsub ( /\/ $/ , '' )
197
- . gsub ( '{' , "\# {#{ __utils } .__listify(_" )
185
+ . gsub ( '{' , "\# {Utils .__listify(_" )
198
186
. gsub ( '}' , ')}' )
199
187
end
200
188
@@ -288,12 +276,8 @@ def print_tree
288
276
say_status ( 'tree' , lines . first + "\n " + lines [ 1 , lines . size ] . map { |l | ' ' * 14 + l } . join ( "\n " ) )
289
277
end
290
278
291
- def __utils
292
- ( @current_api == :xpack ) ? 'Elasticsearch::API::Utils' : 'Utils'
293
- end
294
-
295
- def run_rubocop ( api )
296
- system ( "rubocop -c ./thor/.rubocop.yml --format autogenconf -x #{ FilesHelper ::output_dir ( api ) } " )
279
+ def run_rubocop
280
+ system ( "rubocop -c ./thor/.rubocop.yml --format autogenconf -x #{ FilesHelper ::output_dir } " )
297
281
end
298
282
end
299
283
end
0 commit comments