Skip to content

Commit

Permalink
Backport spec_to_console script to work with new JSON file format. (e…
Browse files Browse the repository at this point in the history
…lastic#43427)

* Backport spec_to_console script to work with new JSON file format.

* Updated test fixture to use new JSON file pattern

* Fix if statement
  • Loading branch information
jloleysens committed Aug 19, 2019
1 parent 7a7d689 commit 9e23063
Show file tree
Hide file tree
Showing 118 changed files with 319 additions and 215 deletions.
45 changes: 30 additions & 15 deletions packages/kbn-spec-to-console/lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,61 @@
* under the License.
*/


const convertParams = require('./convert/params');
const convertMethods = require('./convert/methods');
const convertPaths = require('./convert/paths');
const convertParts = require('./convert/parts');

module.exports = spec => {
const result = {};
// TODO:
// Since https://github.com/elastic/elasticsearch/pull/42346 has been merged into ES master
// the JSON doc specification has been updated. We need to update this script to take advantage
// of the added information but it will also require updating console's editor autocomplete.
Object.keys(spec).forEach(api => {
const source = spec[api];
if (!source.url) {
return result;
}
const convertedSpec = result[api] = {};
if (source.url && source.url.params) {
const urlParams = convertParams(source.url.params);
const convertedSpec = (result[api] = {});
if (source.params) {
const urlParams = convertParams(source.params);
if (Object.keys(urlParams).length > 0) {
convertedSpec.url_params = urlParams;
}
}

if (source.methods) {
convertedSpec.methods = convertMethods(source.methods);
}
const methodSet = new Set();
let patterns;
const urlComponents = {};

if (source.url.paths) {
convertedSpec.patterns = convertPaths(source.url.paths);
patterns = convertPaths(source.url.paths);
source.url.paths.forEach(pathsObject => {
pathsObject.methods.forEach(method => methodSet.add(method));
if (pathsObject.parts) {
for (const partName of Object.keys(pathsObject.parts)) {
urlComponents[partName] = pathsObject.parts[partName];
}
}
});
}

if (source.url.parts) {
const components = convertParts(source.url.parts);
const hasComponents = Object.keys(components).filter(c => {
return Boolean(components[c]);
}).length > 0;
convertedSpec.methods = convertMethods(Array.from(methodSet));
convertedSpec.patterns = patterns;

if (Object.keys(urlComponents).length) {
const components = convertParts(urlComponents);
const hasComponents =
Object.keys(components).filter(c => {
return Boolean(components[c]);
}).length > 0;
if (hasComponents) {
convertedSpec.url_components = convertParts(source.url.parts);
convertedSpec.url_components = convertParts(urlComponents);
}
}
if (source.documentation) {
convertedSpec.documentation = source.documentation;
convertedSpec.documentation = source.documentation.url;
}
});

Expand Down
1 change: 0 additions & 1 deletion packages/kbn-spec-to-console/lib/convert/parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/


const replacePattern = require('../replace_pattern');

module.exports = parts => {
Expand Down
5 changes: 2 additions & 3 deletions packages/kbn-spec-to-console/lib/convert/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
* under the License.
*/


const replacePattern = require('../replace_pattern');

module.exports = patterns => {
return patterns.map(pattern => {
return replacePattern(pattern, { brackets: true });
return patterns.map(patternObject => {
return replacePattern(patternObject.path, { brackets: true });
});
};
1 change: 0 additions & 1 deletion packages/kbn-spec-to-console/lib/replace_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/


const map = require('./static/map_interpolation');

module.exports = (pattern, { brackets, exact } = {}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"cluster.health": {
"url_params": {
"expand_wildcards": [
"open",
"closed",
"none",
"all"
],
"level": [
"cluster",
"indices",
Expand Down Expand Up @@ -34,6 +40,6 @@
"_cluster/health",
"_cluster/health/{indices}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html"
}
}
156 changes: 98 additions & 58 deletions packages/kbn-spec-to-console/test/fixtures/cluster_health_spec.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,104 @@
{
"cluster.health": {
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html",
"methods": ["GET"],
"url": {
"path": "/_cluster/health",
"paths": ["/_cluster/health", "/_cluster/health/{index}"],
"parts": {
"index": {
"type" : "list",
"description" : "Limit the information returned to a specific index"
}
},
"params": {
"level": {
"type" : "enum",
"options" : ["cluster","indices","shards"],
"default" : "cluster",
"description" : "Specify the level of detail for returned information"
},
"local": {
"type" : "boolean",
"description" : "Return local information, do not retrieve the state from master node (default: false)"
},
"master_timeout": {
"type" : "time",
"description" : "Explicit operation timeout for connection to master node"
},
"timeout": {
"type" : "time",
"description" : "Explicit operation timeout"
},
"wait_for_active_shards": {
"type" : "string",
"description" : "Wait until the specified number of shards is active"
},
"wait_for_nodes": {
"type" : "string",
"description" : "Wait until the specified number of nodes is available"
},
"wait_for_events": {
"type" : "enum",
"options" : ["immediate", "urgent", "high", "normal", "low", "languid"],
"description" : "Wait until all currently queued events with the given priority are processed"
},
"wait_for_no_relocating_shards": {
"type" : "boolean",
"description" : "Whether to wait until there are no relocating shards in the cluster"
},
"wait_for_no_initializing_shards": {
"type" : "boolean",
"description" : "Whether to wait until there are no initializing shards in the cluster"
"cluster.health":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html",
"description":"Returns basic information about the health of the cluster."
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_cluster/health",
"methods":[
"GET"
]
},
"wait_for_status": {
"type" : "enum",
"options" : ["green","yellow","red"],
"default" : null,
"description" : "Wait until cluster is in a specific state"
{
"path":"/_cluster/health/{index}",
"methods":[
"GET"
],
"parts":{
"index":{
"type":"list",
"description":"Limit the information returned to a specific index"
}
}
}
}
]
},
"body": null
"params":{
"expand_wildcards":{
"type":"enum",
"options":[
"open",
"closed",
"none",
"all"
],
"default":"all",
"description":"Whether to expand wildcard expression to concrete indices that are open, closed or both."
},
"level":{
"type":"enum",
"options":[
"cluster",
"indices",
"shards"
],
"default":"cluster",
"description":"Specify the level of detail for returned information"
},
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
},
"master_timeout":{
"type":"time",
"description":"Explicit operation timeout for connection to master node"
},
"timeout":{
"type":"time",
"description":"Explicit operation timeout"
},
"wait_for_active_shards":{
"type":"string",
"description":"Wait until the specified number of shards is active"
},
"wait_for_nodes":{
"type":"string",
"description":"Wait until the specified number of nodes is available"
},
"wait_for_events":{
"type":"enum",
"options":[
"immediate",
"urgent",
"high",
"normal",
"low",
"languid"
],
"description":"Wait until all currently queued events with the given priority are processed"
},
"wait_for_no_relocating_shards":{
"type":"boolean",
"description":"Whether to wait until there are no relocating shards in the cluster"
},
"wait_for_no_initializing_shards":{
"type":"boolean",
"description":"Whether to wait until there are no initializing shards in the cluster"
},
"wait_for_status":{
"type":"enum",
"options":[
"green",
"yellow",
"red"
],
"default":null,
"description":"Wait until cluster is in a specific state"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"{indices}/_bulk",
"{indices}/{type}/_bulk"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"_cat/aliases",
"_cat/aliases/{name}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"_cat/allocation",
"_cat/allocation/{nodes}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"_cat/count",
"_cat/count/{indices}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"_cat/fielddata",
"_cat/fielddata/{fields}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"patterns": [
"_cat/health"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"patterns": [
"_cat"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"_cat/indices",
"_cat/indices/{indices}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"patterns": [
"_cat/master"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"patterns": [
"_cat/nodeattrs"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"patterns": [
"_cat/nodes"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"patterns": [
"_cat/pending_tasks"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"patterns": [
"_cat/plugins"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html"
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html"
}
}
Loading

0 comments on commit 9e23063

Please sign in to comment.