-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Console] Generate autocomplete definitions from ES specification #163301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4cb1362
32d0c70
e36b095
a40c1b9
9abbf0e
aedd77b
1c2ec83
22da200
5e13a64
eef91cc
89eb6fd
9ea0bab
237f4a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| # Generate console definitions | ||
| This package is a script to generate definitions used in Console to display autocomplete suggestions. The script is | ||
| a new implementation of `kbn-spec-to-console` package: The old script uses [JSON specs](https://github.com/elastic/elasticsearch/tree/main/rest-api-spec) from the Elasticsearch repo as the source, whereas this script uses the Elasticsearch specification [repo](https://github.com/elastic/elasticsearch-specification) as the source. | ||
| This package is a script to generate definitions used in Console to display autocomplete suggestions. | ||
| The definitions files are generated from the Elasticsearch specification [repo](https://github.com/elastic/elasticsearch-specification). | ||
| This script is | ||
| a new implementation of an old `kbn-spec-to-console` package: The old script used [JSON specs](https://github.com/elastic/elasticsearch/tree/main/rest-api-spec) in the Elasticsearch repo as the source. | ||
|
|
||
| ## Instructions | ||
| 1. Checkout the Elasticsearch specification [repo](https://github.com/elastic/elasticsearch-specification). | ||
| 2. Run the command `node scripts/generate_console_definitions.js --source <ES_SPECIFICATION_REPO> --emptyDest` | ||
| This command will use the folder `<ES_SPECIFICATION_REPO>` as the source and the constant [`AUTOCOMPLETE_DEFINITIONS_FOLDER`](https://github.com/elastic/kibana/blob/main/src/plugins/console/common/constants/autocomplete_definitions.ts) as the destination. Based on the value of the constant, the autocomplete definitions will be generated in the folder `<KIBANA_REPO>/src/plugins/server/lib/spec_definitions/json/generated`. Using the flag `--emptyDest` will remove any existing files in the destination folder. | ||
| This command will use the folder `<ES_SPECIFICATION_REPO>` as the source and the constant [`AUTOCOMPLETE_DEFINITIONS_FOLDER`](https://github.com/elastic/kibana/blob/main/src/plugins/console/common/constants/autocomplete_definitions.ts) as the destination. Based on the value of the constant, the autocomplete definitions will be generated in the folder `<KIBANA_REPO>/src/plugins/server/lib/spec_definitions/json/generated`. The flag `--emptyDest` indicates that all existing files in the destination folder will be removed. | ||
| 3. It's possible to generate the definitions into a different folder. For that pass an option to the command `--dest <DEFINITIONS_FOLDER>` and also update the constant [`AUTOCOMPLETE_DEFINITIONS_FOLDER`](https://github.com/elastic/kibana/blob/main/src/plugins/console/common/constants/autocomplete_definitions.ts) so that the Console server will load the definitions from this folder. | ||
|
|
||
| ## Functionality | ||
| This script generates definitions for all endpoints defined in the ES specification at once. | ||
| The script generates fully functional autocomplete definition files with properties as described in the [Console README.md file](https://github.com/elastic/kibana/blob/main/src/plugins/console/README.md) except `data_autocomplete_rules`. Currently, this property needs to be written manually to add autocomplete suggestions for request body parameters. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ const convertValueOf = ( | |
| return convertLiteralValue(valueOf); | ||
| } | ||
| // for query params we can ignore 'dictionary_of' and 'user_defined_value' | ||
| return ''; | ||
| throw new Error('unexpected valueOf type ' + kind); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another safeguard: the script doesn't expect types like |
||
| }; | ||
|
|
||
| const convertInstanceOf = ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,8 @@ export function setActiveApi(api) { | |
| dataType: 'json', // disable automatic guessing | ||
| headers: { | ||
| 'kbn-xsrf': 'kibana', | ||
| // workaround for serverless | ||
| 'x-elastic-internal-origin': 'Kibana', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a workaround to fix #163318, needs to be refactored to the Kibana http client
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this isn't the preferred approach, but just to confirm - are there any particular concerns with moving forward with this workaround for now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No concerns, I confirmed with the Core team that adding the header is one way to fix this issue. There are more details in this PR. My only concern is that we use jQuery ajax for this request 😓 |
||
| }, | ||
| }).then( | ||
| function (data) { | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error here because the script expects all endpoints to have
availabilityaccording to types. An error here will indicate that something changed in the schema.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding a test to expect this scenario to throw? 🤔 I've checked the .test.ts file but couldnt find any for this scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will add a test for this!