Skip to content

Commit fed43d2

Browse files
committed
Merge remote-tracking branch 'origin/main' into charlotte-level-string-1258
2 parents fccf397 + 82c1710 commit fed43d2

File tree

61 files changed

+368
-34834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+368
-34834
lines changed

docs/add-new-api.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# How to add a new API
22

33
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),
55
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.
77

88
> [!TIP]
99
> 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/).
1010
1111
## How to add a new endpoint
1212

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
1414
from the Elasticsearch repository inside [`/specification/_json_spec`](../specification/_json_spec)
1515
and you are good to go.
1616

@@ -20,13 +20,13 @@ or [here](https://github.com/elastic/elasticsearch/tree/7.x/x-pack/plugin/src/te
2020
## How to add the definition of an endpoint
2121

2222
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)
2424
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.
2626
For example, the index document definition can be found in [`/specification/_global/index`](../specification/_global/index).
2727

2828
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:
3030

3131
```ts
3232
// IndexRequest.ts
@@ -38,8 +38,17 @@ interface Request {}
3838
class Response {}
3939
```
4040

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:
43+
44+
[`/specification/_global/bulk/types.ts`](../specification/_global/bulk/types.ts)
45+
46+
47+
or, if there are too many types, they can be organized in separate files in a `_types` folder:
48+
49+
[`/specification/_global/search/_types`](../specification/_global/search/_types)
50+
51+
In general, try to use the fewest files possible, and check if a new type already exists before introducing it.
4352

4453
### Add the endpoint request definition
4554

@@ -63,7 +72,7 @@ Furthermore, every request definition **must** contain these JS Doc tags:
6372
- `feature_flag`: the feature flag value, only valid if the `visibility` is set to `feature_flag`.
6473
This field is only available for `stack`.
6574

66-
Following you can find a template valid for any request definition.
75+
Following, you can find a template valid for any request definition.
6776

6877
```ts
6978
/*
@@ -118,11 +127,11 @@ There are cases where the generic might be the entire body, see [`IndexRequest`]
118127

119128
### Add the endpoint response definition
120129

121-
Responses definitions should always be defined **after** a request definition,
130+
Response definitions should always be defined **after** a request definition,
122131
otherwise the compiler will not pick them up. It is required that the response
123132
definition is named `Response`.
124133

125-
Following you can find a template valid for any response definition.
134+
Following, you can find a template valid for any response definition.
126135

127136
```ts
128137
class Response {
@@ -153,7 +162,7 @@ And the generic will be used somewhere inside the definition.
153162

154163
Normally, every API returns the exact same structure in case of error, which is defined
155164
in [`ErrorResponseBase`](https://github.com/elastic/elasticsearch-specification/blob/main/specification/_types/Base.ts#L66-L75).
156-
In some edge cases, the response structure may change. To document this situations, you should use the `exceptions` key.
165+
In some edge cases, the response structure may change. To document these cases, you should use the `exceptions` key.
157166

158167
```ts
159168
class Response {

0 commit comments

Comments
 (0)