elasticsearch-api 6.8.0 → 7.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +26 -5
  3. data/LICENSE +202 -0
  4. data/README.md +24 -21
  5. data/Rakefile +43 -45
  6. data/elasticsearch-api.gemspec +56 -55
  7. data/lib/elasticsearch/api/actions/abort_benchmark.rb +19 -3
  8. data/lib/elasticsearch/api/actions/benchmark.rb +21 -5
  9. data/lib/elasticsearch/api/actions/bulk.rb +54 -69
  10. data/lib/elasticsearch/api/actions/cat/aliases.rb +45 -45
  11. data/lib/elasticsearch/api/actions/cat/allocation.rb +45 -41
  12. data/lib/elasticsearch/api/actions/cat/count.rb +38 -39
  13. data/lib/elasticsearch/api/actions/cat/fielddata.rb +42 -29
  14. data/lib/elasticsearch/api/actions/cat/health.rb +37 -29
  15. data/lib/elasticsearch/api/actions/cat/help.rb +31 -9
  16. data/lib/elasticsearch/api/actions/cat/indices.rb +51 -51
  17. data/lib/elasticsearch/api/actions/cat/master.rb +36 -26
  18. data/lib/elasticsearch/api/actions/cat/nodeattrs.rb +36 -14
  19. data/lib/elasticsearch/api/actions/cat/nodes.rb +43 -39
  20. data/lib/elasticsearch/api/actions/cat/params_registry.rb +20 -4
  21. data/lib/elasticsearch/api/actions/cat/pending_tasks.rb +38 -26
  22. data/lib/elasticsearch/api/actions/cat/plugins.rb +36 -14
  23. data/lib/elasticsearch/api/actions/cat/recovery.rb +47 -47
  24. data/lib/elasticsearch/api/actions/cat/repositories.rb +36 -22
  25. data/lib/elasticsearch/api/actions/cat/segments.rb +42 -19
  26. data/lib/elasticsearch/api/actions/cat/shards.rb +45 -50
  27. data/lib/elasticsearch/api/actions/cat/snapshots.rb +44 -25
  28. data/lib/elasticsearch/api/actions/cat/tasks.rb +40 -16
  29. data/lib/elasticsearch/api/actions/cat/templates.rb +43 -16
  30. data/lib/elasticsearch/api/actions/cat/thread_pool.rb +46 -35
  31. data/lib/elasticsearch/api/actions/clear_scroll.rb +40 -17
  32. data/lib/elasticsearch/api/actions/cluster/allocation_explain.rb +38 -11
  33. data/lib/elasticsearch/api/actions/cluster/delete_component_template.rb +62 -0
  34. data/lib/elasticsearch/api/actions/cluster/delete_voting_config_exclusions.rb +51 -0
  35. data/lib/elasticsearch/api/actions/cluster/exists_component_template.rb +63 -0
  36. data/lib/elasticsearch/api/actions/cluster/get_component_template.rb +64 -0
  37. data/lib/elasticsearch/api/actions/cluster/get_settings.rb +33 -15
  38. data/lib/elasticsearch/api/actions/cluster/health.rb +46 -27
  39. data/lib/elasticsearch/api/actions/cluster/params_registry.rb +20 -4
  40. data/lib/elasticsearch/api/actions/cluster/pending_tasks.rb +32 -14
  41. data/lib/elasticsearch/api/actions/cluster/post_voting_config_exclusions.rb +55 -0
  42. data/lib/elasticsearch/api/actions/cluster/put_component_template.rb +66 -0
  43. data/lib/elasticsearch/api/actions/cluster/put_settings.rb +35 -15
  44. data/lib/elasticsearch/api/actions/cluster/remote_info.rb +27 -12
  45. data/lib/elasticsearch/api/actions/cluster/reroute.rb +38 -33
  46. data/lib/elasticsearch/api/actions/cluster/state.rb +53 -44
  47. data/lib/elasticsearch/api/actions/cluster/stats.rb +38 -19
  48. data/lib/elasticsearch/api/actions/count.rb +60 -36
  49. data/lib/elasticsearch/api/actions/create.rb +37 -25
  50. data/lib/elasticsearch/api/actions/dangling_indices/delete_dangling_index.rb +60 -0
  51. data/lib/elasticsearch/api/actions/dangling_indices/import_dangling_index.rb +60 -0
  52. data/lib/elasticsearch/api/actions/dangling_indices/list_dangling_indices.rb +43 -0
  53. data/lib/elasticsearch/api/actions/dangling_indices/params_registry.rb +60 -0
  54. data/lib/elasticsearch/api/actions/delete.rb +62 -47
  55. data/lib/elasticsearch/api/actions/delete_by_query.rb +82 -57
  56. data/lib/elasticsearch/api/actions/delete_by_query_rethrottle.rb +36 -11
  57. data/lib/elasticsearch/api/actions/delete_by_rethrottle.rb +47 -0
  58. data/lib/elasticsearch/api/actions/delete_script.rb +37 -12
  59. data/lib/elasticsearch/api/actions/exists.rb +61 -34
  60. data/lib/elasticsearch/api/actions/exists_source.rb +60 -24
  61. data/lib/elasticsearch/api/actions/explain.rb +68 -44
  62. data/lib/elasticsearch/api/actions/field_caps.rb +49 -19
  63. data/lib/elasticsearch/api/actions/get.rb +60 -40
  64. data/lib/elasticsearch/api/actions/get_script.rb +37 -13
  65. data/lib/elasticsearch/api/actions/get_script_context.rb +45 -0
  66. data/lib/elasticsearch/api/actions/get_script_languages.rb +45 -0
  67. data/lib/elasticsearch/api/actions/get_source.rb +57 -38
  68. data/lib/elasticsearch/api/actions/index.rb +67 -74
  69. data/lib/elasticsearch/api/actions/indices/add_block.rb +68 -0
  70. data/lib/elasticsearch/api/actions/indices/analyze.rb +41 -34
  71. data/lib/elasticsearch/api/actions/indices/clear_cache.rb +44 -41
  72. data/lib/elasticsearch/api/actions/indices/clone.rb +65 -0
  73. data/lib/elasticsearch/api/actions/indices/close.rb +41 -21
  74. data/lib/elasticsearch/api/actions/indices/create.rb +39 -69
  75. data/lib/elasticsearch/api/actions/indices/delete.rb +41 -34
  76. data/lib/elasticsearch/api/actions/indices/delete_alias.rb +41 -19
  77. data/lib/elasticsearch/api/actions/indices/delete_index_template.rb +62 -0
  78. data/lib/elasticsearch/api/actions/indices/delete_template.rb +36 -20
  79. data/lib/elasticsearch/api/actions/indices/exists.rb +43 -21
  80. data/lib/elasticsearch/api/actions/indices/exists_alias.rb +46 -18
  81. data/lib/elasticsearch/api/actions/indices/exists_index_template.rb +65 -0
  82. data/lib/elasticsearch/api/actions/indices/exists_template.rb +37 -14
  83. data/lib/elasticsearch/api/actions/indices/exists_type.rb +42 -17
  84. data/lib/elasticsearch/api/actions/indices/flush.rb +41 -19
  85. data/lib/elasticsearch/api/actions/indices/flush_synced.rb +45 -11
  86. data/lib/elasticsearch/api/actions/indices/forcemerge.rb +42 -40
  87. data/lib/elasticsearch/api/actions/indices/freeze.rb +24 -7
  88. data/lib/elasticsearch/api/actions/indices/get.rb +42 -18
  89. data/lib/elasticsearch/api/actions/indices/get_alias.rb +47 -22
  90. data/lib/elasticsearch/api/actions/indices/get_field_mapping.rb +59 -37
  91. data/lib/elasticsearch/api/actions/indices/get_index_template.rb +66 -0
  92. data/lib/elasticsearch/api/actions/indices/get_mapping.rb +57 -32
  93. data/lib/elasticsearch/api/actions/indices/get_settings.rb +50 -36
  94. data/lib/elasticsearch/api/actions/indices/get_template.rb +40 -22
  95. data/lib/elasticsearch/api/actions/indices/get_upgrade.rb +62 -0
  96. data/lib/elasticsearch/api/actions/indices/open.rb +40 -20
  97. data/lib/elasticsearch/api/actions/indices/params_registry.rb +20 -4
  98. data/lib/elasticsearch/api/actions/indices/put_alias.rb +43 -26
  99. data/lib/elasticsearch/api/actions/indices/put_index_template.rb +66 -0
  100. data/lib/elasticsearch/api/actions/indices/put_mapping.rb +58 -40
  101. data/lib/elasticsearch/api/actions/indices/put_settings.rb +46 -36
  102. data/lib/elasticsearch/api/actions/indices/put_template.rb +40 -24
  103. data/lib/elasticsearch/api/actions/indices/recovery.rb +38 -22
  104. data/lib/elasticsearch/api/actions/indices/refresh.rb +39 -25
  105. data/lib/elasticsearch/api/actions/indices/resolve_index.rb +60 -0
  106. data/lib/elasticsearch/api/actions/indices/rollover.rb +47 -18
  107. data/lib/elasticsearch/api/actions/indices/segments.rb +40 -16
  108. data/lib/elasticsearch/api/actions/indices/shard_stores.rb +41 -13
  109. data/lib/elasticsearch/api/actions/indices/shrink.rb +40 -17
  110. data/lib/elasticsearch/api/actions/indices/simulate_index_template.rb +65 -0
  111. data/lib/elasticsearch/api/actions/indices/simulate_template.rb +67 -0
  112. data/lib/elasticsearch/api/actions/indices/split.rb +40 -18
  113. data/lib/elasticsearch/api/actions/indices/stats.rb +68 -104
  114. data/lib/elasticsearch/api/actions/indices/unfreeze.rb +24 -7
  115. data/lib/elasticsearch/api/actions/indices/update_aliases.rb +33 -31
  116. data/lib/elasticsearch/api/actions/indices/upgrade.rb +42 -14
  117. data/lib/elasticsearch/api/actions/indices/validate_query.rb +64 -57
  118. data/lib/elasticsearch/api/actions/info.rb +29 -13
  119. data/lib/elasticsearch/api/actions/ingest/delete_pipeline.rb +36 -11
  120. data/lib/elasticsearch/api/actions/ingest/get_pipeline.rb +37 -9
  121. data/lib/elasticsearch/api/actions/ingest/params_registry.rb +20 -4
  122. data/lib/elasticsearch/api/actions/ingest/processor_grok.rb +27 -13
  123. data/lib/elasticsearch/api/actions/ingest/put_pipeline.rb +37 -13
  124. data/lib/elasticsearch/api/actions/ingest/simulate.rb +39 -10
  125. data/lib/elasticsearch/api/actions/mget.rb +55 -43
  126. data/lib/elasticsearch/api/actions/msearch.rb +67 -50
  127. data/lib/elasticsearch/api/actions/msearch_template.rb +62 -29
  128. data/lib/elasticsearch/api/actions/mtermvectors.rb +59 -32
  129. data/lib/elasticsearch/api/actions/nodes/hot_threads.rb +46 -22
  130. data/lib/elasticsearch/api/actions/nodes/info.rb +43 -40
  131. data/lib/elasticsearch/api/actions/nodes/params_registry.rb +20 -4
  132. data/lib/elasticsearch/api/actions/nodes/reload_secure_settings.rb +37 -21
  133. data/lib/elasticsearch/api/actions/nodes/shutdown.rb +22 -5
  134. data/lib/elasticsearch/api/actions/nodes/stats.rb +53 -33
  135. data/lib/elasticsearch/api/actions/nodes/usage.rb +46 -12
  136. data/lib/elasticsearch/api/actions/params_registry.rb +20 -4
  137. data/lib/elasticsearch/api/actions/ping.rb +30 -18
  138. data/lib/elasticsearch/api/actions/put_script.rb +44 -31
  139. data/lib/elasticsearch/api/actions/rank_eval.rb +49 -16
  140. data/lib/elasticsearch/api/actions/reindex.rb +45 -48
  141. data/lib/elasticsearch/api/actions/reindex_rethrottle.rb +36 -11
  142. data/lib/elasticsearch/api/actions/remote/info.rb +18 -2
  143. data/lib/elasticsearch/api/actions/render_search_template.rb +41 -15
  144. data/lib/elasticsearch/api/actions/scripts_painless_execute.rb +38 -14
  145. data/lib/elasticsearch/api/actions/scroll.rb +51 -51
  146. data/lib/elasticsearch/api/actions/search.rb +96 -121
  147. data/lib/elasticsearch/api/actions/search_shards.rb +43 -15
  148. data/lib/elasticsearch/api/actions/search_template.rb +64 -37
  149. data/lib/elasticsearch/api/actions/snapshot/cleanup_repository.rb +58 -0
  150. data/lib/elasticsearch/api/actions/snapshot/clone.rb +66 -0
  151. data/lib/elasticsearch/api/actions/snapshot/create.rb +39 -26
  152. data/lib/elasticsearch/api/actions/snapshot/create_repository.rb +37 -23
  153. data/lib/elasticsearch/api/actions/snapshot/delete.rb +38 -21
  154. data/lib/elasticsearch/api/actions/snapshot/delete_repository.rb +35 -17
  155. data/lib/elasticsearch/api/actions/snapshot/get.rb +40 -29
  156. data/lib/elasticsearch/api/actions/snapshot/get_repository.rb +38 -20
  157. data/lib/elasticsearch/api/actions/snapshot/params_registry.rb +20 -4
  158. data/lib/elasticsearch/api/actions/snapshot/restore.rb +39 -31
  159. data/lib/elasticsearch/api/actions/snapshot/status.rb +41 -21
  160. data/lib/elasticsearch/api/actions/snapshot/verify_repository.rb +36 -12
  161. data/lib/elasticsearch/api/actions/tasks/cancel.rb +39 -12
  162. data/lib/elasticsearch/api/actions/tasks/get.rb +34 -12
  163. data/lib/elasticsearch/api/actions/tasks/list.rb +35 -16
  164. data/lib/elasticsearch/api/actions/tasks/params_registry.rb +20 -4
  165. data/lib/elasticsearch/api/actions/termvectors.rb +71 -65
  166. data/lib/elasticsearch/api/actions/update.rb +68 -72
  167. data/lib/elasticsearch/api/actions/update_by_query.rb +84 -62
  168. data/lib/elasticsearch/api/actions/update_by_query_rethrottle.rb +36 -11
  169. data/lib/elasticsearch/api/namespace/cat.rb +17 -1
  170. data/lib/elasticsearch/api/namespace/cluster.rb +17 -0
  171. data/lib/elasticsearch/api/namespace/common.rb +17 -0
  172. data/lib/elasticsearch/api/namespace/dangling_indices.rb +35 -0
  173. data/lib/elasticsearch/api/namespace/indices.rb +17 -0
  174. data/lib/elasticsearch/api/namespace/ingest.rb +17 -0
  175. data/lib/elasticsearch/api/namespace/nodes.rb +17 -0
  176. data/lib/elasticsearch/api/namespace/remote.rb +17 -0
  177. data/lib/elasticsearch/api/namespace/snapshot.rb +17 -0
  178. data/lib/elasticsearch/api/namespace/tasks.rb +17 -0
  179. data/lib/elasticsearch/api/utils.rb +17 -0
  180. data/lib/elasticsearch/api/version.rb +18 -1
  181. data/lib/elasticsearch/api.rb +22 -2
  182. data/lib/elasticsearch-api.rb +17 -0
  183. data/spec/elasticsearch/api/actions/abort_benchmark_spec.rb +17 -0
  184. data/spec/elasticsearch/api/actions/benchmark_spec.rb +17 -0
  185. data/spec/elasticsearch/api/actions/bulk_spec.rb +17 -0
  186. data/spec/elasticsearch/api/actions/cat/aliases_spec.rb +18 -1
  187. data/spec/elasticsearch/api/actions/cat/allocation_spec.rb +18 -1
  188. data/spec/elasticsearch/api/actions/cat/count_spec.rb +18 -1
  189. data/spec/elasticsearch/api/actions/cat/fielddata_spec.rb +19 -2
  190. data/spec/elasticsearch/api/actions/cat/health_spec.rb +18 -1
  191. data/spec/elasticsearch/api/actions/cat/help_spec.rb +18 -1
  192. data/spec/elasticsearch/api/actions/cat/indices_spec.rb +18 -1
  193. data/spec/elasticsearch/api/actions/cat/master_spec.rb +18 -1
  194. data/spec/elasticsearch/api/actions/cat/nodeattrs_spec.rb +18 -1
  195. data/spec/elasticsearch/api/actions/cat/nodes_spec.rb +18 -1
  196. data/spec/elasticsearch/api/actions/cat/pending_tasks_spec.rb +18 -1
  197. data/spec/elasticsearch/api/actions/cat/plugins_spec.rb +18 -1
  198. data/spec/elasticsearch/api/actions/cat/recovery_spec.rb +18 -1
  199. data/spec/elasticsearch/api/actions/cat/repositories_spec.rb +18 -1
  200. data/spec/elasticsearch/api/actions/cat/segments_spec.rb +36 -5
  201. data/spec/elasticsearch/api/actions/cat/shards_spec.rb +18 -1
  202. data/spec/elasticsearch/api/actions/cat/snapshot_spec.rb +18 -1
  203. data/spec/elasticsearch/api/actions/cat/tasks_spec.rb +18 -1
  204. data/spec/elasticsearch/api/actions/cat/templates_spec.rb +18 -1
  205. data/spec/elasticsearch/api/actions/cat/thread_pool_spec.rb +18 -1
  206. data/spec/elasticsearch/api/actions/clear_scroll_spec.rb +21 -2
  207. data/spec/elasticsearch/api/actions/cluster/allocation_explain_spec.rb +18 -1
  208. data/spec/elasticsearch/api/actions/cluster/get_settings_spec.rb +18 -1
  209. data/spec/elasticsearch/api/actions/cluster/health_spec.rb +20 -3
  210. data/spec/elasticsearch/api/actions/cluster/pending_tasks_spec.rb +18 -1
  211. data/spec/elasticsearch/api/actions/cluster/put_settings_spec.rb +19 -2
  212. data/spec/elasticsearch/api/actions/cluster/remote_info_spec.rb +18 -1
  213. data/spec/elasticsearch/api/actions/cluster/reroute_spec.rb +19 -2
  214. data/spec/elasticsearch/api/actions/cluster/state_spec.rb +19 -2
  215. data/spec/elasticsearch/api/actions/cluster/stats_spec.rb +18 -18
  216. data/spec/elasticsearch/api/actions/count_spec.rb +30 -10
  217. data/spec/elasticsearch/api/actions/create_document_spec.rb +25 -4
  218. data/spec/elasticsearch/api/actions/dangling_indices/delete_dangling_indices_spec.rb +48 -0
  219. data/spec/elasticsearch/api/actions/dangling_indices/import_dangling_indices_spec.rb +48 -0
  220. data/spec/elasticsearch/api/actions/dangling_indices/list_dangling_indices_spec.rb +36 -0
  221. data/spec/elasticsearch/api/actions/delete_by_query_spec.rb +33 -8
  222. data/spec/elasticsearch/api/actions/delete_document_spec.rb +21 -8
  223. data/spec/elasticsearch/api/actions/delete_script_spec.rb +19 -15
  224. data/spec/elasticsearch/api/actions/exists_document_spec.rb +20 -2
  225. data/spec/elasticsearch/api/actions/explain_document_spec.rb +26 -15
  226. data/spec/elasticsearch/api/actions/field_caps_spec.rb +19 -1
  227. data/spec/elasticsearch/api/actions/get_document_source_spec.rb +24 -4
  228. data/spec/elasticsearch/api/actions/get_document_spec.rb +20 -2
  229. data/spec/elasticsearch/api/actions/get_script_spec.rb +25 -14
  230. data/spec/elasticsearch/api/actions/hashie_spec.rb +17 -0
  231. data/spec/elasticsearch/api/actions/index_document_spec.rb +25 -22
  232. data/spec/elasticsearch/api/actions/indices/add_block_spec.rb +63 -0
  233. data/spec/elasticsearch/api/actions/indices/analyze_spec.rb +24 -12
  234. data/spec/elasticsearch/api/actions/indices/clear_cache_spec.rb +8 -8
  235. data/spec/elasticsearch/api/actions/indices/clone_spec.rb +122 -0
  236. data/spec/elasticsearch/api/actions/indices/close_spec.rb +18 -1
  237. data/spec/elasticsearch/api/actions/indices/create_spec.rb +18 -1
  238. data/spec/elasticsearch/api/actions/indices/delete_alias_spec.rb +20 -3
  239. data/spec/elasticsearch/api/actions/indices/delete_spec.rb +18 -1
  240. data/spec/elasticsearch/api/actions/indices/delete_template_spec.rb +18 -1
  241. data/spec/elasticsearch/api/actions/indices/exists_alias_spec.rb +18 -1
  242. data/spec/elasticsearch/api/actions/indices/exists_spec.rb +18 -1
  243. data/spec/elasticsearch/api/actions/indices/exists_template_spec.rb +18 -1
  244. data/spec/elasticsearch/api/actions/indices/exists_type_spec.rb +18 -1
  245. data/spec/elasticsearch/api/actions/indices/flush_spec.rb +18 -1
  246. data/spec/elasticsearch/api/actions/indices/flush_synced_spec.rb +18 -1
  247. data/spec/elasticsearch/api/actions/indices/forcemerge_spec.rb +18 -1
  248. data/spec/elasticsearch/api/actions/indices/freeze_spec.rb +85 -0
  249. data/spec/elasticsearch/api/actions/indices/get_alias_spec.rb +18 -1
  250. data/spec/elasticsearch/api/actions/indices/get_field_mapping_spec.rb +18 -1
  251. data/spec/elasticsearch/api/actions/indices/get_mapping_spec.rb +18 -1
  252. data/spec/elasticsearch/api/actions/indices/get_settings_spec.rb +18 -1
  253. data/spec/elasticsearch/api/actions/indices/get_spec.rb +18 -12
  254. data/spec/elasticsearch/api/actions/indices/open_spec.rb +18 -1
  255. data/spec/elasticsearch/api/actions/indices/put_alias_spec.rb +21 -4
  256. data/spec/elasticsearch/api/actions/indices/put_mapping_spec.rb +21 -4
  257. data/spec/elasticsearch/api/actions/indices/put_settings_spec.rb +33 -1
  258. data/spec/elasticsearch/api/actions/indices/put_template_spec.rb +18 -1
  259. data/spec/elasticsearch/api/actions/indices/recovery_spec.rb +18 -1
  260. data/spec/elasticsearch/api/actions/indices/refresh_spec.rb +18 -1
  261. data/spec/elasticsearch/api/actions/indices/rollover_spec.rb +18 -1
  262. data/spec/elasticsearch/api/actions/indices/segments_spec.rb +18 -1
  263. data/spec/elasticsearch/api/actions/indices/shard_stores_spec.rb +18 -1
  264. data/spec/elasticsearch/api/actions/indices/shrink_spec.rb +18 -1
  265. data/spec/elasticsearch/api/actions/indices/split_spec.rb +18 -1
  266. data/spec/elasticsearch/api/actions/indices/stats_spec.rb +124 -0
  267. data/spec/elasticsearch/api/actions/indices/unfreeze_spec.rb +85 -0
  268. data/spec/elasticsearch/api/actions/indices/update_aliases_spec.rb +18 -1
  269. data/spec/elasticsearch/api/actions/indices/upgrade_spec.rb +18 -1
  270. data/spec/elasticsearch/api/actions/indices/validate_query_spec.rb +24 -13
  271. data/spec/elasticsearch/api/actions/info_spec.rb +19 -1
  272. data/spec/elasticsearch/api/actions/ingest/delete_pipeline_spec.rb +18 -1
  273. data/spec/elasticsearch/api/actions/ingest/get_pipeline_spec.rb +18 -1
  274. data/spec/elasticsearch/api/actions/ingest/put_pipeline_spec.rb +18 -1
  275. data/spec/elasticsearch/api/actions/ingest/simulate_spec.rb +23 -7
  276. data/spec/elasticsearch/api/actions/json_builders_spec.rb +27 -11
  277. data/spec/elasticsearch/api/actions/mget_spec.rb +22 -5
  278. data/spec/elasticsearch/api/actions/msearch_spec.rb +38 -39
  279. data/spec/elasticsearch/api/actions/msearch_template_spec.rb +22 -6
  280. data/spec/elasticsearch/api/actions/mtermvectors_spec.rb +24 -6
  281. data/spec/elasticsearch/api/actions/nodes/hot_threads_spec.rb +21 -4
  282. data/spec/elasticsearch/api/actions/nodes/info_spec.rb +18 -1
  283. data/spec/elasticsearch/api/actions/nodes/reload_secure_settings_spec.rb +24 -10
  284. data/spec/elasticsearch/api/actions/nodes/shutdown_spec.rb +17 -0
  285. data/spec/elasticsearch/api/actions/nodes/stats_spec.rb +18 -1
  286. data/spec/elasticsearch/api/actions/ping_spec.rb +20 -2
  287. data/spec/elasticsearch/api/actions/put_script_spec.rb +39 -15
  288. data/spec/elasticsearch/api/actions/reindex_spec.rb +20 -2
  289. data/spec/elasticsearch/api/actions/remote/info_spec.rb +17 -0
  290. data/spec/elasticsearch/api/actions/render_search_template_spec.rb +44 -9
  291. data/spec/elasticsearch/api/actions/scroll_spec.rb +52 -0
  292. data/spec/elasticsearch/api/actions/search_shards_spec.rb +20 -2
  293. data/spec/elasticsearch/api/actions/search_spec.rb +24 -6
  294. data/spec/elasticsearch/api/actions/search_template_spec.rb +22 -5
  295. data/spec/elasticsearch/api/actions/snapshot/clone_spec.rb +67 -0
  296. data/spec/elasticsearch/api/actions/snapshot/create_repository_spec.rb +18 -1
  297. data/spec/elasticsearch/api/actions/snapshot/create_spec.rb +18 -1
  298. data/spec/elasticsearch/api/actions/snapshot/delete_repository_spec.rb +18 -1
  299. data/spec/elasticsearch/api/actions/snapshot/delete_spec.rb +18 -1
  300. data/spec/elasticsearch/api/actions/snapshot/get_repository_spec.rb +18 -1
  301. data/spec/elasticsearch/api/actions/snapshot/get_spec.rb +18 -1
  302. data/spec/elasticsearch/api/actions/snapshot/restore_spec.rb +18 -1
  303. data/spec/elasticsearch/api/actions/snapshot/status_spec.rb +18 -1
  304. data/spec/elasticsearch/api/actions/snapshot/verify_repository_spec.rb +18 -1
  305. data/spec/elasticsearch/api/actions/tasks/cancel_spec.rb +18 -1
  306. data/spec/elasticsearch/api/actions/tasks/get_spec.rb +18 -1
  307. data/spec/elasticsearch/api/actions/tasks/list_spec.rb +18 -12
  308. data/spec/elasticsearch/api/actions/termvectors_spec.rb +22 -12
  309. data/spec/elasticsearch/api/actions/update_by_query_spec.rb +20 -2
  310. data/spec/elasticsearch/api/actions/update_document_spec.rb +22 -14
  311. data/spec/elasticsearch/api/api_spec.rb +17 -0
  312. data/spec/elasticsearch/api/client_spec.rb +17 -0
  313. data/spec/elasticsearch/api/rest_api_yaml_spec.rb +138 -0
  314. data/spec/elasticsearch/api/utils_spec.rb +18 -1
  315. data/spec/rest_yaml_tests_helper.rb +107 -0
  316. data/spec/spec_helper.rb +33 -34
  317. data/utils/Gemfile +18 -0
  318. data/utils/README.md +41 -0
  319. data/utils/Thorfile +4 -1
  320. data/utils/thor/.rubocop.yml +2 -0
  321. data/utils/thor/generate_source.rb +248 -81
  322. data/utils/thor/generator/endpoint_specifics.rb +181 -0
  323. data/utils/thor/generator/files_helper.rb +60 -0
  324. data/utils/thor/lister.rb +20 -4
  325. data/utils/thor/templates/_documentation_top.erb +39 -0
  326. data/utils/thor/templates/_method_setup.erb +35 -0
  327. data/utils/thor/templates/_params_registry.erb +12 -0
  328. data/utils/thor/templates/_perform_request.erb +38 -0
  329. data/utils/thor/templates/method.erb +73 -0
  330. data/utils/thor/templates/{ruby/test.erb → test.erb} +4 -0
  331. data/utils/thor/templates/{ruby/test_helper.rb → test_helper.rb} +17 -1
  332. metadata +123 -124
  333. data/LICENSE.txt +0 -13
  334. data/lib/elasticsearch/api/actions/count_percolate.rb +0 -82
  335. data/lib/elasticsearch/api/actions/delete_template.rb +0 -21
  336. data/lib/elasticsearch/api/actions/field_stats.rb +0 -36
  337. data/lib/elasticsearch/api/actions/get_template.rb +0 -27
  338. data/lib/elasticsearch/api/actions/indices/delete_mapping.rb +0 -26
  339. data/lib/elasticsearch/api/actions/indices/delete_warmer.rb +0 -32
  340. data/lib/elasticsearch/api/actions/indices/get_aliases.rb +0 -37
  341. data/lib/elasticsearch/api/actions/indices/get_warmer.rb +0 -62
  342. data/lib/elasticsearch/api/actions/indices/optimize.rb +0 -77
  343. data/lib/elasticsearch/api/actions/indices/put_warmer.rb +0 -65
  344. data/lib/elasticsearch/api/actions/indices/seal.rb +0 -24
  345. data/lib/elasticsearch/api/actions/indices/snapshot_index.rb +0 -44
  346. data/lib/elasticsearch/api/actions/indices/status.rb +0 -63
  347. data/lib/elasticsearch/api/actions/list_benchmarks.rb +0 -27
  348. data/lib/elasticsearch/api/actions/mlt.rb +0 -130
  349. data/lib/elasticsearch/api/actions/mpercolate.rb +0 -62
  350. data/lib/elasticsearch/api/actions/percolate.rb +0 -73
  351. data/lib/elasticsearch/api/actions/put_template.rb +0 -25
  352. data/lib/elasticsearch/api/actions/search_exists.rb +0 -63
  353. data/lib/elasticsearch/api/actions/suggest.rb +0 -49
  354. data/spec/elasticsearch/api/actions/count_percolate_spec.rb +0 -17
  355. data/spec/elasticsearch/api/actions/delete_template_spec.rb +0 -17
  356. data/spec/elasticsearch/api/actions/field_stats_spec.rb +0 -17
  357. data/spec/elasticsearch/api/actions/get_template_spec.rb +0 -52
  358. data/spec/elasticsearch/api/actions/indices/delete_mapping_spec.rb +0 -77
  359. data/spec/elasticsearch/api/actions/indices/delete_warmer_spec.rb +0 -86
  360. data/spec/elasticsearch/api/actions/indices/get_aliases_spec.rb +0 -55
  361. data/spec/elasticsearch/api/actions/indices/get_template_spec.rb +0 -59
  362. data/spec/elasticsearch/api/actions/indices/get_warmer_spec.rb +0 -48
  363. data/spec/elasticsearch/api/actions/indices/optimize_spec.rb +0 -63
  364. data/spec/elasticsearch/api/actions/indices/put_warmer_spec.rb +0 -101
  365. data/spec/elasticsearch/api/actions/indices/seal_spec.rb +0 -18
  366. data/spec/elasticsearch/api/actions/indices/snapshot_index_spec.rb +0 -89
  367. data/spec/elasticsearch/api/actions/indices/status_spec.rb +0 -92
  368. data/spec/elasticsearch/api/actions/list_benchmarks_spec.rb +0 -17
  369. data/spec/elasticsearch/api/actions/mlt_spec.rb +0 -130
  370. data/spec/elasticsearch/api/actions/mpercolate_spec.rb +0 -49
  371. data/spec/elasticsearch/api/actions/percolate_spec.rb +0 -67
  372. data/spec/elasticsearch/api/actions/put_template_spec.rb +0 -17
  373. data/spec/elasticsearch/api/actions/scoll_spec.rb +0 -17
  374. data/spec/elasticsearch/api/actions/search_exists_spec.rb +0 -63
  375. data/spec/elasticsearch/api/actions/suggest_spec.rb +0 -77
  376. data/test/integration/yaml_test_runner.rb +0 -546
  377. data/test/test_helper.rb +0 -42
  378. data/utils/thor/generate_api.rb +0 -189
  379. data/utils/thor/templates/ruby/method.erb +0 -60
@@ -1,135 +1,302 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # encoding: UTF-8
2
19
 
3
20
  require 'thor'
4
-
5
21
  require 'pathname'
6
22
  require 'active_support/core_ext/hash/deep_merge'
7
23
  require 'active_support/inflector'
8
24
  require 'multi_json'
9
25
  require 'coderay'
10
26
  require 'pry'
27
+ require_relative 'generator/files_helper'
28
+ require_relative 'generator/endpoint_specifics'
11
29
 
12
30
  module Elasticsearch
13
-
14
31
  module API
15
-
16
32
  # A command line application based on [Thor](https://github.com/wycats/thor),
17
33
  # which will read the JSON API spec file(s), and generate
18
34
  # the Ruby source code (one file per API endpoint) with correct
19
35
  # module namespace, method names, and RDoc documentation,
20
36
  # as well as test files for each endpoint.
21
37
  #
22
- # Currently it only generates Ruby source, but can easily be
23
- # extended and adapted to generate source code for other
24
- # programming languages.
38
+ # Specific exceptions and code snippets that need to be included are written
39
+ # in EndpointSpecifics (generator/endpoint_specifics) and the module is included
40
+ # here.
25
41
  #
26
42
  class SourceGenerator < Thor
27
43
  namespace 'api:code'
28
-
29
44
  include Thor::Actions
45
+ include EndpointSpecifics
46
+
47
+ __root = Pathname(File.expand_path('../../..', __FILE__))
30
48
 
31
- __root = Pathname( File.expand_path('../../..', __FILE__) )
49
+ desc 'generate', 'Generate source code and tests from the REST API JSON specification'
50
+ method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
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)'
32
53
 
33
- desc "generate <PATH TO JSON SPEC FILES>", "Generate source code and tests from the REST API JSON specification"
34
- method_option :language, default: 'ruby', desc: 'Programming language'
35
- method_option :force, type: :boolean, default: false, desc: 'Overwrite the output'
36
- method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
37
- method_option :input, default: File.expand_path('../../../../tmp/elasticsearch/rest-api-spec/api/**/*.json', __FILE__), desc: 'Path to directory with JSON API specs'
38
- method_option :output, default: File.expand_path('../../../tmp/out', __FILE__), desc: 'Path to output directory'
54
+ def generate
55
+ self.class.source_root File.expand_path(__dir__)
56
+ @xpack = options[:api].include? 'xpack'
57
+ @oss = options[:api].include? 'oss'
39
58
 
40
- def generate(*files)
41
- self.class.source_root File.expand_path('../', __FILE__)
59
+ __generate_source(:xpack) if @xpack
60
+ __generate_source(:oss) if @oss
61
+ # -- Tree output
62
+ print_tree if options[:verbose]
63
+ end
42
64
 
43
- @input = Pathname(options[:input])
44
- @output = Pathname(options[:output])
65
+ private
45
66
 
46
- # -- Test helper
47
- copy_file "templates/ruby/test_helper.rb", @output.join('test').join('test_helper.rb') if options[:language] == 'ruby'
67
+ def __generate_source(api)
68
+ @current_api = api
69
+ @input = FilesHelper.input_dir(api)
70
+ @output = FilesHelper.output_dir(api)
48
71
 
49
- Dir[@input].each do |file|
50
- next if File.basename(file)[0] == '_'
51
- @path = Pathname(file)
52
- @json = MultiJson.load( File.read(@path) )
53
- @spec = @json.values.first
72
+ FilesHelper.files(api).each do |filepath|
73
+ @path = Pathname(@input.join(filepath))
74
+ @json = MultiJson.load(File.read(@path))
75
+ @spec = @json.values.first
54
76
  say_status 'json', @path, :yellow
55
77
 
56
78
  @spec['url'] ||= {}
57
- @spec['url']['parts'] ||= []
58
- @spec['url']['params'] ||= {}
59
-
60
- # say_status 'JSON', @spec.inspect, options[:verbose]
61
79
 
62
- @full_namespace = @json.keys.first.split('.')
63
- @namespace_depth = @full_namespace.size > 0 ? @full_namespace.size-1 : 0
80
+ @endpoint_name = @json.keys.first
81
+ @full_namespace = __full_namespace
82
+ @namespace_depth = @full_namespace.size > 0 ? @full_namespace.size - 1 : 0
64
83
  @module_namespace = @full_namespace[0, @namespace_depth]
65
84
  @method_name = @full_namespace.last
66
- @http_method = "Elasticsearch::API::HTTP_#{@spec['methods'].first}"
67
- @http_path = unless @spec['url']['parts'].empty?
68
- @spec['url']['path']
69
- .split('/')
70
- .compact
71
- .reject { |p| p =~ /^\s*$/ }
72
- .map { |p| p =~ /\{/ ? "\#\{arguments[:#{p.tr('{}', '')}]\}" : p }
73
- .join('/')
74
- .gsub(/^\//, '')
75
- else
76
- @spec['url']['path'].gsub(/^\//, '')
77
- end
78
-
79
- # -- Ruby files
80
-
81
- @path_to_file = @output.join('api').join( @module_namespace.join('/') ).join("#{@method_name}.rb")
82
-
83
- empty_directory @output.join('api').join( @module_namespace.join('/') )
84
-
85
- template "templates/#{options[:language]}/method.erb", @path_to_file
86
-
87
- if options[:verbose]
88
- colorized_output = CodeRay.scan_file(@path_to_file, :ruby).terminal
89
- lines = colorized_output.split("\n")
90
- say_status options[:language].downcase,
91
- lines.first + "\n" + lines[1, lines.size].map { |l| ' '*14 + l }.join("\n"),
92
- :yellow
85
+ @parts = __endpoint_parts
86
+ @params = @spec['params'] || {}
87
+ @specific_params = specific_params(@module_namespace.first) # See EndpointSpecifics
88
+ @http_method = __http_method
89
+ @paths = @spec['url']['paths'].map { |b| b['path'] }
90
+ # Using Ruby's safe operator on array:
91
+ @deprecation_note = @spec['url']['paths'].last&.[]('deprecated')
92
+ @http_path = __http_path
93
+ @required_parts = __required_parts
94
+
95
+ @module_namespace.shift if @module_namespace.first == 'xpack'
96
+ @path_to_file = @output.join(@module_namespace.join('/')).join("#{@method_name}.rb")
97
+ dir = @output.join(@module_namespace.join('/'))
98
+ empty_directory(dir, verbose: false)
99
+
100
+ # Write the file with the ERB template:
101
+ template('templates/method.erb', @path_to_file, force: true)
102
+
103
+ print_source_code(@path_to_file) if options[:verbose]
104
+
105
+ generate_tests if options[:tests]
106
+
107
+ puts
108
+ end
109
+
110
+ run_rubocop(api)
111
+ end
112
+
113
+ def __full_namespace
114
+ names = @endpoint_name.split('.')
115
+ if @current_api == :xpack
116
+ names = (names.first == 'xpack' ? names : ['xpack', names].flatten)
117
+ # Return an array to expand 'ccr', 'ilm', 'ml' and 'slm'
118
+ names.map do |name|
119
+ name
120
+ .gsub(/^ml$/, 'machine_learning')
121
+ .gsub(/^ilm$/, 'index_lifecycle_management')
122
+ .gsub(/^ccr/, 'cross_cluster_replication')
123
+ .gsub(/^slm/, 'snapshot_lifecycle_management')
93
124
  end
125
+ else
126
+ names
127
+ end
128
+ end
94
129
 
95
- # --- Test files
130
+ # Create the hierarchy of directories based on API namespaces
131
+ #
132
+ def __create_directories(key, value)
133
+ return if value['documentation']
96
134
 
97
- @test_directory = @output.join('test/api').join( @module_namespace.join('/') )
98
- @test_file = @test_directory.join("#{@method_name}_test.rb")
135
+ empty_directory @output.join(key)
136
+ create_directory_hierarchy * value.to_a.first
137
+ end
99
138
 
100
- empty_directory @test_directory
101
- template "templates/#{options[:language]}/test.erb", @test_file
139
+ # Extract parts from each path
140
+ #
141
+ def __endpoint_parts
142
+ parts = @spec['url']['paths'].select do |a|
143
+ a.keys.include?('parts')
144
+ end.map do |path|
145
+ path&.[]('parts')
146
+ end
147
+ (parts.inject(&:merge) || [])
148
+ end
102
149
 
103
- if options[:verbose]
104
- colorized_output = colorized_output = CodeRay.scan_file(@test_file, :ruby).terminal
105
- lines = colorized_output.split("\n")
106
- say_status options[:language].downcase,
107
- lines.first + "\n" + lines[1, lines.size].map { |l| ' '*14 + l }.join("\n"),
108
- :yellow
109
- say ''*terminal_width
150
+ def __http_method
151
+ return '_id ? Elasticsearch::API::HTTP_PUT : Elasticsearch::API::HTTP_POST' if @endpoint_name == 'index'
152
+
153
+ default_method = @spec['url']['paths'].map { |a| a['methods'] }.flatten.first
154
+ if @spec['body'] && default_method == 'GET'
155
+ # When default method is GET and body is required, we should always use POST
156
+ if @spec['body']['required']
157
+ 'Elasticsearch::API::HTTP_POST'
158
+ else
159
+ <<~SRC
160
+ if arguments[:body]
161
+ Elasticsearch::API::HTTP_POST
162
+ else
163
+ Elasticsearch::API::HTTP_GET
164
+ end
165
+ SRC
110
166
  end
167
+ else
168
+ "Elasticsearch::API::HTTP_#{default_method}"
111
169
  end
170
+ end
112
171
 
113
- # -- Tree output
172
+ def __http_path
173
+ return "\"#{__parse_path(@paths.first)}\"" if @paths.size == 1
174
+ return termvectors_path if @method_name == 'termvectors'
114
175
 
115
- if options[:verbose] && `which tree > /dev/null 2>&1; echo $?`.to_i < 1
116
- lines = `tree #{@output}`.split("\n")
117
- say_status 'tree',
118
- lines.first + "\n" + lines[1, lines.size].map { |l| ' '*14 + l }.join("\n")
176
+ result = ''
177
+ anchor_string = []
178
+ @paths.sort { |a, b| b.length <=> a.length }.each_with_index do |path, i|
179
+ var_string = __extract_path_variables(path).map { |var| "_#{var}" }.join(' && ')
180
+ next if anchor_string.include? var_string
181
+
182
+ anchor_string << var_string
183
+ result += if i.zero?
184
+ "if #{var_string}\n"
185
+ elsif (i == @paths.size - 1) || var_string.empty?
186
+ "else\n"
187
+ else
188
+ "elsif #{var_string}\n"
189
+ end
190
+ result += "\"#{__parse_path(path)}\"\n"
119
191
  end
192
+ result += 'end'
193
+ result
120
194
  end
121
195
 
122
- private
196
+ def __parse_path(path)
197
+ path.gsub(/^\//, '')
198
+ .gsub(/\/$/, '')
199
+ .gsub('{', "\#{#{__utils}.__listify(_")
200
+ .gsub('}', ')}')
201
+ end
123
202
 
124
- # Create the hierarchy of directories based on API namespaces
203
+ def __path_variables
204
+ @paths.map do |path|
205
+ __extract_path_variables(path)
206
+ end
207
+ end
208
+
209
+ # extract values that are in the {var} format:
210
+ def __extract_path_variables(path)
211
+ path.scan(/{(\w+)}/).flatten
212
+ end
213
+
214
+ # Find parts that are definitely required and should raise an error if
215
+ # they're not present
125
216
  #
126
- def __create_directories(key, value)
127
- unless value['documentation']
128
- empty_directory @output.join(key)
129
- create_directory_hierarchy *value.to_a.first
217
+ def __required_parts
218
+ required = []
219
+ return required if @endpoint_name == 'tasks.get'
220
+
221
+ required << 'body' if (@spec['body'] && @spec['body']['required'])
222
+ # Get required variables from paths:
223
+ req_variables = __path_variables.inject(:&) # find intersection
224
+ required << req_variables unless req_variables.empty?
225
+ required.flatten
226
+ end
227
+
228
+ def docs_helper(name, info)
229
+ info['type'] = 'String' if info['type'] == 'enum' # Rename 'enums' to 'strings'
230
+ tipo = info['type'] ? info['type'].capitalize : 'String'
231
+ description = info['description'] ? info['description'].strip : '[TODO]'
232
+ options = info['options'] ? "(options: #{info['options'].join(', ').strip})" : nil
233
+ required = info['required'] ? '(*Required*)' : ''
234
+ deprecated = info['deprecated'] ? '*Deprecated*' : ''
235
+ optionals = [required, deprecated, options].join(' ').strip
236
+
237
+ "# @option arguments [#{tipo}] :#{name} #{description} #{optionals}\n"
238
+ end
239
+
240
+ def stability_doc_helper(stability)
241
+ return if stability == 'stable'
242
+
243
+ if stability == 'experimental'
244
+ <<~MSG
245
+ # This functionality is Experimental and may be changed or removed
246
+ # completely in a future release. Elastic will take a best effort approach
247
+ # to fix any issues, but experimental features are not subject to the
248
+ # support SLA of official GA features.
249
+ MSG
250
+ elsif stability == 'beta'
251
+ <<~MSG
252
+ # This functionality is in Beta and is subject to change. The design and
253
+ # code is less mature than official GA features and is being provided
254
+ # as-is with no warranties. Beta features are not subject to the support
255
+ # SLA of official GA features.
256
+ MSG
257
+ else
258
+ <<~MSG
259
+ # This functionality is subject to potential breaking changes within a
260
+ # minor version, meaning that your referencing code may break when this
261
+ # library is upgraded.
262
+ MSG
130
263
  end
131
264
  end
132
265
 
266
+ def generate_tests
267
+ copy_file 'templates/test_helper.rb', @output.join('test').join('test_helper.rb')
268
+
269
+ @test_directory = @output.join('test/api').join(@module_namespace.join('/'))
270
+ @test_file = @test_directory.join("#{@method_name}_test.rb")
271
+
272
+ empty_directory @test_directory
273
+ template 'templates/test.erb', @test_file
274
+
275
+ print_source_code(@test_file) if options[:verbose]
276
+ end
277
+
278
+ def print_source_code(path_to_file)
279
+ colorized_output = CodeRay.scan_file(path_to_file, :ruby).terminal
280
+ lines = colorized_output.split("\n")
281
+ formatted = lines.first + "\n" + lines[1, lines.size].map { |l| ' ' * 14 + l }.join("\n")
282
+
283
+ say_status('ruby', formatted, :yellow)
284
+ end
285
+
286
+ def print_tree
287
+ return unless `which tree > /dev/null 2>&1; echo $?`.to_i < 1
288
+
289
+ lines = `tree #{@output}`.split("\n")
290
+ say_status('tree', lines.first + "\n" + lines[1, lines.size].map { |l| ' ' * 14 + l }.join("\n"))
291
+ end
292
+
293
+ def __utils
294
+ (@current_api == :xpack) ? 'Elasticsearch::API::Utils' : 'Utils'
295
+ end
296
+
297
+ def run_rubocop(api)
298
+ system("rubocop -c ./thor/.rubocop.yml --format autogenconf -x #{FilesHelper::output_dir(api)}")
299
+ end
133
300
  end
134
301
  end
135
302
  end
@@ -0,0 +1,181 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Elasticsearch
19
+ module API
20
+ # Handles specific exceptional parameters and code snippets that need to be
21
+ # included in the generated code. This module is included in SourceGenerator
22
+ # so its methods can be used from the ERB template (method.erb). This will
23
+ # potentially be refactored into different templates.
24
+ module EndpointSpecifics
25
+ # Endpoints that need Utils.__rescue_from_not_found
26
+ IGNORE_404 = %w[
27
+ exists
28
+ indices.exists
29
+ indices.exists_alias
30
+ indices.exists_template
31
+ indices.exists_type
32
+ ].freeze
33
+
34
+ # Endpoints that need Utils.__rescue_from_not_found if the ignore
35
+ # parameter is included
36
+ COMPLEX_IGNORE_404 = %w[
37
+ delete
38
+ get
39
+ indices.flush_synced
40
+ indices.delete_template
41
+ indices.delete
42
+ security.get_role
43
+ security.get_user
44
+ snapshot.status
45
+ snapshot.get
46
+ snapshot.get_repository
47
+ snapshot.delete_repository
48
+ snapshot.delete
49
+ update
50
+ watcher.delete_watch
51
+ ].freeze
52
+
53
+ # Endpoints that need params[:h] listified
54
+ H_PARAMS = %w[aliases allocation count health indices nodes pending_tasks
55
+ recovery shards thread_pool].freeze
56
+
57
+ # Function that adds the listified h param code
58
+ def specific_params(namespace)
59
+ params = []
60
+ if H_PARAMS.include?(@method_name) && namespace == 'cat'
61
+ if @method_name == 'nodes'
62
+ params << 'params[:h] = Utils.__listify(params[:h], escape: false) if params[:h]'
63
+ else
64
+ params << 'params[:h] = Utils.__listify(params[:h]) if params[:h]'
65
+ end
66
+ end
67
+ params
68
+ end
69
+
70
+ def needs_ignore_404?(endpoint)
71
+ IGNORE_404.include? endpoint
72
+ end
73
+
74
+ def needs_complex_ignore_404?(endpoint)
75
+ COMPLEX_IGNORE_404.include? endpoint
76
+ end
77
+
78
+ def module_name_helper(name)
79
+ return name.upcase if %w[sql ssl].include? name
80
+
81
+ name.split('_').map(&:capitalize).join
82
+ end
83
+
84
+ def termvectors_path
85
+ <<~SRC
86
+ if _index && _type && _id
87
+ "\#{Utils.__listify(_index)}/\#{Utils.__listify(_type)}/\#{Utils.__listify(_id)}/\#{endpoint}"
88
+ elsif _index && _type
89
+ "\#{Utils.__listify(_index)}/\#{Utils.__listify(_type)}/\#{endpoint}"
90
+ elsif _index && _id
91
+ "\#{Utils.__listify(_index)}/\#{endpoint}/\#{Utils.__listify(_id)}"
92
+ else
93
+ "\#{Utils.__listify(_index)}/\#{endpoint}"
94
+ end
95
+ SRC
96
+ end
97
+
98
+ def ping_perform_request
99
+ <<~SRC
100
+ begin
101
+ perform_request(method, path, params, body, headers).status == 200 ? true : false
102
+ rescue Exception => e
103
+ if e.class.to_s =~ /NotFound|ConnectionFailed/ || e.message =~ /Not\s*Found|404|ConnectionFailed/i
104
+ false
105
+ else
106
+ raise e
107
+ end
108
+ end
109
+ SRC
110
+ end
111
+
112
+ def indices_stats_params_registry
113
+ <<~SRC
114
+ ParamsRegistry.register(:stats_params, [
115
+ #{@spec['params'].keys.map { |k| ":#{k}" }.join(",\n")}
116
+ ].freeze)
117
+
118
+ ParamsRegistry.register(:stats_parts, [
119
+ #{@parts['metric']['options'].push('metric').map { |k| ":#{k}" }.join(",\n")}
120
+ ].freeze)
121
+ SRC
122
+ end
123
+
124
+ def msearch_body_helper
125
+ <<~SRC
126
+ case
127
+ when body.is_a?(Array) && body.any? { |d| d.has_key? :search }
128
+ payload = body.
129
+ inject([]) do |sum, item|
130
+ meta = item
131
+ data = meta.delete(:search)
132
+
133
+ sum << meta
134
+ sum << data
135
+ sum
136
+ end.
137
+ map { |item| Elasticsearch::API.serializer.dump(item) }
138
+ payload << "" unless payload.empty?
139
+ payload = payload.join("\\n")
140
+ when body.is_a?(Array)
141
+ payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) }
142
+ payload << "" unless payload.empty?
143
+ payload = payload.join("\\n")
144
+ else
145
+ payload = body
146
+ end
147
+ SRC
148
+ end
149
+
150
+ def msearch_template_body_helper
151
+ <<~SRC
152
+ case
153
+ when body.is_a?(Array)
154
+ payload = body.map { |d| d.is_a?(String) ? d : Elasticsearch::API.serializer.dump(d) }
155
+ payload << "" unless payload.empty?
156
+ payload = payload.join("\n")
157
+ else
158
+ payload = body
159
+ end
160
+ SRC
161
+ end
162
+
163
+ def bulk_body_helper
164
+ <<~SRC
165
+ if body.is_a? Array
166
+ payload = Elasticsearch::API::Utils.__bulkify(body)
167
+ else
168
+ payload = body
169
+ end
170
+ SRC
171
+ end
172
+
173
+ def bulk_doc_helper(info)
174
+ <<~SRC
175
+ # @option arguments [String|Array] :body #{info}. Array of Strings, Header/Data pairs,
176
+ # or the conveniency "combined" format can be passed, refer to Elasticsearch::API::Utils.__bulkify documentation.
177
+ SRC
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,60 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'pathname'
19
+ require_relative '../../../lib/elasticsearch/api/version.rb'
20
+
21
+ module Elasticsearch
22
+ module API
23
+ module FilesHelper
24
+ OSS_SRC_PATH = '../../../../../tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/'.freeze
25
+ 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
+ XPACK_OUTPUT_DIR = '../../elasticsearch-xpack/lib/elasticsearch/xpack/api/actions'.freeze
29
+
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)
38
+ end
39
+
40
+ # Path to directory to copy generated files
41
+ def self.output_dir(api)
42
+ api == :xpack ? Pathname(XPACK_OUTPUT_DIR) : Pathname(OSS_OUTPUT_DIR)
43
+ end
44
+
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
+ def self.gem_version
55
+ regex = /([0-9]{1,2}\.[0-9x]{1,2})/
56
+ Elasticsearch::API::VERSION.match(regex)[0]
57
+ end
58
+ end
59
+ end
60
+ end
data/utils/thor/lister.rb CHANGED
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # encoding: UTF-8
2
19
 
3
20
  require 'thor'
@@ -5,16 +22,16 @@ require 'thor'
5
22
  require 'pathname'
6
23
 
7
24
  module Elasticsearch
8
-
9
25
  module API
10
-
11
26
  class Lister < Thor
12
27
  namespace 'api'
13
28
 
29
+ DEFAULT_PATH = '../../tmp/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/api/'.freeze
30
+
14
31
  desc "list <PATH DIRECTORY WITH JSON SPEC FILES>", "List all the REST API endpoints from the JSON specification"
15
32
  method_option :verbose, type: :boolean, default: false, desc: 'Output more information'
16
33
  method_option :format, default: 'text', desc: 'Output format (text, json)'
17
- def list(directory)
34
+ def list(directory = DEFAULT_PATH)
18
35
  input = Pathname(directory).join('*.json')
19
36
  apis = Dir[input.to_s].map do |f|
20
37
  File.basename(f, '.json')
@@ -36,6 +53,5 @@ module Elasticsearch
36
53
  end
37
54
  end
38
55
  end
39
-
40
56
  end
41
57
  end