Skip to content

Commit ce99786

Browse files
authored
docs: add troubleshooting section to contributing guide (#897)
1 parent eec1a92 commit ce99786

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

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

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,84 @@
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+
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)
15+
3. [Generate the client](#3-generate-the-client)
16+
4. [Adding tests](#4-adding-tests-with-the-common-test-suite)
17+
1518
## 1. Writing specs
1619

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

1933
### `common` spec folder
2034

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

2337
### `<clientName>` spec folder
2438

2539
> Example with the [search client spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/)
2640
27-
#### `spec.yml` file
41+
#### **`spec.yml` file**
2842

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

31-
#### `<clientName>`/common folder
45+
#### **`<clientName>`/common folder**
3246

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

35-
#### `<clientName>`/paths folder
49+
#### **`<clientName>`/paths folder**
3650

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

39-
### Send additional options to the template
53+
### Troubleshooting
4054

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`**
4256

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

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

52-
## 2. Configuring the environment
74+
## 2. Configuring the generator
5375

5476
> The generator follows its own configuration file named `config/openapitools.json`
5577
56-
### Generation config
78+
### Configs
5779

5880
[`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.
5981

60-
#### `generators`
82+
#### Settings
6183

6284
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.
6385

@@ -75,10 +97,10 @@ Below are the options you need to **make sure to define for your client**, other
7597
| `apiFolder` | `clients.config.json` | All | The path to the `api` folder that will host the generated code. |
7698
| `customGenerator` | `clients.config.json` | All | The name of the generator used to generate code. |
7799

78-
## 3. Generate new client
100+
## 3. Generate the client
79101

80102
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).
81103

82-
## 4. Implementing the Common Test Suite
104+
## 4. Adding tests with the Common Test Suite
83105

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

website/docs/contributing/add-new-language.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: Support a new language
33
---
44

5-
# Support a new language
6-
75
:::info
86

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

0 commit comments

Comments
 (0)