-
Notifications
You must be signed in to change notification settings - Fork 21
docs: generate doc from specs #92
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
Changes from all commits
ddb000e
79a0a26
3db8cd3
e299262
5c47648
90f6529
7fbd9aa
7c3702b
baddda7
67080d4
3f14df6
aa1a920
ee254f9
e6437a8
6f2b95e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[build] | ||
command="yarn website:build" | ||
publish="website/build" | ||
ignore="git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- website/ specs/bundled/" | ||
|
||
[build.environment] | ||
YARN_VERSION = "3.1.1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Website | ||
|
||
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. | ||
|
||
### Installation | ||
|
||
``` | ||
$ yarn | ||
``` | ||
|
||
### Local Development | ||
|
||
``` | ||
$ yarn start | ||
``` | ||
|
||
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. | ||
|
||
### Build | ||
|
||
``` | ||
$ yarn build | ||
``` | ||
|
||
This command generates static content into the `build` directory and can be served using any static contents hosting service. | ||
|
||
### Deployment | ||
|
||
Using SSH: | ||
|
||
``` | ||
$ USE_SSH=true yarn deploy | ||
``` | ||
|
||
Not using SSH: | ||
|
||
``` | ||
$ GIT_USER=<Your GitHub username> yarn deploy | ||
``` | ||
|
||
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// eslint-disable-next-line import/no-commonjs | ||
module.exports = { | ||
presets: [require.resolve('@docusaurus/core/lib/babel/preset')], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
# How to add a new client | ||
--- | ||
title: Add a new client | ||
--- | ||
|
||
# Add a new client | ||
|
||
Adding a client requires a few 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`. | ||
|
||
> See [README](../README.md) to [`setup the repository tooling`](../README.md#setup-repository-tooling) and [`setup dev environment`](../README.md#setup-dev-environment). | ||
> See the [Setup repository guide](/docs/setupRepository) to [`setup the repository tooling`](/docs/setupRepository#setup-the-repository-tooling). | ||
|
||
## 1. 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. | ||
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. | ||
|
||
### [common spec folder](../specs/common/) | ||
### [common spec folder](https://github.com/algolia/api-clients-automation/blob/main/specs/common/) | ||
|
||
Properties that are common to Algolia or used in multiple clients. | ||
|
||
### `<clientName>` spec folder | ||
|
||
> Example with the [search client spec](../specs/search/) | ||
> Example with the [search client spec](https://github.com/algolia/api-clients-automation/blob/main/specs/search/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no way to make docusaurus change that? because it will break branch navigation in github. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean a way to provide a relative path to the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep |
||
|
||
#### `spec.yml` file | ||
|
||
This file is the entry point of the client spec, it contains `servers`, `paths` and other specific imformations of the API. We recommend to copy an existing [`spec.yml` file](../specs/search/spec.yml) to get started. | ||
This file is the entry point of the client spec, it contains `servers`, `paths` and other specific imformations 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. | ||
|
||
#### `<clientName>`/common folder | ||
|
||
|
@@ -38,11 +42,11 @@ Path definition of the paths defined in the [spec file](#specyml-file) | |
|
||
## 2. Configuring the environment | ||
|
||
After setting up the dev environment from [README](../README.md) and [writing your spec files](#1-writing-specs), you need to update the configuration files to properly generate clients that are maintainable. | ||
After setting up the dev environment from [README](/docs/setupRepository) and [writing your spec files](#1-writing-specs), you need to update the 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 the generated clients with their available languages. | ||
[openapitools.json](https://github.com/algolia/api-clients-automation/blob/main/openapitools.json) hosts the configuration of all of the generated clients with their available languages. | ||
|
||
#### `generators` | ||
|
||
|
@@ -60,19 +64,19 @@ You can copy an existing object of a client and replace the `<clientName>` value | |
| 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). | | ||
| packageName | string | common | `AlgoliaSearch` | Name of the API package, used in [CTS](/docs/commonTestSuite). | | ||
| 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 | ||
|
||
The built clients are cached with the [Cache GitHub Action](../.github/actions/cache/action.yml) to avoid unnecessary CI tasks. | ||
The built clients are cached with the [Cache GitHub Action](https://github.com/algolia/api-clients-automation/blob/main/.github/actions/cache/action.yml) to avoid unnecessary CI tasks. | ||
|
||
> TODO: Automate this step | ||
|
||
You can copy [an existing client caching step](../.github/actions/cache/action.yml) or edit the following example: | ||
You can copy [an existing client caching step](https://github.com/algolia/api-clients-automation/blob/main/.github/actions/cache/action.yml) or edit the following example: | ||
|
||
```yaml | ||
- name: Restore built <LANGUAGE> <CLIENT_NAME> client | ||
|
@@ -85,12 +89,12 @@ You can copy [an existing client caching step](../.github/actions/cache/action.y | |
|
||
## 3. Generate new client | ||
|
||
> You can find more commands in the [README](../README.md#generate-all-clients). | ||
> You can find more commands in the [CLI > generation commands page](/docs/generationCommands) and [CLI > specs commands page](/docs/specsCommands). | ||
|
||
```bash | ||
yarn docker generate <languageName> <clientName> | ||
``` | ||
|
||
## 4. Implementing the Common Test Suite | ||
|
||
See [CTS.md](./CTS.md) for more informations. | ||
See [CTS.md](/docs/commonTestSuite) for more informations. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Generation commands | ||
--- | ||
|
||
# CLI generation commands | ||
|
||
## Usage | ||
|
||
```bash | ||
yarn docker generate <language | all> <client | all> | ||
``` | ||
|
||
### Available options | ||
|
||
| Option | Command | Description | | ||
| ----------- | :---------------- | :------------------------------------------------------------ | | ||
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools | | ||
| interactive | -i, --interactive | Open prompt to query parameters | | ||
|
||
## Generate all clients for all support languages | ||
|
||
```bash | ||
yarn docker generate | ||
``` | ||
|
||
### Generate specific client for specific language | ||
|
||
```bash | ||
yarn docker generate java sources | ||
``` | ||
|
||
## Build all clients for all support languages | ||
|
||
```bash | ||
yarn docker build clients | ||
``` | ||
|
||
### Build specific client for specific language | ||
|
||
```bash | ||
yarn docker build clients javascript recommend | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Getting started | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
<Tabs | ||
groupId="language" | ||
defaultValue="js" | ||
values={[ | ||
{ label: 'JavaScript', value: 'js', } | ||
] | ||
}> | ||
<TabItem value="js"> | ||
|
||
## Installation | ||
|
||
To get started, you first need to install `algoliasearch` (or any other available API client package) | ||
|
||
```bash | ||
yarn add @experimental-api-clients-automation/algoliasearch | ||
``` | ||
|
||
Or use a specific package to reduce bundle size: | ||
|
||
```bash | ||
yarn add @experimental-api-clients-automation/client-search | ||
``` | ||
|
||
You can find the full list of available packages [here](https://www.npmjs.com/org/experimental-api-clients-automation). | ||
|
||
### Without a package manager | ||
|
||
Add the JavaScript to your `<head>` | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@experimental-api-clients-automation/[email protected]/dist/algoliasearch.umd.browser.js"></script> | ||
``` | ||
|
||
## Using the client | ||
|
||
Then you need to import the correct package, depending on your choice: | ||
|
||
```js | ||
import { algoliasearch } from 'algoliasearch'; | ||
|
||
const client = algoliasearch(appId, apiKey); | ||
|
||
// And access analytics or personalization client | ||
const analyticsClient = client.initAnalytics(analyticsAppId, analyticsApiKey); | ||
const personalizationCilent = client.initPersonalization(personalizationAppId, personalizationApiKey, 'eu'); | ||
``` | ||
|
||
```js | ||
import { searchApi } from '@algolia/client-search'; | ||
|
||
const client = searchApi(appId, apiKey); | ||
``` | ||
|
||
It is possible to customize the client by passing optional parameters: | ||
|
||
```js | ||
const client = searchApi(appId, apiKey, { | ||
requester: customRequester(), | ||
hosts: [{ | ||
url: 'my.custom.host.net', | ||
accept: 'read', | ||
protocol: 'https', | ||
}] | ||
}) | ||
``` | ||
|
||
Once the client is setup, you can enjoy all of Algolia API ! | ||
|
||
```js | ||
const res = await client.search({ | ||
indexName: 'my-index', | ||
searchParams: { query: 'words to query' }, | ||
}); | ||
|
||
console.log('Search result', res.hits); | ||
``` | ||
|
||
|
||
Or with the `personalization` client | ||
|
||
```js | ||
const res = await personalizationCilent.getUserTokenProfile({ | ||
userToken: 'token', | ||
}); | ||
|
||
console.log('User scores', res.scores); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename website to something more specific like
documentation
ordocWebsite
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the usual name of the folder for open-source repository that hosts their website on the same repository, but we can go with
documentation
indeed