Skip to content

Commit 73692c8

Browse files
committed
lots of thing
1 parent 7eb9fcf commit 73692c8

File tree

111 files changed

+740
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+740
-699
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"build:specs": "./scripts/builds/specs.sh ${0:-all} ${1:-yaml}",
1212
"build": "yarn build:specs && yarn build:clients",
1313
"clean": "rm -rf **/dist **/build **/node_modules",
14-
"cts:generate": "yarn workspace tests start",
14+
"cts:generate": "yarn workspace tests build && ./scripts/multiplexer.sh yarn workspace tests generate ${0:-all} ${1:-all} && yarn workspace tests lint:fix",
1515
"cts:test": "yarn workspace tests test",
1616
"docker:build": "./scripts/docker/build.sh",
1717
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
@@ -36,13 +36,13 @@
3636
"eslint-plugin-algolia": "2.0.0",
3737
"eslint-plugin-eslint-comments": "3.2.0",
3838
"eslint-plugin-import": "2.25.4",
39-
"eslint-plugin-jsdoc": "37.5.1",
39+
"eslint-plugin-jsdoc": "37.6.1",
4040
"eslint-plugin-prettier": "4.0.0",
4141
"eslint-plugin-unused-imports": "2.0.0",
4242
"eslint-plugin-yml": "0.12.0",
4343
"json": "11.0.0",
4444
"prettier": "2.5.1",
45-
"prettier-plugin-java": "1.6.0",
45+
"prettier-plugin-java": "1.6.1",
4646
"swagger-cli": "4.0.4",
4747
"typescript": "4.5.4"
4848
},

playground/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@algolia/client-query-suggestions": "5.0.0",
2424
"@algolia/client-search": "5.0.0",
2525
"@algolia/recommend": "5.0.0",
26-
"dotenv": "10.0.0",
26+
"dotenv": "11.0.0",
2727
"typescript": "4.5.4"
2828
},
2929
"engines": {

scripts/multiplexer.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
1515
# Move to the root (easier to locate other scripts)
1616
cd ${DIR}/..
1717

18-
CMD=$1
19-
LANGUAGE=$2
20-
CLIENT=$3
18+
CMD=${@:1:$#-2}
19+
LANGUAGE=${@: -2:1}
20+
CLIENT=${@: -1}
2121

2222
if [[ $CMD == "./scripts/playground.sh" ]] && ([[ $LANGUAGE == "all" ]] || [[ $CLIENT == "all" ]]); then
2323
echo "You cannot use 'all' when running the playground, please specify the language and client"

tests/CTS/templates/java/requests.mustache

Whitespace-only changes.

tests/generateCTS.ts

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import type { OpenAPIV3 } from 'openapi-types';
88

99
import openapitools from '../openapitools.json';
1010

11-
const availableLanguages = ['javascript'] as const;
12-
type Language = typeof availableLanguages[number];
1311
type ParametersWithDataType = {
1412
key: string;
1513
value: string;
@@ -40,22 +38,22 @@ type CTSBlock = {
4038
tests: Tests[];
4139
};
4240

43-
// Array of test per client
44-
type CTS = Record<string, CTSBlock[]>;
45-
46-
const extensionForLanguage: Record<Language, string> = {
47-
javascript: '.test.ts',
41+
type CTS = {
42+
requests: CTSBlock[];
4843
};
4944

50-
const cts: CTS = {};
45+
const extensionForLanguage: Record<string, string> = {
46+
javascript: 'test.ts',
47+
java: 'java',
48+
};
5149

5250
// For each generator, we map the packageName with the language and client
53-
const packageNames: Record<string, Record<Language, string>> = Object.entries(
51+
const packageNames: Record<string, Record<string, string>> = Object.entries(
5452
openapitools['generator-cli'].generators
5553
).reduce((prev, [clientName, clientConfig]) => {
5654
const obj = prev;
5755
const parts = clientName.split('-');
58-
const lang = parts[0] as Language;
56+
const lang = parts[0];
5957
const client = parts.slice(1).join('-');
6058

6159
if (!(lang in prev)) {
@@ -67,8 +65,9 @@ const packageNames: Record<string, Record<Language, string>> = Object.entries(
6765
return obj;
6866
}, {} as Record<string, Record<string, string>>);
6967

70-
async function createOutputDir(language: Language): Promise<void> {
68+
async function createOutputDir(language: string): Promise<void> {
7169
await fsp.mkdir(`output/${language}`, { recursive: true });
70+
await fsp.mkdir(`output/${language}/tests`, { recursive: true });
7271
}
7372

7473
async function* walk(
@@ -103,7 +102,7 @@ function removeObjectName(obj: Record<string, any>): void {
103102
}
104103
}
105104

106-
async function loadCTSForClient(client: string): Promise<CTSBlock[]> {
105+
async function loadRequestsCTS(client: string): Promise<CTSBlock[]> {
107106
// load the list of operations from the spec
108107
const spec = await SwaggerParser.validate(`../specs/${client}/spec.yml`);
109108
if (!spec.paths) {
@@ -116,7 +115,7 @@ async function loadCTSForClient(client: string): Promise<CTSBlock[]> {
116115

117116
const ctsClient: CTSBlock[] = [];
118117

119-
for await (const file of walk(`./CTS/clients/${client}`)) {
118+
for await (const file of walk(`./CTS/clients/${client}/requests`)) {
120119
if (!file.name.endsWith('json')) {
121120
continue;
122121
}
@@ -181,10 +180,6 @@ async function loadCTSForClient(client: string): Promise<CTSBlock[]> {
181180
}
182181
);
183182

184-
if (fileName === 'getDictionarySettings') {
185-
console.log(test.parameters, test.parametersWithDataType);
186-
}
187-
188183
test.parameters = JSON.stringify(test.parameters);
189184
test.hasParameters = true;
190185
}
@@ -200,45 +195,56 @@ async function loadCTSForClient(client: string): Promise<CTSBlock[]> {
200195
);
201196
}
202197

203-
async function loadCTS(): Promise<void> {
204-
for await (const { name: client } of await fsp.opendir('./CTS/clients/')) {
205-
cts[client] = await loadCTSForClient(client);
206-
}
198+
async function loadCTS(client: string): Promise<CTS> {
199+
return {
200+
requests: await loadRequestsCTS(client),
201+
};
207202
}
208203

209-
async function loadTemplate(language: Language): Promise<string> {
210-
return (await fsp.readFile(`CTS/templates/${language}.mustache`)).toString();
204+
async function loadRequestsTemplate(language: string): Promise<string> {
205+
return (
206+
await fsp.readFile(`CTS/templates/${language}/requests.mustache`)
207+
).toString();
208+
}
209+
210+
async function generateRequestsTests(
211+
cts: CTSBlock[],
212+
template: string,
213+
language: string,
214+
client: string
215+
): Promise<void> {
216+
if (cts.length === 0) {
217+
return;
218+
}
219+
220+
const code = Mustache.render(template, {
221+
import: packageNames[language][client],
222+
client: createClientName(client),
223+
blocks: cts,
224+
hasRegionalHost: [
225+
'personalization',
226+
'analytics',
227+
'abtesting',
228+
'query-suggestions',
229+
].includes(client),
230+
});
231+
await fsp.writeFile(
232+
`output/${language}/tests/${client}Requests.${extensionForLanguage[language]}`,
233+
code
234+
);
211235
}
212236

213-
async function generateCode(language: Language): Promise<void> {
214-
const template = await loadTemplate(language);
237+
async function generateTests(language: string, client: string): Promise<void> {
238+
const template = await loadRequestsTemplate(language);
239+
const cts = await loadCTS(client);
240+
215241
await createOutputDir(language);
216-
for (const client in cts) {
217-
if (cts[client].length === 0) {
218-
continue;
219-
}
220242

221-
const code = Mustache.render(template, {
222-
import: packageNames[language][client],
223-
client: createClientName(client),
224-
blocks: cts[client],
225-
hasRegionalHost: [
226-
'personalization',
227-
'analytics',
228-
'abtesting',
229-
'query-suggestions',
230-
].includes(client),
231-
});
232-
await fsp.writeFile(
233-
`output/${language}/${client}${extensionForLanguage[language]}`,
234-
code
235-
);
236-
}
243+
await generateRequestsTests(cts.requests, template, language, client);
237244
}
238245

239246
function printUsage(): void {
240-
console.log(`usage: generateCTS all | language1 language2...`);
241-
console.log(`\tavailable languages: ${availableLanguages.join(',')}`);
247+
console.log(`usage: generateCTS language client`);
242248
// eslint-disable-next-line no-process-exit
243249
process.exit(1);
244250
}
@@ -249,26 +255,24 @@ async function parseCLI(args: string[]): Promise<void> {
249255
printUsage();
250256
}
251257

252-
let toGenerate: Language[];
253-
if (args.length === 3 && args[2] === 'all') {
254-
toGenerate = [...availableLanguages];
255-
} else {
256-
const languages = args[2].split(' ') as Language[];
257-
const unknownLanguages = languages.filter(
258-
(lang) => !availableLanguages.includes(lang)
259-
);
260-
if (unknownLanguages.length > 0) {
261-
console.log('unkown language(s): ', unknownLanguages.join(', '));
262-
printUsage();
263-
}
264-
toGenerate = languages;
258+
const lang = args[2];
259+
const client = args[3];
260+
261+
if (!(lang in packageNames)) {
262+
console.log('Unknown language', lang);
263+
// eslint-disable-next-line no-process-exit
264+
process.exit(1);
265+
}
266+
if (!(client in packageNames[lang])) {
267+
console.log('Unknown client', client);
268+
// eslint-disable-next-line no-process-exit
269+
process.exit(1);
265270
}
266271

272+
console.log(`Generating CTS for ${lang} and ${client}`);
273+
267274
try {
268-
await loadCTS();
269-
for (const lang of toGenerate) {
270-
generateCode(lang);
271-
}
275+
await generateTests(args[2], args[3]);
272276
} catch (e) {
273277
if (e instanceof Error) {
274278
console.error(e);

tests/output/java/tests/searchRequests.java

Whitespace-only changes.
File renamed without changes.

tests/output/javascript/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "javascript-tests",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"lint:fix": "yarn eslint --ext=ts tests --fix",
6+
"test": "jest"
7+
},
8+
"dependencies": {
9+
"@algolia/client-abtesting": "5.0.0",
10+
"@algolia/client-analytics": "5.0.0",
11+
"@algolia/client-insights": "5.0.0",
12+
"@algolia/client-personalization": "5.0.0",
13+
"@algolia/client-query-suggestions": "5.0.0",
14+
"@algolia/client-search": "5.0.0",
15+
"@algolia/recommend": "5.0.0"
16+
},
17+
"devDependencies": {
18+
"@apidevtools/swagger-parser": "10.0.3",
19+
"@types/jest": "27.0.3",
20+
"@types/mustache": "4.1.2",
21+
"@types/node": "16.11.11",
22+
"dotenv": "11.0.0",
23+
"eslint": "8.6.0",
24+
"jest": "27.4.7",
25+
"mustache": "4.2.0",
26+
"openapi-types": "10.0.0",
27+
"prettier": "2.5.1",
28+
"ts-jest": "27.1.2",
29+
"typescript": "4.5.4"
30+
}
31+
}

tests/output/javascript/tsconfig.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"noImplicitAny": false,
5+
"suppressImplicitAnyIndexErrors": true,
6+
"target": "ES6",
7+
"allowSyntheticDefaultImports": true,
8+
"esModuleInterop": true,
9+
"strict": true,
10+
"moduleResolution": "node",
11+
"removeComments": true,
12+
"sourceMap": true,
13+
"noLib": false,
14+
"declaration": true,
15+
"lib": [
16+
"dom",
17+
"es6",
18+
"es5",
19+
"dom.iterable",
20+
"scripthost"
21+
],
22+
"outDir": "dist",
23+
"typeRoots": [
24+
"../node_modules/@types"
25+
],
26+
"types": [
27+
"node",
28+
"jest"
29+
],
30+
"resolveJsonModule": true
31+
},
32+
"include": [
33+
"tests"
34+
]
35+
}

tests/package.json

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
{
22
"name": "tests",
33
"version": "1.0.0",
4+
"workspaces": [
5+
"output/javascript"
6+
],
47
"scripts": {
58
"build": "tsc",
6-
"lint:fix": "yarn eslint --ext=ts output --fix",
7-
"test": "jest",
8-
"start": "yarn build && node dist/tests/generateCTS.js ${0:-all} && yarn lint:fix"
9-
},
10-
"dependencies": {
11-
"@algolia/client-abtesting": "5.0.0",
12-
"@algolia/client-analytics": "5.0.0",
13-
"@algolia/client-insights": "5.0.0",
14-
"@algolia/client-personalization": "5.0.0",
15-
"@algolia/client-query-suggestions": "5.0.0",
16-
"@algolia/client-search": "5.0.0",
17-
"@algolia/recommend": "5.0.0"
9+
"lint:fix": "yarn workspace javascript-tests lint:fix",
10+
"generate": "node dist/tests/generateCTS.js ${0:-javascript} ${1:-search}",
11+
"start": "yarn build && yarn generate ${0:-javascript} ${1:-search} && yarn lint:fix"
1812
},
1913
"devDependencies": {
2014
"@apidevtools/swagger-parser": "10.0.3",
21-
"@types/jest": "27.0.3",
2215
"@types/mustache": "4.1.2",
2316
"@types/node": "16.11.11",
24-
"dotenv": "10.0.0",
2517
"eslint": "8.6.0",
26-
"jest": "27.4.5",
2718
"mustache": "4.2.0",
2819
"openapi-types": "10.0.0",
29-
"prettier": "2.5.1",
30-
"ts-jest": "27.1.2",
3120
"typescript": "4.5.4"
3221
}
3322
}

0 commit comments

Comments
 (0)