-
Notifications
You must be signed in to change notification settings - Fork 21
docs: add contribution guides #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
877bb21
doc: add contribution guides
shortcuts f7ec1a1
allow `docs` PR titles
shortcuts 5489c31
update paths
shortcuts 087a1db
Merge branch 'main' into doc/APIC-210/contribution-guides
shortcuts 091230b
Merge branch 'main' into doc/APIC-210/contribution-guides
shortcuts 2cdac95
apply review
shortcuts a5bb1fc
Merge branch 'main' into doc/APIC-210/contribution-guides
shortcuts 5942c80
apply changes from suggestion
shortcuts 12d08ab
fix format
shortcuts 505a54d
add guidelines and CTS step
shortcuts 7a50f79
Merge branch 'main' into doc/APIC-210/contribution-guides
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ jobs: | |
- name: Pull Request title rules | ||
uses: deepakputhraya/[email protected] | ||
with: | ||
regex: '^(?:(feat)|(fix)|(docs)|(style)|(refactor)|(perf)|(test)|(build)|(ci)|(chore)|(revert))\((?:(javascript)|(php)|(java)|(cts)|(spec)|(script)|(ci))\): .+' | ||
regex: '^(docs)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:javascript|php|java|cts|spec|script|ci)\)): .+' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# How to add a new client | ||
|
||
> Adding a client requires a few manual steps in order to setup our tooling, generation scripts and properly generate the code. We recommend getting inspirations from existing clients such as `javascript-recommend`. | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
> See [README](../README.md) for the repository commands | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Configuring the environment | ||
|
||
After following the repository [README](../README.md), you need to update our configuration files to properly generate clients that are maintainable. | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Generation config | ||
|
||
> [openapitools.json](../openapitools.json) hosts the configuration of all of our generated clients with their available languages. | ||
|
||
#### `generators` | ||
|
||
> Generators are referenced by key with the following pattern `<languageName>-<clientName>`. | ||
|
||
> TODO: Automate this step. | ||
|
||
You can copy an existing object of a client and replace the `<clientName>` value with the one you'd like to generate. | ||
|
||
| Option | Type | Language | Example | Definition | | ||
| ------------------ | :-----: | :--------: | :-----------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------: | | ||
| output | string | Common | `path/to/client/client-sources` | The output path of your client. | | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| glob | string | Common | `path/to/spec/sources.yml` | The path of your bundled spec file. | | ||
| gitRepoId | string | Common | `algoliasearch-client-java-2` | The name of the repository under the Algolia org. | | ||
| apiName | string | JavaScript | `search` | The lowercase name of the exported API. | | ||
| capitalizedApiName | string | JavaScript | `Search` | The capitalized name of the exported API. | | ||
| packageVersion | string | JavaScript | `1.2.3` | The version you'd like to publish the first iteration of the generated client. It will be automatically incremented. | | ||
| packageName | string | common | `AlgoliaSearch` | Name of the API package, used in [CTS](./CTS.md). | | ||
| hasRegionalHost | boolean | common | `false` | Automatically guessed from `servers` in spec. `undefined` implies that hosts used will required the `appId`, regional hosts are used otherwise. | | ||
| isDeHost | boolean | common | `false` | Automatically guessed from `servers` in spec. `undefined` implies that `eu` is the regional host, `de` otherwise. | | ||
| host | string | common | `crawler` | Automatically guessed from `servers` in spec. | | ||
| topLevelDomain | string | common | `io` | Automatically guessed from `servers` in spec. | | ||
|
||
### GitHub actions | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
> We cache built clients with the [Cache GitHub Action](../.github/actions/cache/action.yml) to avoid useless CI tasks. | ||
|
||
> TODO: Automate this step | ||
|
||
You can copy [an existing client caching step](../.github/actions/cache/action.yml) or edit the following example: | ||
|
||
```yaml | ||
- name: Restore built <LANGUAGE> <CLIENT_NAME> client | ||
bodinsamuel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if: ${{ inputs.job == 'cts' }} | ||
uses: actions/cache@v2 | ||
with: | ||
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/<LANGUAGE_FOLDER>/<CLIENT_NAME>/<CLIENT_BUILD_PATH> | ||
key: ${{ runner.os }}-${{ env.CACHE_VERSION }}-<LANGUAGE>-<CLIENT_NAME>-${{ hashFiles('clients/<LANGUAGE_FOLDER>/<CLIENT_NAME>/**') }}-${{ hashFiles('specs/bundled/<CLIENT_SPEC>.yml') }} | ||
``` | ||
|
||
## Writing specs | ||
|
||
> We recommend to have a look at [existing spec files](../specs/). | ||
|
||
> The `bundled` folder is automatically generated, manual changes shouldn't be done in these files. | ||
|
||
### [common spec folder](../specs/common/) | ||
|
||
Properties that are common to Algolia or used in multiple clients. | ||
|
||
### [clientName spec folder](../specs/search) | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### [spec file](../specs/search/spec.yml) | ||
|
||
> We recommend to copy an of existing [spec file](../specs/search/spec.yml) and edit the `paths` and `servers | ||
|
||
This file is the entry point of the spec, it contains `servers` and `paths` of your API spec. | ||
|
||
#### [spec common folder](../specs/search/common) | ||
|
||
Properties that are common to your client. | ||
|
||
#### [paths folder](../specs/search/paths) | ||
|
||
Path definition of the paths defined in your [spec file](../specs/search/spec.yml) | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# How to add support of a new language | ||
|
||
> We use [openapi-generator](https://openapi-generator.tech/) to generate API clients. | ||
|
||
> See [README](../README.md) for the repository commands | ||
|
||
## Find a template to start with | ||
|
||
> Provided templates should be a good starting point to generate a client but make sure to implement the [Algolia requirements](#algolia-requirements) to make it work properly. | ||
|
||
You can pick a default template on the [openapi-generator's "generators" page](https://openapi-generator.tech/docs/generators) | ||
|
||
> [Install openapi-generator](https://openapi-generator.tech/docs/installation/) | ||
|
||
### Extract the template locally | ||
|
||
```bash | ||
openapi-generator author template -g <YOUR_TEMPLATE_NAME> -o templates/<YOUR_API_CLIENT_NAME> | ||
``` | ||
|
||
Example for the JavaScript client with the `typescript-node` template: | ||
|
||
```bash | ||
openapi-generator author template -g typescript-node -o templates/javascript/ | ||
``` | ||
|
||
## Update the generator config | ||
|
||
Add each client in the file [`openapitools.json`](../openapitools.json), following the others client structure. | ||
|
||
> See [How to add a new client](./addNewClient.md) for informations regarding this file | ||
|
||
### Algolia requirements | ||
|
||
API clients require custom Algolia logic in order to work with our engine. | ||
|
||
### Strip code | ||
|
||
The generator includes a lot of useless features that we don't use: | ||
|
||
- Multiple authentication methods: We only use `appId`/`apiKey` authentication methods in headers. | ||
- Built-in transporters: The engine requires a [retry strategy](#retry-strategy) and a lot of other features, you need to implement it. | ||
- File support, payload format etc.: We only need to support JSON to communicate with the engine. | ||
|
||
**DX is key, make sure to provide a linter and formatting tools, with consistent method usage based on the language.** | ||
|
||
### Init method | ||
|
||
By default, OpenAPI will put the `AppId` and `ApiKey` in every method parameters, but our clients to be initialized with those values and put them in the header of every requests, with the right hosts. | ||
|
||
The constructor of the client can be edited (from the `.mustache` files) to accept and store those values. | ||
|
||
- [First implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/pull/7) | ||
- [Current implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/blob/main/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts#L110-L125) | ||
|
||
### Retry strategy | ||
|
||
The retry strategy cannot be generated and needs to be implemented outside of the generated client folder. You can achieve this by creating a `utils` (or any naming that you find relevant) folder and add your transporter and retry strategy logic to it. | ||
|
||
- [First implementation on the JavaScript client](https://github.com/algolia/api-clients-automation/pull/9) | ||
- [Current implementation on the PHP client](https://github.com/algolia/api-clients-automation/tree/main/clients/algoliasearch-client-php/lib/RetryStrategy) | ||
|
||
### Different client hosts | ||
|
||
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`). | ||
|
||
We guess those hosts methods and variables by reading the `servers` in your spec file and create variables for you to use in your templates, [read more here](./addNewClient.md). | ||
|
||
### Requesters | ||
|
||
> TODO: informations | ||
|
||
### Logger | ||
|
||
> TODO: informations | ||
|
||
### **DX** | ||
|
||
We require our API clients to have an up-to-date usage with their ecosystem, make sure to provide correct tooling to lint and format your generate code. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Playground | ||
|
||
> All of the existing clients should have an active playground for you to test generated clients, if it's not the case, consider contributing or letting us know! | ||
|
||
## Usage | ||
|
||
```bash | ||
yarn docker playground <language> <client> | ||
``` | ||
|
||
### JavaScript | ||
|
||
```bash | ||
yarn docker playground javascript search | ||
``` | ||
|
||
### Java | ||
|
||
```bash | ||
yarn docker playground java search | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,4 +395,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ fs.writeFileSync( | |
// update changelogs | ||
new Set([...Object.keys(versionsToRelease), ...langsToUpdateRepo]).forEach( | ||
(lang) => { | ||
const filePath = path.resolve(ROOT_DIR, `doc/changelogs/${lang}.md`); | ||
const filePath = path.resolve(ROOT_DIR, `docs/changelogs/${lang}.md`); | ||
const header = versionsToRelease[lang!] | ||
? `## ${versionsToRelease[lang!].next}` | ||
: `## ${new Date().toISOString().split('T')[0]}`; | ||
|
@@ -112,7 +112,7 @@ new Set([...Object.keys(versionsToRelease), ...langsToUpdateRepo]).forEach( | |
run('git config user.name "api-clients-bot"'); | ||
run('git config user.email "[email protected]"'); | ||
run('git add openapitools.json'); | ||
run('git add doc/changelogs/*'); | ||
run('git add docs/changelogs/*'); | ||
execa.sync('git', ['commit', '-m', TEXT.commitMessage]); | ||
run(`git push origin ${MAIN_BRANCH}`); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.