Skip to content

Commit da9a86d

Browse files
committed
Add stepper, info
1 parent 3924bba commit da9a86d

File tree

1 file changed

+127
-17
lines changed

1 file changed

+127
-17
lines changed

extend/contribute/api-docs/quickstart.md

Lines changed: 127 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
2-
navigation_title: Contribute locally: quickstarts
2+
navigation_title: Quickstarts
33
---
44

55
# Contribute to Elastic API docs locally: Quickstart guides
66

7+
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+
79
::::::::{tab-set}
810
:::::::{tab-item} Elasticsearch
911

@@ -99,6 +101,7 @@ You should try to fix all linter warnings and not just errors. Fixing errors alo
99101
```shell
100102
make overlay-docs
101103
```
104+
::::
102105

103106
::::{step} Preview your changes
104107
Generate a preview of how your docs will appear:
@@ -122,34 +125,134 @@ Once you're satisfied with your docs changes:
122125

123126
:::::::
124127

125-
:::::::{tab-item} Kibana
126-
Follow these steps to capture live API specs from Kibana, generate OpenAPI documentation, and view a preview URL.
128+
:::::::{tab-item} {{kib}}
129+
130+
Follow these steps to capture live API specs from {{kib}}, generate OpenAPI documentation, and view a preview URL.
127131

128-
## Step 0: Set up Kibana environment
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.
134+
:::
135+
136+
:::::{stepper}
137+
138+
::::{step} Set up {{kib}} environment
129139

130140
```bash
131141
cd kibana
132142
nvm use
133143
yarn kbn bootstrap
134144
```
135145

136-
**Note:** Run `yarn kbn clean` first if dependencies are broken.
146+
:::{note}
147+
Run `yarn kbn clean` first if dependencies are broken.
148+
:::
149+
::::
137150

138-
## Step 0.1: Start Docker
151+
::::{step} Start Docker
139152
Ensure Docker is running, otherwise things will fail slowly.
153+
::::
140154

141-
## Step 1: Capture OAS snapshot
155+
::::{step} Enable OAS in {{kib}}
142156

143-
### 1.1: Ensure OAS is enabled
144-
`kibana/config/kibana.dev.yml` shoud look like this:
157+
Ensure `kibana/config/kibana.dev.yml` contains:
145158
```yaml
146159
server.oas.enabled: true
147160
```
161+
::::
148162
149-
### 1.2: Run capture command
163+
::::{step} Add examples to your routes (optional)
164+
165+
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+
167+
:::{dropdown} Inline TypeScript examples
168+
You can add examples directly in your route definitions:
169+
```typescript
170+
.addVersion({
171+
version: '2023-10-31',
172+
options: {
173+
oasOperationObject: () => ({
174+
requestBody: {
175+
content: {
176+
'application/json': {
177+
examples: {
178+
fooExample1: {
179+
summary: 'An example foo request',
180+
value: {
181+
name: 'Cool foo!',
182+
} as FooResource,
183+
},
184+
},
185+
},
186+
},
187+
},
188+
}),
189+
},
190+
// ...
191+
})
192+
```
193+
:::
150194

151-
You can just include your API set of interest, here it's for all plugins per [`capture_oas_snapshot.sh`](https://github.com/elastic/kibana/blob/main/.buildkite/scripts/steps/checks/capture_oas_snapshot.sh).
195+
:::{dropdown} YAML-based examples
196+
For pre-existing YAML examples:
197+
```typescript
198+
import path from 'node:path';
199+
200+
const oasOperationObject = () => path.join(__dirname, 'foo.examples.yaml');
201+
202+
.addVersion({
203+
version: '2023-10-31',
204+
options: {
205+
oasOperationObject,
206+
},
207+
validate: {
208+
request: {
209+
body: fooResource,
210+
},
211+
response: {
212+
200: {
213+
body: fooResourceResponse,
214+
},
215+
},
216+
},
217+
})
218+
```
152219

220+
Where `foo.examples.yaml` contains:
221+
```yaml
222+
requestBody:
223+
content:
224+
application/json:
225+
examples: # Use examples (plural), not example (deprecated)
226+
fooExample:
227+
summary: Foo example
228+
description: >
229+
An example request of creating foo.
230+
value:
231+
name: 'Cool foo!'
232+
fooExampleRef:
233+
# You can use JSONSchema $refs to organize further
234+
$ref: "./examples/foo_example_i_factored_out_of_this_file.yaml"
235+
responses:
236+
200:
237+
content:
238+
application/json:
239+
examples:
240+
# Apply a similar pattern for response examples
241+
```
242+
:::
243+
::::
244+
245+
::::{step} Capture OAS snapshot
246+
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+
:::
250+
251+
Run this step when you've made changes to route definitions, request/response schemas, or added new HTTP APIs in your plugin code.
252+
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.
254+
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):
153256

154257
```bash
155258
node scripts/capture_oas_snapshot \
@@ -168,21 +271,28 @@ node scripts/capture_oas_snapshot \
168271
--include-path /api/agent_builder
169272
```
170273

171-
**Output:** `oas_docs/bundle.json` and `oas_docs/bundle.serverless.json`
274+
This generates `oas_docs/bundle.json` and `oas_docs/bundle.serverless.json`.
275+
::::
172276

173-
## Step 2: Generate docs
277+
::::{step} Generate docs
174278
```bash
175279
cd oas_docs
176280
make api-docs
177281
```
178282

179-
**Output:** `oas_docs/output/kibana.yaml` and `oas_docs/output/kibana.info.yaml`
283+
This generates `oas_docs/output/kibana.yaml` and `oas_docs/output/kibana.info.yaml`.
284+
285+
Use `make help` to see available commands.
286+
::::
180287

181-
## Step 3: Preview the API docs
288+
::::{step} Preview the API docs
182289
```bash
183290
make api-docs-preview
184291
```
185292

186293
This creates a short-lived URL preview on Bump.sh.
187-
:::::::
188-
::::::::
294+
::::
295+
296+
:::::
297+
298+
:::::::

0 commit comments

Comments
 (0)