You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide provides step-by-step workflows for contributing to Elasticsearch and {{kib}} API documentation locally. These workflows enable you to validate, preview, and debug your changes before submitting them for review.
8
8
9
-
::::::::{tab-set}
10
-
:::::::{tab-item} Elasticsearch
9
+
## Elasticsearch
11
10
12
11
The Elasticsearch APIs are the foundation of the Elastic Stack and the largest API set we maintain. Because the workflow is quite complex, we created this quickstart guide to help you get started.
13
12
@@ -123,48 +122,88 @@ Once you're satisfied with your docs changes:
123
122
124
123
:::::
125
124
126
-
:::::::
125
+
## {{kib}}
127
126
128
-
:::::::{tab-item} {{kib}}
127
+
The Kibana API documentation is created by merging multiple OpenAPI documents. The workflow you follow depends on which set of APIs you're updating:
129
128
130
-
Follow these steps to capture live API specs from {{kib}}, generate OpenAPI documentation, and view a preview URL.
129
+
::::{tab-set}
131
130
132
-
:::{tip}
133
-
Refer to the {{kib}} [OAS docs README](https://github.com/elastic/kibana/tree/main/oas_docs#kibana-api-reference-documentation) for more information.
131
+
:::{tab-item} Code-generated APIs
132
+
133
+
The core Kibana APIs are automatically generated from TypeScript route definitions in the codebase. Edit the `.ts` files in your plugin, and CI will regenerate the OpenAPI files when you push your PR. You can also run the generation locally for validation.
134
134
:::
135
135
136
-
:::::{stepper}
136
+
:::{tab-item} Manually-maintained APIs
137
137
138
-
::::{step} Set up {{kib}} environment
138
+
Some teams, including Security and Observability, work with hand-edited YAML files in the `oas_docs` directory. Edit these files directly and skip the code-generation steps.
139
+
:::
140
+
::::
141
+
142
+
For the complete list of files and which workflow they follow, refer to the [merge scripts](https://github.com/elastic/kibana/tree/main/oas_docs/scripts). For more details, see the {{kib}} [OAS docs README](https://github.com/elastic/kibana/tree/main/oas_docs#kibana-api-reference-documentation).
143
+
144
+
Follow these steps to contribute to Kibana API docs locally:
145
+
146
+
::::::::{stepper}
147
+
148
+
::::{step} Prepare your environment
149
+
150
+
Run this command to set up your Node.js environment:
139
151
140
152
```bash
141
-
cd kibana
142
153
nvm use
154
+
```
155
+
156
+
If you don't have Node.js installed, refer to the [Kibana development getting started guide](https://www.elastic.co/docs/extend/kibana/development-getting-started).
157
+
::::
158
+
159
+
::::{step} Clone the repository
160
+
161
+
```bash
162
+
git clone https://github.com/elastic/kibana.git
163
+
cd kibana
164
+
```
165
+
::::
166
+
167
+
::::{step} Install dependencies
168
+
169
+
```bash
143
170
yarn kbn bootstrap
144
171
```
145
172
146
173
:::{note}
147
-
Run `yarn kbn clean` first if dependencies are broken.
174
+
If dependencies are broken or bootstrap fails, run `yarn kbn clean` first. For more troubleshooting guidance, refer to the [Kibana development getting started guide](https://www.elastic.co/docs/extend/kibana/development-getting-started).
148
175
:::
149
176
::::
150
177
151
-
::::{step} Start Docker
152
-
Ensure Docker is running, otherwise things will fail slowly.
178
+
::::::{step} Make your docs changes
179
+
180
+
Choose your workflow based on which APIs you're updating:
181
+
182
+
:::::{tab-set}
183
+
184
+
::::{tab-item} Code-generated APIs
185
+
Edit the TypeScript route definitions in your plugin code. Add JSDoc comments, request/response schemas, and examples as needed.
186
+
187
+
:::{note}
188
+
**CI will automatically regenerate the OpenAPI files when you push your `.ts` changes.** The next two steps show how to capture the snapshot and add examples locally, which is useful for validating changes before pushing or debugging issues.
189
+
:::
190
+
153
191
::::
154
192
155
-
::::{step} Enable OAS in {{kib}}
193
+
::::{tab-item} Manually-maintained APIs
194
+
Edit the YAML files directly in the `oas_docs` directory. Refer to the README alongside each file for specific guidance on adding summaries, descriptions, tags, metadata, links, and examples.
156
195
157
-
Ensure `kibana/config/kibana.dev.yml` contains:
158
-
```yaml
159
-
server.oas.enabled: true
160
-
```
196
+
Once you've made your changes, skip the next two steps and proceed to "Generate docs".
161
197
::::
162
198
163
-
::::{step} Add examples to your routes (optional)
199
+
::::::
200
+
201
+
:::::{step} Add examples to your routes (optional)
164
202
203
+
(For code-generated APIs)
165
204
Beyond schema definitions, providing concrete request and response examples significantly improves API documentation usability. Examples are type-checked at development time, so shape errors are caught during authoring.
166
205
167
-
:::{dropdown} Inline TypeScript examples
206
+
::::{dropdown} Inline TypeScript examples
168
207
You can add examples directly in your route definitions:
169
208
```typescript
170
209
.addVersion({
@@ -190,9 +229,9 @@ You can add examples directly in your route definitions:
190
229
// ...
191
230
})
192
231
```
193
-
:::
232
+
::::
194
233
195
-
:::{dropdown} YAML-based examples
234
+
::::{dropdown} YAML-based examples
196
235
For pre-existing YAML examples:
197
236
```typescript
198
237
importpathfrom'node:path';
@@ -239,38 +278,34 @@ responses:
239
278
examples:
240
279
# Apply a similar pattern for response examples
241
280
```
242
-
:::
243
281
::::
282
+
:::::
244
283
245
-
::::{step} Capture OAS snapshot
284
+
::::{step} For code-generated APIs: Capture OAS snapshot
246
285
247
-
:::{tip}
248
-
Skip this step if you've only edited manually-maintained YAML files (like `bundled.yaml`, `*.schema.yaml`, or `kibana.info.serverless.yaml`).
249
-
:::
286
+
This step captures the OpenAPI specification that {{kib}} generates at runtime from your route definitions. It spins up a local {{es}} and {{kib}} cluster with your code changes.
250
287
251
-
Run this step when you've made changes to route definitions, request/response schemas, or added new HTTP APIs in your plugin code.
288
+
Before running the capture script:
289
+
1. Ensure Docker is running
252
290
253
-
This spins up a local {{es}} and {{kib}} cluster with your code changes, then extracts the OpenAPI specification that {{kib}} generates at runtime based on your route definitions and schemas.
291
+
**To capture all API paths** (recommended for most cases):
254
292
255
-
This example includes all plugins per [`capture_oas_snapshot.sh`](https://github.com/elastic/kibana/blob/main/.buildkite/scripts/steps/checks/capture_oas_snapshot.sh):
293
+
```bash
294
+
node scripts/capture_oas_snapshot --update
295
+
```
296
+
297
+
**To capture specific API paths** (useful for faster iteration during development), specify the paths you're working on:
256
298
257
299
```bash
258
300
node scripts/capture_oas_snapshot \
259
301
--update \
260
-
--include-path /api/status \
261
-
--include-path /api/alerting/rule/ \
262
-
--include-path /api/alerting/rules \
263
-
--include-path /api/actions \
264
-
--include-path /api/security/role \
265
-
--include-path /api/spaces \
266
-
--include-path /api/streams \
267
-
--include-path /api/fleet \
268
-
--include-path /api/saved_objects/_import \
269
-
--include-path /api/saved_objects/_export \
270
-
--include-path /api/maintenance_window \
271
-
--include-path /api/agent_builder
302
+
--include-path /api/your/specific/path
272
303
```
273
304
305
+
:::{tip}
306
+
The full list of paths captured in CI is available in [`capture_oas_snapshot.sh`](https://github.com/elastic/kibana/blob/main/.buildkite/scripts/steps/checks/capture_oas_snapshot.sh). However, most contributors should use `--update` without path restrictions to ensure complete documentation.
307
+
:::
308
+
274
309
This generates `oas_docs/bundle.json` and `oas_docs/bundle.serverless.json`.
275
310
::::
276
311
@@ -285,6 +320,21 @@ This generates `oas_docs/output/kibana.yaml` and `oas_docs/output/kibana.info.ya
285
320
Use `make help` to see available commands.
286
321
::::
287
322
323
+
::::{step} Lint your docs
324
+
325
+
Run this command to lint your OpenAPI files:
326
+
327
+
```bash
328
+
node ../scripts/validate_oas_docs.js
329
+
```
330
+
331
+
You can limit the scope of APIs that the linter checks by using `--path` or `--only` options. For details and examples, add `--help`.
332
+
333
+
:::{tip}
334
+
When you open a pull request to submit API documentation changes, this linter runs in a CI check. It uses the `--assert-no-error-increase` option which causes the check to fail if the number of errors increases compared to the baseline.
335
+
:::
336
+
::::
337
+
288
338
::::{step} Preview the API docs
289
339
```bash
290
340
make api-docs-preview
@@ -293,6 +343,24 @@ make api-docs-preview
293
343
This creates a short-lived URL preview on Bump.sh.
294
344
::::
295
345
346
+
:::::{step} Open a pull request
347
+
348
+
Once you're satisfied with your docs changes, create a pull request:
349
+
350
+
::::{tab-set}
351
+
352
+
:::{tab-item} Manually-maintained APIs
353
+
Push your edited YAML files. The CI will validate your OpenAPI specs using the linter. Once approved, merge your changes.
354
+
:::
355
+
356
+
:::{tab-item} Code-generated APIs
357
+
You have two options:
358
+
- Push only your `.ts` changes and let CI regenerate the OpenAPI files automatically
359
+
- Push both your `.ts` changes and locally-generated OpenAPI files together
360
+
361
+
The CI will validate your OpenAPI specs using the linter. Once approved, merge your changes.
0 commit comments