Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/kbn-spec-to-console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,38 @@ A mini utility to convert [Elasticsearch's REST spec](https://github.com/elastic

It is used to semi-manually update Console's autocompletion rules.

### Retrieving the spec

If you don't have a copy of the Elasticsearch repo on your machine, follow these steps to clone only the rest API specs

### Retrieving the spec
```
cd es-spec
mkdir es-spec && cd es-spec
git init
git remote add origin https://github.com/elastic/elasticsearch
git config core.sparsecheckout true
echo "rest-api-spec/src/main/resources/rest-api-spec/api/*" > .git/info/sparse-checkout
echo "rest-api-spec/src/main/resources/rest-api-spec/api/*\nx-pack/plugin/src/test/resources/rest-api-spec/api/*" > .git/info/sparse-checkout
git pull --depth=1 origin master
```

### Usage
```

You need to run the command twice: once for the **OSS** specs and once for the **X-Pack** specs
At the root of the Kibana repository, run the following commands:

```sh
# OSS
yarn spec_to_console \
-g "<ELASTICSEARCH-REPO-FOLDER>/rest-api-spec/src/main/resources/rest-api-spec/api/*" \
-d "src/legacy/core_plugins/console/api_server/spec/generated"

# X-pack
yarn spec_to_console \
-g "es-spec/rest-api-spec/src/main/resources/rest-api-spec/api/*.json" \
-d "../kibana/src/core_plugins/console/api_server/spec/generated"
-g "<ELASTICSEARCH-REPO-FOLDER>/x-pack/plugin/src/test/resources/rest-api-spec/api/*" \
-d "x-pack/plugins/console_extensions/spec/generated"
```

### Information used in Console that is not available in the REST spec

* Request bodies
* Data fetched at runtime: indices, fields, snapshots, etc
* Ad hoc additions
7 changes: 6 additions & 1 deletion packages/kbn-spec-to-console/bin/spec_to_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ files.forEach(file => {
if (program.directory) {
const outputName = path.basename(file);
const outputPath = path.resolve(program.directory, outputName);
fs.writeFileSync(outputPath, output + '\n');
try {
fs.mkdirSync(program.directory, { recursive: true });
fs.writeFileSync(outputPath, output + '\n');
} catch(e) {
console.log('Cannot write file ', e);
}
} else {
console.log(output);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"bulk": {
"url_params": {
"include_type_name": "",
"wait_for_active_shards": "",
"refresh": [
"true",
Expand All @@ -12,8 +11,8 @@
"timeout": "",
"type": "",
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"pipeline": ""
},
"methods": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"help": "__flag__",
"pri": "__flag__",
"s": [],
"v": "__flag__"
"v": "__flag__",
"include_unloaded_segments": "__flag__"
},
"methods": [
"GET"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"DELETE"
],
"patterns": [
"_search/scroll/{scroll_id}",
"_search/scroll"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html"
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"local": "__flag__",
"master_timeout": "",
"flat_settings": "__flag__",
"wait_for_metadata_version": "",
"wait_for_timeout": "",
"ignore_unavailable": "__flag__",
"allow_no_indices": "__flag__",
"expand_wildcards": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"count": {
"url_params": {
"ignore_unavailable": "__flag__",
"ignore_throttled": "__flag__",
"allow_no_indices": "__flag__",
"expand_wildcards": [
"open",
Expand Down Expand Up @@ -29,8 +30,7 @@
],
"patterns": [
"_count",
"{indices}/_count",
"{indices}/{type}/_count"
"{indices}/_count"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"create": {
"url_params": {
"wait_for_active_shards": "",
"parent": "",
"refresh": [
"true",
"false",
Expand All @@ -24,7 +23,7 @@
"POST"
],
"patterns": [
"{indices}/{type}/{id}/_create"
"{indices}/_create/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"delete": {
"url_params": {
"include_type_name": "",
"wait_for_active_shards": "",
"parent": "",
"refresh": [
"true",
"false",
"wait_for"
],
"routing": "",
"timeout": "",
"if_seq_no": "",
"if_primary_term": "",
"version": "",
"version_type": [
"internal",
Expand All @@ -23,7 +23,6 @@
"DELETE"
],
"patterns": [
"{indices}/{type}/{id}",
"{indices}/_doc/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
"dfs_query_then_fetch"
],
"search_timeout": "",
"size": "10",
"size": "",
"max_docs": "all documents",
"sort": [],
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"terminate_after": "",
"stats": [],
"version": "__flag__",
Expand All @@ -52,8 +53,7 @@
"POST"
],
"patterns": [
"{indices}/_delete_by_query",
"{indices}/{type}/_delete_by_query"
"{indices}/_delete_by_query"
],
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"delete_by_query_rethrottle": {
"url_params": {
"requests_per_second": ""
},
"methods": [
"POST"
],
"patterns": [
"_delete_by_query/{task_id}/_rethrottle"
],
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"exists": {
"url_params": {
"stored_fields": [],
"parent": "",
"preference": "random",
"realtime": "__flag__",
"refresh": "__flag__",
"routing": "",
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"version": "",
"version_type": [
"internal",
Expand All @@ -22,7 +21,7 @@
"HEAD"
],
"patterns": [
"{indices}/{type}/{id}"
"{indices}/_doc/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"exists_source": {
"url_params": {
"parent": "",
"preference": "random",
"realtime": "__flag__",
"refresh": "__flag__",
"routing": "",
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"version": "",
"version_type": [
"internal",
Expand All @@ -21,7 +20,7 @@
"HEAD"
],
"patterns": [
"{indices}/{type}/{id}/_source"
"{indices}/_source/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
"df": "_all",
"stored_fields": [],
"lenient": "__flag__",
"parent": "",
"preference": "random",
"q": "",
"routing": "",
"_source": [],
"_source_exclude": [],
"_source_include": []
"_source_excludes": [],
"_source_includes": []
},
"methods": [
"GET",
"POST"
],
"patterns": [
"{indices}/{type}/{id}/_explain"
"{indices}/_explain/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"closed",
"none",
"all"
]
],
"include_unmapped": "__flag__"
},
"methods": [
"GET",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"get": {
"url_params": {
"include_type_name": "",
"stored_fields": [],
"parent": "",
"preference": "random",
"realtime": "__flag__",
"refresh": "__flag__",
"routing": "",
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"version": "",
"version_type": [
"internal",
Expand All @@ -23,7 +21,6 @@
"GET"
],
"patterns": [
"{indices}/{type}/{id}",
"{indices}/_doc/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"get_script": {
"url_params": {
"master_timeout": ""
},
"methods": [
"GET"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"get_source": {
"url_params": {
"parent": "",
"preference": "random",
"realtime": "__flag__",
"refresh": "__flag__",
"routing": "",
"_source": [],
"_source_exclude": [],
"_source_include": [],
"_source_excludes": [],
"_source_includes": [],
"version": "",
"version_type": [
"internal",
Expand All @@ -21,7 +20,7 @@
"GET"
],
"patterns": [
"{indices}/{type}/{id}/_source"
"{indices}/_source/{id}"
],
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html"
}
Expand Down
Loading