Skip to content

Commit 6fbf899

Browse files
authored
chore: add json schema for clients config (#4657)
1 parent 5c28957 commit 6fbf899

File tree

6 files changed

+123
-13
lines changed

6 files changed

+123
-13
lines changed

config/clients.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "./clients.schema.json",
23
"csharp": {
34
"clients": [
45
"abtesting",

config/clients.schema.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"additionalProperties": {
5+
"type": "object",
6+
"properties": {
7+
"clients": {
8+
"oneOf": [
9+
{
10+
"type": "array",
11+
"items": {
12+
"type": "string",
13+
"enum": [
14+
"abtesting",
15+
"analytics",
16+
"composition",
17+
"ingestion",
18+
"insights",
19+
"monitoring",
20+
"personalization",
21+
"query-suggestions",
22+
"recommend",
23+
"search"
24+
]
25+
}
26+
},
27+
{
28+
"type": "array",
29+
"items": {
30+
"type": "object",
31+
"properties": {
32+
"name": {
33+
"type": "string",
34+
"enum": [
35+
"algoliasearch",
36+
"abtesting",
37+
"analytics",
38+
"composition",
39+
"composition-full",
40+
"ingestion",
41+
"insights",
42+
"monitoring",
43+
"personalization",
44+
"query-suggestions",
45+
"recommend",
46+
"search"
47+
]
48+
},
49+
"output": { "type": "string" }
50+
},
51+
"required": ["name", "output"],
52+
"additionalProperties": false
53+
}
54+
}
55+
]
56+
},
57+
"folder": { "type": "string", "description": "the output folder of your client, usually matching the github repository name, e.g. clients/algoliasearch-client-dart" },
58+
"gitRepoId": { "type": "string", "description": "the github repository name, without the organization or username that owns it, e.g. algoliasearch-client-php"},
59+
"packageVersion": { "type": "string", "description": "the version to publish the packages with, it must be semver compatible, e.g. 1.2.3" },
60+
"modelFolder": { "type": "string", "description": "the models folder, e.g. algoliasearch/models"},
61+
"apiFolder": { "type": "string", "description": "the api folder, e.g. lib/src"},
62+
"dockerImage": {
63+
"type": "string",
64+
"description": "whether your client requires a custom docker image with specific needs, most clients require 'apic_base'",
65+
"enum": [
66+
"apic_base",
67+
"apic_ruby",
68+
"apic_swift"
69+
]
70+
},
71+
"tests": {
72+
"type": "object",
73+
"properties": {
74+
"extension": { "type": "string", "description": "the test file extension, e.g. .test.ts" },
75+
"outputFolder": { "type": "string", "description": "the test output folder, e.g. src/generated" }
76+
},
77+
"required": ["extension", "outputFolder"],
78+
"additionalProperties": false
79+
},
80+
"snippets": {
81+
"type": "object",
82+
"properties": {
83+
"extension": { "type": "string", "description": "the snippet file extension, e.g. .cs" },
84+
"outputFolder": { "type": "string", "description": "the snippet output folder, e.g. src" }
85+
},
86+
"required": ["extension", "outputFolder"],
87+
"additionalProperties": false
88+
},
89+
"supportedVersions": {
90+
"type": "array",
91+
"description": "hints the CI on what matrix to generate for this client, this must be language specific versions, e.g. versions of node",
92+
"items": { "type": "string" }
93+
}
94+
},
95+
"required": ["clients", "folder", "gitRepoId", "packageVersion", "modelFolder", "apiFolder", "tests", "snippets"],
96+
"additionalProperties": false
97+
}
98+
}

scripts/common.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ export const ROOT_DIR = path.resolve(process.cwd(), '..');
3030

3131
// Build `GENERATORS` from the `clients.config.json` file
3232
export const GENERATORS = Object.entries(clientsConfig).reduce(
33-
(current, [language, { clients, folder, ...gen }]) => {
34-
for (const client of clients) {
35-
let output = folder;
33+
(current, [language, opts]) => {
34+
if (typeof opts === 'string') {
35+
return current;
36+
}
37+
38+
for (const client of opts.clients) {
39+
let output = opts.folder;
3640
let key = '';
3741
let clientName = '';
3842

@@ -47,7 +51,7 @@ export const GENERATORS = Object.entries(clientsConfig).reduce(
4751

4852
current[key] = {
4953
additionalProperties: {},
50-
...gen,
54+
...opts,
5155
output,
5256
client: clientName,
5357
language: language as Language,

scripts/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export function getClientsConfigField(
88
pathToField: string[] | string,
99
required: boolean = true,
1010
): any {
11+
if (typeof clientsConfig[language] !== 'object') {
12+
throw new Error(`${language} doesn't exist in clients.config.json`);
13+
}
14+
1115
const config: LanguageConfig = clientsConfig[language];
1216
const path = Array.isArray(pathToField) ? pathToField : [pathToField];
1317

@@ -42,11 +46,11 @@ export function getTestOutputFolder(language: Language): string {
4246
}
4347

4448
export function getDockerImage(language?: Language): string | undefined {
45-
if (CI || !language || !('dockerImage' in clientsConfig[language])) {
49+
if (CI || !language) {
4650
return undefined;
4751
}
4852

49-
return getClientsConfigField(language, 'dockerImage');
53+
return getClientsConfigField(language, 'dockerImage', false);
5054
}
5155

5256
/**
@@ -57,7 +61,7 @@ export function getPackageVersionDefault(language: Language): string {
5761
}
5862

5963
export function getGitHubUrl(language: Language, options?: { token: string }): string {
60-
const { gitRepoId } = clientsConfig[language];
64+
const gitRepoId = getClientsConfigField(language, ['gitRepoId']);
6165

6266
// GitHub Action provides a default token for authentication
6367
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication

scripts/husky/pre-commit.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ async function run(command) {
1818

1919
export function getPatterns() {
2020
const entries = patterns;
21-
for (const [language, { tests }] of Object.entries(clientConfig)) {
22-
entries.unshift(`tests/output/${language}/${tests.outputFolder}/client/**`);
23-
entries.unshift(`tests/output/${language}/${tests.outputFolder}/requests/**`);
24-
entries.unshift(`tests/output/${language}/${tests.outputFolder}/e2e/**`);
25-
entries.unshift(`tests/output/${language}/${tests.outputFolder}/benchmark/**`);
21+
for (const [language, opts] of Object.entries(clientConfig)) {
22+
if (typeof opts !== 'object') {
23+
continue;
24+
}
25+
entries.unshift(`tests/output/${language}/${opts.tests.outputFolder}/client/**`);
26+
entries.unshift(`tests/output/${language}/${opts.tests.outputFolder}/requests/**`);
27+
entries.unshift(`tests/output/${language}/${opts.tests.outputFolder}/e2e/**`);
28+
entries.unshift(`tests/output/${language}/${opts.tests.outputFolder}/benchmark/**`);
2629
}
2730
return entries;
2831
}

scripts/release/updateAPIVersions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { Changelog, Versions } from './types.ts';
1313
async function updateConfigFiles(versionsToRelease: Versions): Promise<void> {
1414
// update the other versions in clients.config.json
1515
for (const lang of Object.keys(versionsToRelease) as Language[]) {
16-
if (versionsToRelease[lang]?.next) {
16+
if (typeof clientsConfig[lang] == 'object' && versionsToRelease[lang]?.next) {
1717
clientsConfig[lang].packageVersion = versionsToRelease[lang].next;
1818
}
1919
}

0 commit comments

Comments
 (0)