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
Copy file name to clipboardExpand all lines: docs/add-new-api.md
+21-12Lines changed: 21 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
# How to add a new API
2
2
3
3
It might happen that a new API in Elasticsearch is not yet defined
4
-
in this repository, or we do have an endpoint definition in [`/specification/_json_spec`](../specification/_json_spec)
4
+
in this repository, or we do have an endpoint definition in [`/specification/_json_spec`](../specification/_json_spec),
5
5
but we don't have a type definition for it.
6
-
In this document you will see how to add a new endpoint and how to add a new endpoint definition.
6
+
This document explains how to add a new endpoint and how to add a new endpoint definition.
7
7
8
8
> [!TIP]
9
9
> To learn more about how to write docs specifically for our [API references](https://www.elastic.co/docs/api/), refer to the [Contribute to Elastic API docs](https://www.elastic.co/docs/extend/contribute/api-docs/).
10
10
11
11
## How to add a new endpoint
12
12
13
-
Add a new endpoint is straightforward, you only need to copy-paste the json rest-api-spec definition
13
+
Adding a new endpoint is straightforward, you only need to copy-paste the json rest-api-spec definition
14
14
from the Elasticsearch repository inside [`/specification/_json_spec`](../specification/_json_spec)
15
15
and you are good to go.
16
16
@@ -20,13 +20,13 @@ or [here](https://github.com/elastic/elasticsearch/tree/7.x/x-pack/plugin/src/te
20
20
## How to add the definition of an endpoint
21
21
22
22
Once you have added a new endpoint definition, the next step is to add its type definition.
23
-
First of all, you should find the most appropriate place inside [`/specification`](../specification)
23
+
First, you should find the most appropriate place inside [`/specification`](../specification)
24
24
where to put the new definition. The content of [`/specification`](../specification)
25
-
tried to mimic the Elasticsearch online documentation, so you can use it as inspiration.
25
+
tries to mimic the Elasticsearch online documentation, so you can use that as inspiration.
26
26
For example, the index document definition can be found in [`/specification/_global/index`](../specification/_global/index).
27
27
28
28
Once you have found the best place for the new definition, you should create a new file for it.
29
-
The filename should be the same of the type definition you are writing, for example:
29
+
The filename should be the same as the type definition you are writing, for example:
30
30
31
31
```ts
32
32
// IndexRequest.ts
@@ -38,8 +38,17 @@ interface Request {}
38
38
classResponse {}
39
39
```
40
40
41
-
Try to use less files as possible, for example there is no need to create a custom file for an enum,
42
-
you can define it in the same file where it's used, unless is a commonly used type.
41
+
The request and response files should only contain the main type definition: everything else, from subtypes to enums, should
42
+
be placed in a separate file, usually called types.ts, at the same level in the hierarchy, for example:
0 commit comments