Skip to content

Commit 881c9c9

Browse files
committed
WIP
1 parent dc41b61 commit 881c9c9

File tree

1 file changed

+111
-43
lines changed

1 file changed

+111
-43
lines changed

extend/contribute/api-docs/quickstart.md

Lines changed: 111 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ navigation_title: Quickstarts
66

77
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.
88

9-
::::::::{tab-set}
10-
:::::::{tab-item} Elasticsearch
9+
## Elasticsearch
1110

1211
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.
1312

@@ -123,48 +122,88 @@ Once you're satisfied with your docs changes:
123122

124123
:::::
125124

126-
:::::::
125+
## {{kib}}
127126

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:
129128

130-
Follow these steps to capture live API specs from {{kib}}, generate OpenAPI documentation, and view a preview URL.
129+
::::{tab-set}
131130

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.
134134
:::
135135

136-
:::::{stepper}
136+
:::{tab-item} Manually-maintained APIs
137137

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:
139151

140152
```bash
141-
cd kibana
142153
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
143170
yarn kbn bootstrap
144171
```
145172

146173
:::{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).
148175
:::
149176
::::
150177

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+
153191
::::
154192

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.
156195

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".
161197
::::
162198

163-
::::{step} Add examples to your routes (optional)
199+
::::::
200+
201+
:::::{step} Add examples to your routes (optional)
164202

203+
(For code-generated APIs)
165204
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.
166205

167-
:::{dropdown} Inline TypeScript examples
206+
::::{dropdown} Inline TypeScript examples
168207
You can add examples directly in your route definitions:
169208
```typescript
170209
.addVersion({
@@ -190,9 +229,9 @@ You can add examples directly in your route definitions:
190229
// ...
191230
})
192231
```
193-
:::
232+
::::
194233

195-
:::{dropdown} YAML-based examples
234+
::::{dropdown} YAML-based examples
196235
For pre-existing YAML examples:
197236
```typescript
198237
import path from 'node:path';
@@ -239,38 +278,34 @@ responses:
239278
examples:
240279
# Apply a similar pattern for response examples
241280
```
242-
:::
243281
::::
282+
:::::
244283

245-
::::{step} Capture OAS snapshot
284+
::::{step} For code-generated APIs: Capture OAS snapshot
246285

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.
250287

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
252290

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):
254292

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:
256298

257299
```bash
258300
node scripts/capture_oas_snapshot \
259301
--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
272303
```
273304

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+
274309
This generates `oas_docs/bundle.json` and `oas_docs/bundle.serverless.json`.
275310
::::
276311

@@ -285,6 +320,21 @@ This generates `oas_docs/output/kibana.yaml` and `oas_docs/output/kibana.info.ya
285320
Use `make help` to see available commands.
286321
::::
287322

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+
288338
::::{step} Preview the API docs
289339
```bash
290340
make api-docs-preview
@@ -293,6 +343,24 @@ make api-docs-preview
293343
This creates a short-lived URL preview on Bump.sh.
294344
::::
295345

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.
362+
:::
363+
296364
:::::
297365

298-
:::::::
366+
::::::::

0 commit comments

Comments
 (0)