Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ private void transferPrimitiveData(IJsonSchemaValidationProperties spec, Map<Str
case "Boolean":
output.put("isBoolean", true);
break;
case "oas_any_type_not_mapped":
output.put("isAnyType", true);
output.put("isFreeFormObject", true);
break;
default:
throw new CTSException("Unknown primitive: " + getTypeName(spec));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ private static void setHasChildGeneric(IJsonSchemaValidationProperties property)
setVendorExtension(property, "x-has-child-generic", true);
}

private static void setHasGenericParameter(CodegenOperation ope) {
ope.vendorExtensions.put("x-has-generic-parameter", true);
}

/**
* @return true if the vendor extensions of the property contains either x-propagated-generic or
* x-has-child-generic
Expand Down Expand Up @@ -224,9 +228,17 @@ public static void propagateGenericsToOperations(OperationsMap operations, List<
public static void propagateGenericsToOperations(String language, String client, OperationsMap operations, List<ModelMap> allModels) {
Map<String, CodegenModel> models = convertToMap(language, client, allModels);
for (CodegenOperation ope : operations.getOperations().getOperation()) {
for (CodegenParameter param : ope.requiredParams) {
if (param.vendorExtensions.containsKey("x-is-generic")) {
setHasGenericParameter(ope);
break;
}
}

if (ope.returnType == null) {
continue;
}

CodegenModel returnType = models.get(ope.returnType);
if (returnType != null && hasGeneric(returnType)) {
ope.vendorExtensions.put("x-is-generic", true);
Expand Down
17 changes: 7 additions & 10 deletions playground/javascript/browser/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import js from '@eslint/js';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
Expand All @@ -19,10 +19,7 @@ export default tseslint.config(
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
)
);
5 changes: 3 additions & 2 deletions playground/javascript/browser/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ h1 {
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
}

em {
Expand Down
2 changes: 1 addition & 1 deletion playground/javascript/browser/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { liteClient as algoliasearch } from 'algoliasearch/lite';
import { Hit } from 'instantsearch.js';
import type { Hit } from 'instantsearch.js';
import {
Carousel,
Configure,
Expand Down
2 changes: 1 addition & 1 deletion playground/javascript/browser/src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import type React from 'react';

type PanelProps = React.PropsWithChildren<{
header: string;
Expand Down
10 changes: 5 additions & 5 deletions playground/javascript/browser/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import {App} from './App.tsx'
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App.tsx';
import './index.css';

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
);
6 changes: 3 additions & 3 deletions playground/javascript/browser/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';

// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})
});
23 changes: 16 additions & 7 deletions playground/javascript/node/algoliasearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function testAlgoliasearch() {
// Init client with appId and apiKey
const client = algoliasearch(appId, apiKey);
const clientLite = liteClient(appId, apiKey);

client.addAlgoliaAgent('algoliasearch node playground', '0.0.1');

try {
Expand Down Expand Up @@ -134,12 +134,21 @@ async function testAlgoliasearch() {

async function testAlgoliasearchBridgeIngestion() {
// Init client with appId and apiKey
const client = algoliasearch(appId, adminApiKey, { transformation: { region: 'eu'}});

await client.saveObjectsWithTransformation({indexName: "foo", objects: [{objectID: "foo", data: {baz: "baz", win: 42}}], waitForTasks: true })

await client.partialUpdateObjectsWithTransformation({indexName: "foo", objects: [{objectID: "foo", data: {baz: "baz", win: 42}}], waitForTasks: true, createIfNotExists: false })
const client = algoliasearch(appId, adminApiKey, { transformation: { region: 'eu' } });

await client.saveObjectsWithTransformation({
indexName: 'foo',
objects: [{ objectID: 'foo', data: { baz: 'baz', win: 42 } }],
waitForTasks: true,
});

await client.partialUpdateObjectsWithTransformation({
indexName: 'foo',
objects: [{ objectID: 'foo', data: { baz: 'baz', win: 42 } }],
waitForTasks: true,
createIfNotExists: false,
});
}

// testAlgoliasearch();
testAlgoliasearchBridgeIngestion()
testAlgoliasearchBridgeIngestion();
11 changes: 7 additions & 4 deletions playground/javascript/node/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ const client = analyticsClient(appId, apiKey, 'de');

async function testAnalytics() {
try {
const res = await client.getTopFilterForAttribute({
attribute: 'myAttribute1,myAttribute2',
index: analyticsIndex,
}, {timeouts: {read:20000, write: 30000}});
const res = await client.getTopFilterForAttribute(
{
attribute: 'myAttribute1,myAttribute2',
index: analyticsIndex,
},
{ timeouts: { read: 20000, write: 30000 } },
);

console.log(`[OK]`, res);
} catch (e) {
Expand Down
5 changes: 2 additions & 3 deletions playground/javascript/node/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = compositionClient(appId, apiKey);

async function testComposition() {
try {
console.log(appId, apiKey)
console.log(appId, apiKey);
// create a new composition
// const res = await client.multipleBatch({
// requests: [
Expand All @@ -36,8 +36,7 @@ async function testComposition() {
// });
// console.log(`[OK]`, res);

console.log(await client.search({ compositionID: 'id1', requestBody: {} }))

console.log(await client.search({ compositionID: 'id1', requestBody: {} }));
} catch (e) {
if (e instanceof ApiError) {
return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e);
Expand Down
5 changes: 2 additions & 3 deletions playground/javascript/node/compositionFull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = compositionClient(appId, apiKey);

async function testComposition() {
try {
console.log(appId, apiKey)
console.log(appId, apiKey);
// create a new composition
// const res = await client.multipleBatch({
// requests: [
Expand All @@ -36,8 +36,7 @@ async function testComposition() {
// });
// console.log(`[OK]`, res);

console.log(await client.listCompositions())

console.log(await client.listCompositions());
} catch (e) {
if (e instanceof ApiError) {
return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e);
Expand Down
23 changes: 20 additions & 3 deletions playground/javascript/node/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiError } from '@algolia/client-common';
import { apiClientVersion, searchClient, SearchQuery } from '@algolia/client-search';
import type { SearchQuery } from '@algolia/client-search';
import { apiClientVersion, searchClient } from '@algolia/client-search';

const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
const apiKey = process.env.ALGOLIA_ADMIN_KEY || '**** SEARCH_API_KEY *****';
Expand All @@ -15,15 +16,31 @@ client.addAlgoliaAgent('Node playground', '0.0.1');
const requests: SearchQuery[] = [{ indexName: searchIndex, query: searchQuery }];
console.log('version', apiClientVersion, 'requests', requests);

interface Animal {
name: string;
age: number;
objectID: string;
}

async function testSearch() {
try {
const req = await client.setSettings({
indexName: 'theIndexName',
indexSettings: { distinct: true },
})

});

console.log(`[OK]`, req);

const a: Animal = {
name: 'Dog',
age: 5,
objectID: 'dog-123',
};

const ssss = await client.saveObject({
indexName: 'theIndexName',
body: a,
});
} catch (e: any) {
// Instance of
if (e instanceof ApiError) {
Expand Down
5 changes: 5 additions & 0 deletions specs/search/paths/objects/object.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ put:
requestBody:
required: true
description: The record. A schemaless object with attributes that are useful in the context of search and discovery.
x-is-generic: true
content:
application/json:
schema:
type: object
example:
objectID: blackTShirt
name: Black T-shirt
color: '#000000'
responses:
'200':
$ref: '../../../common/responses/UpdatedAtWithObjectId.yml'
Expand Down
5 changes: 5 additions & 0 deletions specs/search/paths/objects/objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ post:
requestBody:
required: true
description: The record. A schemaless object with attributes that are useful in the context of search and discovery.
x-is-generic: true
content:
application/json:
schema:
type: object
example:
objectID: blackTShirt
name: Black T-shirt
color: '#000000'
responses:
'201':
description: Created
Expand Down
2 changes: 1 addition & 1 deletion templates/javascript/clients/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({
{{/isCompositionFullClient}}
{{#operation}}
{{> client/api/operation/jsdoc}}
{{nickname}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}( {{> client/api/operation/parameters}} ) : Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}> {
{{nickname}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}{{#vendorExtensions.x-has-generic-parameter}}<T extends object>{{/vendorExtensions.x-has-generic-parameter}}( {{> client/api/operation/parameters}} ) : Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}{{#vendorExtensions.x-is-generic}}<T>{{/vendorExtensions.x-is-generic}}> {
{{#vendorExtensions.x-legacy-signature}}
{{> client/api/operation/legacySearchCompatible/implementation}}
{{/vendorExtensions.x-legacy-signature}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#vendorExtensions}}
{{#x-create-wrapping-object}}
{ {{#allParams}}{{paramName}}, {{/allParams}} }: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props{{^hasRequiredParams}} = {}{{/hasRequiredParams}},
{ {{#allParams}}{{paramName}}, {{/allParams}} }: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props{{#x-has-generic-parameter}}<T>{{/x-has-generic-parameter}}{{^hasRequiredParams}} = {}{{/hasRequiredParams}},
{{/x-create-wrapping-object}}
{{#x-is-single-body-param}}
{{#bodyParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import type { CreateIterablePromise } from '@algolia/client-common';
/**
* Properties for the `{{nickname}}` method.
*/
export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props{{#x-has-generic-parameter}}<T extends object>{{/x-has-generic-parameter}} = {
{{#allParams}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
{{paramName}}{{^required}}?{{/required}}: {{{dataType}}};
{{paramName}}{{^required}}?{{/required}}: {{#vendorExtensions.x-is-generic}}T{{/vendorExtensions.x-is-generic}}{{^vendorExtensions.x-is-generic}}{{{dataType}}}{{/vendorExtensions.x-is-generic}};
{{/allParams}}
}
{{/x-create-wrapping-object}}
Expand Down