From 12e88d6f870fbecad7c27b20f3076ba73f1a0075 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 26 Apr 2019 09:25:34 +0200 Subject: [PATCH] Support for deprecated paths (#828) * Updated code generation * API generation * Updated test --- api/api/delete.js | 6 ------ api/api/index.js | 6 ------ api/api/indices.put_mapping.js | 10 ++++++++++ api/api/nodes.hot_threads.js | 5 +++++ scripts/utils/generateApis.js | 12 +++++++++++- test/integration/index.js | 3 +++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/api/api/delete.js b/api/api/delete.js index 35ab29398..6f835dcc8 100644 --- a/api/api/delete.js +++ b/api/api/delete.js @@ -94,12 +94,6 @@ function buildDelete (opts) { return handleError(err, callback) } - // check required url components - if (params['id'] != null && (params['index'] == null)) { - const err = new ConfigurationError('Missing required parameter of the url: index') - return handleError(err, callback) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) diff --git a/api/api/index.js b/api/api/index.js index 716d8c4cf..07e1a09c3 100644 --- a/api/api/index.js +++ b/api/api/index.js @@ -96,12 +96,6 @@ function buildIndex (opts) { return handleError(err, callback) } - // check required url components - if (params['id'] != null && (params['index'] == null)) { - const err = new ConfigurationError('Missing required parameter of the url: index') - return handleError(err, callback) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) diff --git a/api/api/indices.put_mapping.js b/api/api/indices.put_mapping.js index 491ffd2db..da848cfb1 100644 --- a/api/api/indices.put_mapping.js +++ b/api/api/indices.put_mapping.js @@ -111,6 +111,7 @@ function buildIndicesPutMapping (opts) { } else if ((index) != null && (type) != null) { path = '/' + encodeURIComponent(index) + '/' + '_mappings' + '/' + encodeURIComponent(type) } else if ((type) != null) { +<<<<<<< HEAD path = '/' + '_mapping' + '/' + encodeURIComponent(type) } else if ((type) != null) { path = '/' + '_mappings' + '/' + encodeURIComponent(type) @@ -118,6 +119,15 @@ function buildIndicesPutMapping (opts) { path = '/' + encodeURIComponent(index) + '/' + '_mappings' } else { path = '/' + encodeURIComponent(index) + '/' + '_mapping' +======= + path = '/' + '_mappings' + '/' + encodeURIComponent(type) + } else if ((type) != null) { + path = '/' + '_mapping' + '/' + encodeURIComponent(type) + } else if ((index) != null) { + path = '/' + encodeURIComponent(index) + '/' + '_mapping' + } else { + path = '/' + encodeURIComponent(index) + '/' + '_mappings' +>>>>>>> 349b832... Support for deprecated paths (#828) } // build request object diff --git a/api/api/nodes.hot_threads.js b/api/api/nodes.hot_threads.js index 12f59399c..fdb0f4cae 100644 --- a/api/api/nodes.hot_threads.js +++ b/api/api/nodes.hot_threads.js @@ -101,9 +101,14 @@ function buildNodesHotThreads (opts) { } else if ((node_id || nodeId) != null) { path = '/' + '_cluster' + '/' + 'nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hot_threads' } else if ((node_id || nodeId) != null) { +<<<<<<< HEAD path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hotthreads' } else if ((node_id || nodeId) != null) { +======= +>>>>>>> 349b832... Support for deprecated paths (#828) path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hot_threads' + } else if ((node_id || nodeId) != null) { + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'hotthreads' } else { path = '/' + '_cluster' + '/' + 'nodes' + '/' + 'hotthreads' } diff --git a/scripts/utils/generateApis.js b/scripts/utils/generateApis.js index 33fd4eded..9dbeb04b3 100644 --- a/scripts/utils/generateApis.js +++ b/scripts/utils/generateApis.js @@ -17,6 +17,8 @@ * under the License. */ +/* eslint camelcase: 0 */ + 'use strict' const dedent = require('dedent') @@ -33,6 +35,7 @@ const noPathValidation = [ 'explain', 'get', 'get_source', + 'index', 'indices.get_alias', 'indices.exists_alias', 'indices.get_field_mapping', @@ -40,6 +43,7 @@ const noPathValidation = [ 'indices.get_settings', 'indices.put_mapping', 'indices.stats', + 'delete', 'nodes.info', 'nodes.stats', 'nodes.usage', @@ -66,10 +70,16 @@ function generate (spec, common) { .replace(/_([a-z])/g, k => k[1].toUpperCase()) const methods = spec[api].methods - const { paths, parts, params } = spec[api].url + const { paths, deprecated_paths, parts, params } = spec[api].url const acceptedQuerystring = [] const required = [] + if (deprecated_paths) { + for (const p of deprecated_paths) { + paths.push(p.path) + } + } + for (const key in parts) { if (parts[key].required) { required.push(key) diff --git a/test/integration/index.js b/test/integration/index.js index eca6dd474..98745b6e7 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -34,6 +34,9 @@ const esFolder = join(__dirname, '..', '..', 'elasticsearch') const yamlFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'rest-api-spec', 'test') const xPackYamlFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'test') const customSkips = [ + // TODO: remove this once 'arbitrary_key' is implemented + // https://github.com/elastic/elasticsearch/pull/41492 + 'indices.split/30_copy_settings.yml', // skipping because we are booting ES with `discovery.type=single-node` // and this test will fail because of this configuration 'nodes.stats/30_discovery.yml',