Skip to content

Commit 03b52ec

Browse files
committed
docs: add troubleshooting section to contributing guide
1 parent 07c302b commit 03b52ec

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

website/docs/contributing/add-new-api-client.md

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,78 @@
22
title: Add a new API client
33
---
44

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-
95
:::info
106

117
Make sure to first [setup the repository tooling](/docs/contributing/setup-repository) to ease your journey!
128

139
:::
1410

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)
17+
3. [Generate the client](#3-generate-the-client)
18+
4. [Adding tests](#4-adding-tests-with-the-common-test-suite)
19+
1520
## 1. Writing specs
1621

17-
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.
1834

1935
### `common` spec folder
2036

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.
2238

2339
### `<clientName>` spec folder
2440

2541
> Example with the [search client spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/)
2642
2743
#### `spec.yml` file
2844

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.
3046

3147
#### `<clientName>`/common folder
3248

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.
3450

3551
#### `<clientName>`/paths folder
3652

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).
3854

39-
### Send additional options to the template
55+
### Troubleshooting
4056

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`
4258

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).
59+
> [Detailed issue](https://github.com/algolia/api-clients-automation/issues/891)
4460
45-
#### Guidelines
61+
In some cases, you can encounter wrongly named `requestBody` from the specs, which is due to:
4662

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).
5175

52-
## 2. Configuring the environment
76+
## 2. Configuring the generator
5377

5478
> The generator follows its own configuration file named `config/openapitools.json`
5579
@@ -75,10 +99,10 @@ Below are the options you need to **make sure to define for your client**, other
7599
| `apiFolder` | `clients.config.json` | All | The path to the `api` folder that will host the generated code. |
76100
| `customGenerator` | `clients.config.json` | All | The name of the generator used to generate code. |
77101

78-
## 3. Generate new client
102+
## 3. Generate the client
79103

80104
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).
81105

82-
## 4. Implementing the Common Test Suite
106+
## 4. Adding tests with the Common Test Suite
83107

84108
Clients needs to be tested, you can read more in the [Common Test Suite](/docs/contributing/testing/common-test-suite) guide.

0 commit comments

Comments
 (0)