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: website/docs/contributing/add-new-api-client.md
+47-25Lines changed: 47 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -2,62 +2,84 @@
2
2
title: Add a new API client
3
3
---
4
4
5
-
# Add a new API client
6
-
7
-
Adding an API client requires manual steps in order to setup the tooling, generation scripts and properly generate the code. We recommend getting inspirations from existing clients such as `javascript-recommend`.
8
-
9
5
:::info
10
6
11
7
Make sure to first [setup the repository tooling](/docs/contributing/setup-repository) to ease your journey!
12
8
13
9
:::
14
10
11
+
Adding a new API client requires some manual steps in order to have a properly working client:
12
+
13
+
1.[Writing specs](#1-writing-specs)
14
+
2.[Configuring the generator](#2-configuring-the-generator)
We recommend to have a look at [existing spec files](https://github.com/algolia/api-clients-automation/blob/main/specs/). The `bundled` folder is automatically generated, manual changes shouldn't be done in these files.
20
+
We recommend to have a look at [existing spec files](https://github.com/algolia/api-clients-automation/blob/main/specs/).
21
+
22
+
> **The `bundled` folder is automatically generated, manual changes shouldn't be done in these files.**
23
+
24
+
### Guidelines
25
+
26
+
-**Endpoints**: Each file in [the `paths` folder](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths) should contain `operationId`s for a single endpoint, multiple methods are allowed.
27
+
-**File name**:
28
+
- When the `path` file only contain one method (e.g. `GET`), we name the file after the `operationId`
29
+
- When multiple methods are present (e.g. `PUT` and `DELETE`), we pick a more generic name that is related to the endpoint itself.
30
+
-**Description/Summary**: `operationId`s must have both description and summary.
31
+
-**Complex objects**: Complex objects (nested arrays, nested objects, `oneOf`, `allOf`, etc.) must be referenced (`$ref`) in the `operationId` file and not inlined. This is required to provide a accurate naming and improve readability.
18
32
19
33
### `common` spec folder
20
34
21
-
[This folder](https://github.com/algolia/api-clients-automation/blob/main/specs/common/) hosts properties that are common to Algolia or used in multiple clients.
35
+
[The `common`folder](https://github.com/algolia/api-clients-automation/blob/main/specs/common/) hosts properties that are common to Algolia and/or used in multiple clients.
22
36
23
37
### `<clientName>` spec folder
24
38
25
39
> Example with the [search client spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/)
26
40
27
-
#### `spec.yml` file
41
+
#### **`spec.yml` file**
28
42
29
-
This file is the entry point of the client spec, it contains `servers`, `paths` and other specific information of the API. We recommend to copy an existing [`spec.yml` file](https://github.com/algolia/api-clients-automation/blob/main/specs/search/spec.yml) to get started.
43
+
The `spec.yml` file is the entry point of the client spec, it contains `servers`, `paths` and other specific information of the API. We recommend to copy an existing [`spec.yml` file](https://github.com/algolia/api-clients-automation/blob/main/specs/search/spec.yml) to get started.
30
44
31
-
#### `<clientName>`/common folder
45
+
#### **`<clientName>`/common folder**
32
46
33
-
Properties that are common to the client, for properties common to all clients, check the [common folder](#common-spec-folder).
47
+
Same as [the `common`folder](#common-spec-folder) but only related to the current client.
34
48
35
-
#### `<clientName>`/paths folder
49
+
#### **`<clientName>`/paths folder**
36
50
37
-
Path definition of the paths defined in the [spec file](#specyml-file).
51
+
Path definition of the paths defined in the [spec file](#specyml-file). See [guidelines](#guidelines).
38
52
39
-
### Send additional options to the template
53
+
### Troubleshooting
40
54
41
-
You might want to send additional information to the generators that have no link with your REST API. To do so, you can add parameters starting with `x-` at the root level of your spec, which will be available in the mustache template under the `vendorExtensions` object.
55
+
#### **Force the name of a `requestBody`**
42
56
43
-
[Example in the `search.yml` spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/paths/search/search.yml#L5) and how it is used [in a mustache file](https://github.com/algolia/api-clients-automation/blob/bf4271246f9282d3c11dd46918e74cb86d9c96dc/templates/java/libraries/okhttp-gson/api.mustache#L196).
In some cases, you can encounter wrongly named `requestBody` from the specs, which could be due to:
46
60
47
-
-**Endpoints**: Each file in the `paths` folder should contain `operationId`s for a single endpoint, but multiple methods are allowed.
48
-
-**Name**: If the path file only contain one method, we name the file same as the `operationId`, but we try to make it less specific if there is multiple methods.
49
-
-**Description/Summary**: `operationId`s must have both description and summary.
50
-
-**Complex objects**: Complex objects (nested arrays, nested objects, , `oneOf`, `allOf`, etc.) must be referenced (`$ref`) in the `operationId` file and not inlined. This is required to provide a accurate naming and improve readability.
61
+
- The type is too complex/too broad to be generated. (e.g. [An object with `additionalProperties`](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths/objects/partialUpdate.yml#L24-L33))
62
+
- The type is an alias of its model (e.g. [A list of `model`](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths/rules/saveRules.yml#L12-L20))
63
+
64
+
The [`x-codegen-request-body-name`](https://openapi-generator.tech/docs/swagger-codegen-migration/#body-parameter-name) property can be added at the root of the spec, to force the name of the generated `requestBody` property.
65
+
66
+
You can find an example of this implementation [on this PR](https://github.com/algolia/api-clients-automation/pull/896).
67
+
68
+
#### **Send additional options to the template**
69
+
70
+
You might want to send additional information to the generators. To do so, you can add parameters starting with an `x-` at the root level of your spec, which will be available in the `mustache` template under the `vendorExtensions` object.
71
+
72
+
[Example in the `search.yml` spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/paths/search/search.yml#L5-L7) and how it is used [in a mustache file](https://github.com/algolia/api-clients-automation/blob/bf4271246f9282d3c11dd46918e74cb86d9c96dc/templates/java/libraries/okhttp-gson/api.mustache#L196).
51
73
52
-
## 2. Configuring the environment
74
+
## 2. Configuring the generator
53
75
54
76
> The generator follows its own configuration file named `config/openapitools.json`
55
77
56
-
### Generation config
78
+
### Configs
57
79
58
80
[`config/openapitools.json`](https://github.com/algolia/api-clients-automation/blob/main/config/openapitools.json) and [`config/clients.config.json`](https://github.com/algolia/api-clients-automation/blob/main/config/clients.config.json) hosts the configuration of all of the generated clients with their available languages and extra information.
59
81
60
-
#### `generators`
82
+
#### Settings
61
83
62
84
Generators are referenced by key with the following pattern `<languageName>-<clientName>`. You can copy an existing object of a client and replace the `<clientName>` value with the one you'd like to generate.
63
85
@@ -75,10 +97,10 @@ Below are the options you need to **make sure to define for your client**, other
75
97
|`apiFolder`|`clients.config.json`| All | The path to the `api` folder that will host the generated code. |
76
98
|`customGenerator`|`clients.config.json`| All | The name of the generator used to generate code. |
77
99
78
-
## 3. Generate new client
100
+
## 3. Generate the client
79
101
80
102
You can find all the commands in the [CLI > clients commands page](/docs/contributing/CLI/clients-commands) and [CLI > specs commands page](/docs/contributing/CLI/specs-commands).
81
103
82
-
## 4. Implementing the Common Test Suite
104
+
## 4. Adding tests with the Common Test Suite
83
105
84
106
Clients needs to be tested, you can read more in the [Common Test Suite](/docs/contributing/testing/common-test-suite) guide.
0 commit comments