Skip to content

Commit d423821

Browse files
authored
docs: rework the new client section and small guide on pre-releases (#4800)
1 parent a292828 commit d423821

File tree

11 files changed

+230
-205
lines changed

11 files changed

+230
-205
lines changed

generators/src/main/java/com/algolia/codegen/utils/Helpers.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,20 @@ public static void removeHelpers(OperationsMap operations) {
175175
/**
176176
* Get the current version of the given client from the
177177
* `clients/algoliasearch-client-javascript/packages/${client}/package.json` file, defaults to
178-
* 0.0.1 if not found
178+
* 0.0.1-alpha.0 if not found
179179
*/
180180
public static String getPackageJsonVersion(String client) throws ConfigException {
181181
try {
182182
JsonNode packageJson = Helpers.readJsonFile("clients/algoliasearch-client-javascript/packages/" + client + "/package.json");
183183
String value = packageJson.get("version").asText();
184184

185185
if (value.isEmpty()) {
186-
return "0.0.1";
186+
return "0.0.1-alpha.0";
187187
}
188188

189189
return value;
190190
} catch (ConfigException e) {
191-
return "0.0.1";
191+
return "0.0.1-alpha.0";
192192
}
193193
}
194194

website/docs/docs.md renamed to website/docs/add-a-new-api/api-documentation-guidelines.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: API documentation
2+
title: API documentation guidelines
33
description: Guidelines for writing API documentation for Algolia's APIs.
44
---
55

@@ -14,7 +14,7 @@ For more general documentation guidelines,
1414
see the [Google developer documentation style guide](https://developers.google.com/style).
1515

1616
For information on how to structure spec files to support a new API client,
17-
see [Add a new API client](./add-new-api-client.md).
17+
see [Add a new API client](/docs/add-a-new-language).
1818

1919
## Prefer plain text
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Generate your client
3+
---
4+
5+
:::info
6+
7+
Make sure to first read the [setup the repository tooling section](/docs/setup-repository) first.
8+
9+
This section is only about **adding to the existing API clients**, to support a new programming language, see [Support a new language](/docs/add-a-new-language).
10+
11+
:::
12+
13+
## Configuration file
14+
15+
> Most of the configuration is determined by the api-clients-automation CLI (`scripts/`).
16+
17+
The file [`config/clients.config.json`](https://github.com/algolia/api-clients-automation/blob/main/config/clients.config.json) contains information that's common to all clients generated for each language, you can [find its JSON schema here](https://github.com/algolia/api-clients-automation/blob/main/config/clients.schema.json).
18+
19+
## CLI Commands
20+
21+
Use the CLI to generate your client:
22+
23+
- [Commands for working with clients](/docs/CLI/generate-commands)
24+
25+
## Generate a pre-release client
26+
27+
:::info
28+
29+
Only the JavaScript client releases standalone packages along with the main `algoliasearch` package, so it's the only possible "generated" solution for pre-releases (alpha or beta).
30+
31+
:::
32+
33+
1. [Update the configuration file](https://github.com/algolia/api-clients-automation/blob/main/config/clients.config.json#L131)
34+
35+
The `clients` field define which specification to generate and their output location. In order to create a pre-release for your API, it needs to be standalone only (non bundled with `algoliasearch`).
36+
37+
```json
38+
{
39+
"name": "awesomeapi", // this must match the name of the specification
40+
"output": "clients/algoliasearch-client-javascript/packages/awesomeapi", // make sure to keep everything in `clients/algoliasearch-client-javascript/packages/`
41+
"isStandaloneClient": true // this tells the generator not to put it in the `algoliasearch` bundle
42+
},
43+
```
44+
45+
2. Generate your client
46+
47+
With just the above changes, you can now run `yarn cli generate -h` which should output a complete list of the available APIs for Javascript, `awesomeapi` should be in it.
48+
49+
Running `yarn cli generate javascript awesomeapi` will generate the client and format it, and `yarn cli build clients javascript awesomeapi` will bundle it.
50+
51+
3. Test the client
52+
53+
At least one test per operation is required, you can read more about it in the [Common Test Suite section](/docs/testing/common-test-suite.md).
54+
55+
4. Release
56+
57+
We take care of it, open your pull request :)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
title: Write an OpenAPI specification
3+
---
4+
5+
:::info
6+
7+
Algolia's API specs follow the [OpenAPI specification, version 3.1](https://spec.openapis.org/oas/v3.1.0).
8+
9+
Starting from an existing specification **really eases the contribution process and is recommended** (e.g. [search](https://github.com/algolia/api-clients-automation/blob/main/specs/search/))
10+
11+
**Do not edit the files in [`specs/bundled`](https://github.com/algolia/api-clients-automation/blob/main/specs/bundled)** they are the generated from the manually written specifications, and only used to generate API clients.
12+
13+
:::
14+
15+
:::caution
16+
17+
A specification is used to generate the API client, its tests and code snippets, but is most importantly served by [the Algolia public documentation](https://www.algolia.com/doc/api-reference/rest-api/), please read our [API Documentation guidelines](./api-documentation-guidelines.md) to properly document your specification.
18+
19+
:::
20+
21+
# Structure your specification
22+
23+
Each API specification follows a consistent structure.
24+
25+
## `specs/common/`
26+
27+
This [common directory](https://github.com/algolia/api-clients-automation/blob/main/specs/common/) contains schemas and parameters that are common to multiple Algolia APIs, for example: search parameters or indexName definitions.
28+
29+
## `specs/<apiName>/`
30+
31+
Each API must be contained in its own directory, for example: [the Search API](https://github.com/algolia/api-clients-automation/blob/main/specs/search/).
32+
33+
### `specs/<apiName>/spec.yml`
34+
35+
This file is the main entrypoint of your specification and should describe your API, including the `servers`, `securitySchemes` and `paths` properties.
36+
37+
### `specs/<apiName>/common/`
38+
39+
This directory contains schemas and parameters that are common to **your API**.
40+
For schemas that are shared between multiple APIs please use the global [`specs/common`](#specscommon) directory.
41+
42+
### `specs/<apiName>/paths/`
43+
44+
This directory contains the descriptions of the **endpoints** of your API.
45+
The paths themselves are defined in the [`spec.yml`](#specsapinamespecyml) file.
46+
47+
#### `specs/<apiName>/paths/<operation>.yml`
48+
49+
Operations are endpoints combined with an HTTP method (`GET`, `POST`, etc.).
50+
Each operation must have a unique `operationID` property.
51+
Operations for the same endpoint may share the same file, for example, the `GET` and `DELETE` request for the same endpoint.
52+
53+
##### Filenames
54+
55+
Follow these conventions:
56+
57+
- If the file only contains one operation, use `<operationId>.yml` as filename.
58+
- If the file contains multiple operations, use a more generic name, for example [`rule.yml`](https://github.com/algolia/api-clients-automation/blob/main/specs/search/paths/rules/rule.yml) for the `GET`, `PUT`, and `DELETE` request for a rule.
59+
60+
##### Summaries and descriptions
61+
62+
Every operation must have a `summary` and `description` property (they will be used in the generated API clients, and the Algolia documentation).
63+
For information about documenting operations, see [Operation summaries](/docs/add-a-new-api/api-documentation-guidelines#operation-summaries) and [Operation descriptions](./api-documentation-guidelines.md#operation-descriptions).
64+
65+
##### Access Control Lists (ACL)
66+
67+
Each operation should include an `x-acl` property
68+
to document the ACL required to make the request.
69+
70+
The `x-acl` property is an array of strings, the allowed values are: `search`, `browse`, `addObject`, `deleteObject`, `listIndexes`, `deleteIndex`, `settings`, `editSettings`, `analytics`, `recommendation`, `usage`, `logs`, `setUnretrievableAttributes`, `admin`.
71+
For operations that require the admin API key, use `admin`
72+
73+
##### Complex objects
74+
75+
The following objects must not be inlined, but referenced with `$ref`:
76+
77+
- Nested arrays
78+
- Nested objects
79+
- `oneOf`
80+
- `allOf`
81+
- `enum`
82+
83+
This is required for accurate naming of the generated code objects.
84+
It also improves the readability of the specs.
85+
86+
##### Properties and parameters
87+
88+
- Create separate objects and reference them for [complex objects](#complex-objects).
89+
- The `format` parameter for strings isn't supported.
90+
- For **nullable properties**, use the following syntax:
91+
92+
```yaml
93+
nullableProp:
94+
default: null
95+
oneOf:
96+
- type: string
97+
description: Some value
98+
- type: 'null'
99+
description: The single quotes are required.
100+
```
101+
102+
For information about documenting properties and parameters, see [Properties and parameters](/docs/add-a-new-api/api-documentation-guidelines#properties-and-parameter-descriptions).
103+
104+
## CLI Commands
105+
106+
Use the CLI to generate build your specs:
107+
108+
- [Commands for working with specs](/docs/CLI/build-commands)
109+
110+
## Troubleshooting
111+
112+
### Explicit names for request bodies
113+
114+
> [Detailed issue](https://github.com/algolia/api-clients-automation/issues/891)
115+
116+
In some cases, the generated name for the `requestBody` property might be wrong.
117+
This can happen in these cases:
118+
119+
- The type is too complex or too broad to be correctly generated,
120+
for example, [an object with `additionalProperties`](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths/objects/partialUpdate.yml#L24-L33).
121+
122+
- The type is an alias of its model,
123+
for example, [a list of `model`](https://github.com/algolia/api-clients-automation/tree/main/specs/search/paths/rules/saveRules.yml#L12-L20).
124+
125+
To provide a name for the request body, add the [`x-codegen-request-body-name`](https://openapi-generator.tech/docs/swagger-codegen-migration/#body-parameter-name) property to the root of the operation's spec file.
126+
127+
For an example, see [pull request #896](https://github.com/algolia/api-clients-automation/pull/896).
128+
129+
### Send additional options to the templates
130+
131+
To send additional information to the generators,
132+
you can add properties starting with `x-` to the root level of your spec.
133+
These are available in the templates as part of the `vendorExtensions` object.
134+
135+
For an example, see [`search.yml`](https://github.com/algolia/api-clients-automation/blob/main/specs/search/paths/search/search.yml#L5-L7)

website/docs/add-new-language.md renamed to website/docs/add-a-new-language.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Support a new language
2+
title: Add a new language
33
---
44

55
:::info
@@ -28,10 +28,6 @@ Example for the `JavaScript` client with the `typescript-node` template:
2828
apic exec java "yarn openapi-generator-cli author template -g typescript-node -o templates/javascript/"
2929
```
3030

31-
## Update the generator config
32-
33-
Please read the [`add a new client guide`](/docs/add-new-api-client) for information on how to structure your new client and setup the configuration files.
34-
3531
### Algolia requirements
3632

3733
:::caution
@@ -71,8 +67,6 @@ The retry strategy cannot be generated and needs to be implemented outside of th
7167

7268
Some Algolia clients (search and recommend) targets the default appId host (`${appId}-dsn.algolia.net`, `${appId}.algolia.net`, etc.), while clients like `personalization` have their own regional `host` (`eu` | `us` | `de`).
7369

74-
As the generator does not support reading `servers` in a spec file **yet**, hosts methods and variables are extracted with a custom script and create variables for you to use in the mustache templates, [read more here](/docs/add-new-api-client#2-configure-the-generator).
75-
7670
### User Agent
7771

7872
The header 'User-Agent' must respect a strict pattern of a base, client, plus additional user defined segments:

0 commit comments

Comments
 (0)