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
+44-20Lines changed: 44 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -2,54 +2,78 @@
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
+
# Add a new API client
12
+
13
+
Adding a new API client requires some manual steps in order to have a properly working client:
14
+
15
+
1.[Writing specs](#1-writing-specs)
16
+
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.
22
+
We recommend to have a look at [existing spec files](https://github.com/algolia/api-clients-automation/blob/main/specs/).
23
+
24
+
> **The `bundled` folder is automatically generated, manual changes shouldn't be done in these files.**
25
+
26
+
### Guidelines
27
+
28
+
-**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.
29
+
-**File name**:
30
+
- When the `path` file only contain one method (e.g. `GET`), we name the file after the `operationId`
31
+
- When multiple methods are present (e.g. `PUT` and `DELETE`), we pick a more generic name that is related to the endpoint itself.
32
+
-**Description/Summary**: `operationId`s must have both description and summary.
33
+
-**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
34
19
35
### `common` spec folder
20
36
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.
37
+
[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
38
23
39
### `<clientName>` spec folder
24
40
25
41
> Example with the [search client spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/)
26
42
27
43
#### `spec.yml` file
28
44
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.
45
+
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
46
31
47
#### `<clientName>`/common folder
32
48
33
-
Properties that are common to the client, for properties common to all clients, check the [common folder](#common-spec-folder).
49
+
Same as [the `common`folder](#common-spec-folder) but only related to the current client.
34
50
35
51
#### `<clientName>`/paths folder
36
52
37
-
Path definition of the paths defined in the [spec file](#specyml-file).
53
+
Path definition of the paths defined in the [spec file](#specyml-file). See [guidelines](#guidelines).
38
54
39
-
### Send additional options to the template
55
+
### Troubleshooting
40
56
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.
57
+
#### Force the name of a `requestBody`
42
58
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 is due to:
46
62
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.
63
+
- 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))
64
+
- The body is an alias of its sub type (e.g. [A list of sub models](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths/rules/saveRules.yml#L12-L20))
65
+
66
+
The `x-codegen-request-body-name` property can be added at the root of the spec, to force the name of the generated `requestBody` property.
67
+
68
+
You can find an example of this implementation [on this PR](https://github.com/algolia/api-clients-automation/pull/896).
69
+
70
+
#### Send additional options to the template
71
+
72
+
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.
73
+
74
+
[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
75
52
-
## 2. Configuring the environment
76
+
## 2. Configuring the generator
53
77
54
78
> The generator follows its own configuration file named `config/openapitools.json`
55
79
@@ -75,10 +99,10 @@ Below are the options you need to **make sure to define for your client**, other
75
99
|`apiFolder`|`clients.config.json`| All | The path to the `api` folder that will host the generated code. |
76
100
|`customGenerator`|`clients.config.json`| All | The name of the generator used to generate code. |
77
101
78
-
## 3. Generate new client
102
+
## 3. Generate the client
79
103
80
104
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
105
82
-
## 4. Implementing the Common Test Suite
106
+
## 4. Adding tests with the Common Test Suite
83
107
84
108
Clients needs to be tested, you can read more in the [Common Test Suite](/docs/contributing/testing/common-test-suite) guide.
0 commit comments