Skip to content

Commit aa5c34c

Browse files
authored
feat(clients): add generic parameter (#4922)
1 parent 0eac7ed commit aa5c34c

File tree

18 files changed

+97
-46
lines changed

18 files changed

+97
-46
lines changed

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ private void transferPrimitiveData(IJsonSchemaValidationProperties spec, Map<Str
654654
case "Boolean":
655655
output.put("isBoolean", true);
656656
break;
657+
case "oas_any_type_not_mapped":
658+
output.put("isAnyType", true);
659+
output.put("isFreeFormObject", true);
660+
break;
657661
default:
658662
throw new CTSException("Unknown primitive: " + getTypeName(spec));
659663
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ private static void setHasChildGeneric(IJsonSchemaValidationProperties property)
3939
setVendorExtension(property, "x-has-child-generic", true);
4040
}
4141

42+
private static void setHasGenericParameter(CodegenOperation ope) {
43+
ope.vendorExtensions.put("x-has-generic-parameter", true);
44+
}
45+
4246
/**
4347
* @return true if the vendor extensions of the property contains either x-propagated-generic or
4448
* x-has-child-generic
@@ -224,9 +228,17 @@ public static void propagateGenericsToOperations(OperationsMap operations, List<
224228
public static void propagateGenericsToOperations(String language, String client, OperationsMap operations, List<ModelMap> allModels) {
225229
Map<String, CodegenModel> models = convertToMap(language, client, allModels);
226230
for (CodegenOperation ope : operations.getOperations().getOperation()) {
231+
for (CodegenParameter param : ope.requiredParams) {
232+
if (param.vendorExtensions.containsKey("x-is-generic")) {
233+
setHasGenericParameter(ope);
234+
break;
235+
}
236+
}
237+
227238
if (ope.returnType == null) {
228239
continue;
229240
}
241+
230242
CodegenModel returnType = models.get(ope.returnType);
231243
if (returnType != null && hasGeneric(returnType)) {
232244
ope.vendorExtensions.put("x-is-generic", true);
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
1+
import js from '@eslint/js';
2+
import reactHooks from 'eslint-plugin-react-hooks';
3+
import reactRefresh from 'eslint-plugin-react-refresh';
4+
import globals from 'globals';
5+
import tseslint from 'typescript-eslint';
66

77
export default tseslint.config(
88
{ ignores: ['dist'] },
@@ -19,10 +19,7 @@ export default tseslint.config(
1919
},
2020
rules: {
2121
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
24-
{ allowConstantExport: true },
25-
],
22+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
2623
},
2724
},
28-
)
25+
);

playground/javascript/browser/src/App.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ h1 {
55
}
66

77
body {
8-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
9-
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
8+
font-family:
9+
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
10+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
1011
}
1112

1213
em {

playground/javascript/browser/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { liteClient as algoliasearch } from 'algoliasearch/lite';
2-
import { Hit } from 'instantsearch.js';
2+
import type { Hit } from 'instantsearch.js';
33
import {
44
Carousel,
55
Configure,

playground/javascript/browser/src/Panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import type React from 'react';
22

33
type PanelProps = React.PropsWithChildren<{
44
header: string;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { StrictMode } from 'react'
2-
import { createRoot } from 'react-dom/client'
3-
import './index.css'
4-
import {App} from './App.tsx'
1+
import { StrictMode } from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { App } from './App.tsx';
4+
import './index.css';
55

66
createRoot(document.getElementById('root')!).render(
77
<StrictMode>
88
<App />
99
</StrictMode>,
10-
)
10+
);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { defineConfig } from 'vite'
2-
import react from '@vitejs/plugin-react-swc'
1+
import react from '@vitejs/plugin-react-swc';
2+
import { defineConfig } from 'vite';
33

44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7-
})
7+
});

playground/javascript/node/algoliasearch.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function testAlgoliasearch() {
1616
// Init client with appId and apiKey
1717
const client = algoliasearch(appId, apiKey);
1818
const clientLite = liteClient(appId, apiKey);
19-
19+
2020
client.addAlgoliaAgent('algoliasearch node playground', '0.0.1');
2121

2222
try {
@@ -134,12 +134,21 @@ async function testAlgoliasearch() {
134134

135135
async function testAlgoliasearchBridgeIngestion() {
136136
// Init client with appId and apiKey
137-
const client = algoliasearch(appId, adminApiKey, { transformation: { region: 'eu'}});
138-
139-
await client.saveObjectsWithTransformation({indexName: "foo", objects: [{objectID: "foo", data: {baz: "baz", win: 42}}], waitForTasks: true })
140-
141-
await client.partialUpdateObjectsWithTransformation({indexName: "foo", objects: [{objectID: "foo", data: {baz: "baz", win: 42}}], waitForTasks: true, createIfNotExists: false })
137+
const client = algoliasearch(appId, adminApiKey, { transformation: { region: 'eu' } });
138+
139+
await client.saveObjectsWithTransformation({
140+
indexName: 'foo',
141+
objects: [{ objectID: 'foo', data: { baz: 'baz', win: 42 } }],
142+
waitForTasks: true,
143+
});
144+
145+
await client.partialUpdateObjectsWithTransformation({
146+
indexName: 'foo',
147+
objects: [{ objectID: 'foo', data: { baz: 'baz', win: 42 } }],
148+
waitForTasks: true,
149+
createIfNotExists: false,
150+
});
142151
}
143152

144153
// testAlgoliasearch();
145-
testAlgoliasearchBridgeIngestion()
154+
testAlgoliasearchBridgeIngestion();

playground/javascript/node/analytics.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ const client = analyticsClient(appId, apiKey, 'de');
1111

1212
async function testAnalytics() {
1313
try {
14-
const res = await client.getTopFilterForAttribute({
15-
attribute: 'myAttribute1,myAttribute2',
16-
index: analyticsIndex,
17-
}, {timeouts: {read:20000, write: 30000}});
14+
const res = await client.getTopFilterForAttribute(
15+
{
16+
attribute: 'myAttribute1,myAttribute2',
17+
index: analyticsIndex,
18+
},
19+
{ timeouts: { read: 20000, write: 30000 } },
20+
);
1821

1922
console.log(`[OK]`, res);
2023
} catch (e) {

0 commit comments

Comments
 (0)