From 401781f530568a4ca3106f2647f07ea39fb2d1a0 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Fri, 19 Nov 2021 15:03:19 +0100 Subject: [PATCH 1/6] fix some types and default --- package.json | 3 ++- specs/schemas/Record.yml | 4 ++-- specs/schemas/SearchParams.yml | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 97ebfface8..b5fa07c56e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "playground/javascript/" ], "scripts": { - "build:spec": "yarn swagger-cli bundle openapi_spec/spec.yml --outfile dist/openapi.yml --type yaml", + "build:spec": "yarn swagger-cli bundle specs/spec.yml --outfile dist/openapi.yml --type yaml", + "build:spec:json": "yarn swagger-cli bundle specs/spec.yml --outfile dist/openapi.json --type json", "clean": "rm -rf **/dist **/build **/node_modules", "client:build-js": "cd clients/algoliasearch-client-javascript/ && yarn install && yarn build && cd ../../", "client:build": "yarn client:build-js", diff --git a/specs/schemas/Record.yml b/specs/schemas/Record.yml index a41bf93019..016dbfb1d2 100644 --- a/specs/schemas/Record.yml +++ b/specs/schemas/Record.yml @@ -74,10 +74,10 @@ rankingInfo: additionalProperties: false properties: lat: - type: float + type: number description: 'Latitude of the matched location.' lng: - type: float + type: number description: 'Longitude of the matched location.' distance: type: integer diff --git a/specs/schemas/SearchParams.yml b/specs/schemas/SearchParams.yml index 12dea2e006..10f642d6a8 100644 --- a/specs/schemas/SearchParams.yml +++ b/specs/schemas/SearchParams.yml @@ -215,13 +215,11 @@ searchParams: items: type: number description: Search inside a rectangular area (in geo coordinates). - default: null insidePolygon: type: array items: type: number description: Search inside a polygon (in geo coordinates). - default: null ignorePlurals: type: string description: Treats singular, plurals, and other forms of declensions as matching terms. From 52f8f7968d3364ce65ad70c8257ef729705e505a Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Fri, 19 Nov 2021 15:44:20 +0100 Subject: [PATCH 2/6] raname Error to ErrorBase because it clashes with standard typescript Error --- .../client-search/searchApi.ts | 1 + .../model/errorBase.ts | 22 +++++++++++++++++++ .../model/models.ts | 6 ++--- specs/responses/BadRequest.yml | 2 +- specs/responses/IndexNotFound.yml | 2 +- specs/schemas/{Error.yml => ErrorBase.yml} | 0 6 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 clients/algoliasearch-client-javascript/model/errorBase.ts rename specs/schemas/{Error.yml => ErrorBase.yml} (100%) diff --git a/clients/algoliasearch-client-javascript/client-search/searchApi.ts b/clients/algoliasearch-client-javascript/client-search/searchApi.ts index 804d1da2b5..f7039e9e53 100644 --- a/clients/algoliasearch-client-javascript/client-search/searchApi.ts +++ b/clients/algoliasearch-client-javascript/client-search/searchApi.ts @@ -5,6 +5,7 @@ import { Headers, Host, Request, RequestOptions } from '../utils/types'; import { BatchObject } from '../model/batchObject'; import { BatchResponse } from '../model/batchResponse'; +import { ErrorBase } from '../model/errorBase'; import { MultipleQueriesObject } from '../model/multipleQueriesObject'; import { MultipleQueriesResponse } from '../model/multipleQueriesResponse'; import { SaveObjectResponse } from '../model/saveObjectResponse'; diff --git a/clients/algoliasearch-client-javascript/model/errorBase.ts b/clients/algoliasearch-client-javascript/model/errorBase.ts new file mode 100644 index 0000000000..8b62065523 --- /dev/null +++ b/clients/algoliasearch-client-javascript/model/errorBase.ts @@ -0,0 +1,22 @@ +import { RequestFile } from './models'; + +/** + * Error + */ +export class ErrorBase extends null { + 'message'?: string; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ + { + name: 'message', + baseName: 'message', + type: 'string', + }, + ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(ErrorBase.attributeTypeMap); + } +} diff --git a/clients/algoliasearch-client-javascript/model/models.ts b/clients/algoliasearch-client-javascript/model/models.ts index fd9cb170bf..20a2a1e2da 100644 --- a/clients/algoliasearch-client-javascript/model/models.ts +++ b/clients/algoliasearch-client-javascript/model/models.ts @@ -2,8 +2,8 @@ import type { RequestOptions } from '../utils/types'; export * from './batchObject'; export * from './batchResponse'; +export * from './errorBase'; export * from './highlightResult'; -export * from './modelError'; export * from './multipleQueries'; export * from './multipleQueriesObject'; export * from './multipleQueriesResponse'; @@ -32,8 +32,8 @@ export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; import { BatchObject } from './batchObject'; import { BatchResponse } from './batchResponse'; +import { ErrorBase } from './errorBase'; import { HighlightResult } from './highlightResult'; -import { ModelError } from './modelError'; import { MultipleQueries } from './multipleQueries'; import { MultipleQueriesObject } from './multipleQueriesObject'; import { MultipleQueriesResponse } from './multipleQueriesResponse'; @@ -67,8 +67,8 @@ let enumsMap: { [index: string]: any } = { let typeMap: { [index: string]: any } = { BatchObject: BatchObject, BatchResponse: BatchResponse, + ErrorBase: ErrorBase, HighlightResult: HighlightResult, - ModelError: ModelError, MultipleQueries: MultipleQueries, MultipleQueriesObject: MultipleQueriesObject, MultipleQueriesResponse: MultipleQueriesResponse, diff --git a/specs/responses/BadRequest.yml b/specs/responses/BadRequest.yml index b811bc1e78..bd78840b4f 100644 --- a/specs/responses/BadRequest.yml +++ b/specs/responses/BadRequest.yml @@ -2,4 +2,4 @@ description: Bad request or request arguments content: application/json: schema: - $ref: '../schemas/Error.yml' + $ref: '../schemas/ErrorBase.yml' diff --git a/specs/responses/IndexNotFound.yml b/specs/responses/IndexNotFound.yml index 73fd650f77..a13beb85b1 100644 --- a/specs/responses/IndexNotFound.yml +++ b/specs/responses/IndexNotFound.yml @@ -2,4 +2,4 @@ description: Index not found content: application/json: schema: - $ref: '../schemas/Error.yml' + $ref: '../schemas/ErrorBase.yml' diff --git a/specs/schemas/Error.yml b/specs/schemas/ErrorBase.yml similarity index 100% rename from specs/schemas/Error.yml rename to specs/schemas/ErrorBase.yml From 3780bfd57eb9a7159148aa148d372ee8d94880ba Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Mon, 22 Nov 2021 09:53:42 +0100 Subject: [PATCH 3/6] remove useless code --- .../client-search/apis.ts | 12 ++-------- .../client-search/searchApi.ts | 2 -- .../model/batchObject.ts | 1 - .../model/batchResponse.ts | 2 -- .../model/errorBase.ts | 2 -- .../model/highlightResult.ts | 2 -- .../model/modelError.ts | 22 ------------------- .../model/models.ts | 12 ---------- .../model/multipleQueries.ts | 2 -- .../model/multipleQueriesObject.ts | 1 - .../model/multipleQueriesResponse.ts | 1 - .../model/operation.ts | 2 -- .../model/rankingInfo.ts | 1 - .../model/rankingInfoMatchedGeoLocation.ts | 2 -- .../model/record.ts | 1 - .../model/saveObjectResponse.ts | 2 -- .../model/searchParams.ts | 2 -- .../model/searchParamsString.ts | 2 -- .../model/searchResponse.ts | 1 - .../model/searchResponseFacetsStats.ts | 2 -- .../model/snippetResult.ts | 2 -- .../utils/Requester.ts | 2 +- .../utils/Transporter.ts | 2 +- clients/utils/javascript/Requester.ts | 2 +- clients/utils/javascript/Transporter.ts | 2 +- playground/javascript/app.ts | 12 +++++----- templates/javascript/api-all.mustache | 12 ++-------- templates/javascript/api-single.mustache | 2 -- templates/javascript/model.mustache | 1 - templates/javascript/models.mustache | 12 ---------- 30 files changed, 14 insertions(+), 109 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/model/modelError.ts diff --git a/clients/algoliasearch-client-javascript/client-search/apis.ts b/clients/algoliasearch-client-javascript/client-search/apis.ts index 886f823050..862aa147ff 100644 --- a/clients/algoliasearch-client-javascript/client-search/apis.ts +++ b/clients/algoliasearch-client-javascript/client-search/apis.ts @@ -1,16 +1,8 @@ export * from './searchApi'; import { SearchApi } from './searchApi'; -import * as http from 'http'; - -export class HttpError extends Error { - constructor(public response: http.IncomingMessage, public body: any, public statusCode?: number) { - super('HTTP request failed'); - this.name = 'HttpError'; - } -} - -export { RequestFile } from '../model/models'; export class searchClient extends SearchApi {} +export * from '../utils/errors'; + export const APIS = [SearchApi]; diff --git a/clients/algoliasearch-client-javascript/client-search/searchApi.ts b/clients/algoliasearch-client-javascript/client-search/searchApi.ts index f7039e9e53..70284bea6f 100644 --- a/clients/algoliasearch-client-javascript/client-search/searchApi.ts +++ b/clients/algoliasearch-client-javascript/client-search/searchApi.ts @@ -16,8 +16,6 @@ import { SearchResponse } from '../model/searchResponse'; import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models'; import { HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models'; -import { HttpError, RequestFile } from './apis'; - export enum SearchApiApiKeys { apiKey, appId, diff --git a/clients/algoliasearch-client-javascript/model/batchObject.ts b/clients/algoliasearch-client-javascript/model/batchObject.ts index 443d3201bb..0a1428e699 100644 --- a/clients/algoliasearch-client-javascript/model/batchObject.ts +++ b/clients/algoliasearch-client-javascript/model/batchObject.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { Operation } from './operation'; export class BatchObject { diff --git a/clients/algoliasearch-client-javascript/model/batchResponse.ts b/clients/algoliasearch-client-javascript/model/batchResponse.ts index f4effb8376..c5eeb8d619 100644 --- a/clients/algoliasearch-client-javascript/model/batchResponse.ts +++ b/clients/algoliasearch-client-javascript/model/batchResponse.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class BatchResponse { /** * taskID of the indexing task to wait for. diff --git a/clients/algoliasearch-client-javascript/model/errorBase.ts b/clients/algoliasearch-client-javascript/model/errorBase.ts index 8b62065523..c9d4cb8e85 100644 --- a/clients/algoliasearch-client-javascript/model/errorBase.ts +++ b/clients/algoliasearch-client-javascript/model/errorBase.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - /** * Error */ diff --git a/clients/algoliasearch-client-javascript/model/highlightResult.ts b/clients/algoliasearch-client-javascript/model/highlightResult.ts index de5d38781a..d3101098fe 100644 --- a/clients/algoliasearch-client-javascript/model/highlightResult.ts +++ b/clients/algoliasearch-client-javascript/model/highlightResult.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class HighlightResult { /** * Markup text with occurrences highlighted. diff --git a/clients/algoliasearch-client-javascript/model/modelError.ts b/clients/algoliasearch-client-javascript/model/modelError.ts deleted file mode 100644 index 13fc1b8937..0000000000 --- a/clients/algoliasearch-client-javascript/model/modelError.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { RequestFile } from './models'; - -/** - * Error - */ -export class ModelError extends null { - 'message'?: string; - - static discriminator: string | undefined = undefined; - - static attributeTypeMap: Array<{ name: string; baseName: string; type: string }> = [ - { - name: 'message', - baseName: 'message', - type: 'string', - }, - ]; - - static getAttributeTypeMap() { - return super.getAttributeTypeMap().concat(ModelError.attributeTypeMap); - } -} diff --git a/clients/algoliasearch-client-javascript/model/models.ts b/clients/algoliasearch-client-javascript/model/models.ts index 20a2a1e2da..edd74146de 100644 --- a/clients/algoliasearch-client-javascript/model/models.ts +++ b/clients/algoliasearch-client-javascript/model/models.ts @@ -18,18 +18,6 @@ export * from './searchResponse'; export * from './searchResponseFacetsStats'; export * from './snippetResult'; -import * as fs from 'fs'; - -export interface RequestDetailedFile { - value: Buffer; - options?: { - filename?: string; - contentType?: string; - }; -} - -export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; - import { BatchObject } from './batchObject'; import { BatchResponse } from './batchResponse'; import { ErrorBase } from './errorBase'; diff --git a/clients/algoliasearch-client-javascript/model/multipleQueries.ts b/clients/algoliasearch-client-javascript/model/multipleQueries.ts index ec21e366b4..9acaadac44 100644 --- a/clients/algoliasearch-client-javascript/model/multipleQueries.ts +++ b/clients/algoliasearch-client-javascript/model/multipleQueries.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class MultipleQueries { /** * The Algolia index name diff --git a/clients/algoliasearch-client-javascript/model/multipleQueriesObject.ts b/clients/algoliasearch-client-javascript/model/multipleQueriesObject.ts index 35d55da74d..c093684133 100644 --- a/clients/algoliasearch-client-javascript/model/multipleQueriesObject.ts +++ b/clients/algoliasearch-client-javascript/model/multipleQueriesObject.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { MultipleQueries } from './multipleQueries'; export class MultipleQueriesObject { diff --git a/clients/algoliasearch-client-javascript/model/multipleQueriesResponse.ts b/clients/algoliasearch-client-javascript/model/multipleQueriesResponse.ts index dcf1fdf7d1..334774a50e 100644 --- a/clients/algoliasearch-client-javascript/model/multipleQueriesResponse.ts +++ b/clients/algoliasearch-client-javascript/model/multipleQueriesResponse.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { SearchResponse } from './searchResponse'; export class MultipleQueriesResponse { diff --git a/clients/algoliasearch-client-javascript/model/operation.ts b/clients/algoliasearch-client-javascript/model/operation.ts index 771fd8cd80..2c008cdad5 100644 --- a/clients/algoliasearch-client-javascript/model/operation.ts +++ b/clients/algoliasearch-client-javascript/model/operation.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class Operation { /** * type of operation diff --git a/clients/algoliasearch-client-javascript/model/rankingInfo.ts b/clients/algoliasearch-client-javascript/model/rankingInfo.ts index 60f0aac8be..7af7562160 100644 --- a/clients/algoliasearch-client-javascript/model/rankingInfo.ts +++ b/clients/algoliasearch-client-javascript/model/rankingInfo.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { RankingInfoMatchedGeoLocation } from './rankingInfoMatchedGeoLocation'; export class RankingInfo { diff --git a/clients/algoliasearch-client-javascript/model/rankingInfoMatchedGeoLocation.ts b/clients/algoliasearch-client-javascript/model/rankingInfoMatchedGeoLocation.ts index 91b552ad44..58aab4d485 100644 --- a/clients/algoliasearch-client-javascript/model/rankingInfoMatchedGeoLocation.ts +++ b/clients/algoliasearch-client-javascript/model/rankingInfoMatchedGeoLocation.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class RankingInfoMatchedGeoLocation { /** * Latitude of the matched location. diff --git a/clients/algoliasearch-client-javascript/model/record.ts b/clients/algoliasearch-client-javascript/model/record.ts index 7400eda991..f4a3de4042 100644 --- a/clients/algoliasearch-client-javascript/model/record.ts +++ b/clients/algoliasearch-client-javascript/model/record.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { HighlightResult } from './highlightResult'; import { RankingInfo } from './rankingInfo'; import { SnippetResult } from './snippetResult'; diff --git a/clients/algoliasearch-client-javascript/model/saveObjectResponse.ts b/clients/algoliasearch-client-javascript/model/saveObjectResponse.ts index 90020ef73a..4761e6f28c 100644 --- a/clients/algoliasearch-client-javascript/model/saveObjectResponse.ts +++ b/clients/algoliasearch-client-javascript/model/saveObjectResponse.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class SaveObjectResponse { 'createdAt'?: string; /** diff --git a/clients/algoliasearch-client-javascript/model/searchParams.ts b/clients/algoliasearch-client-javascript/model/searchParams.ts index f342201182..3728d48467 100644 --- a/clients/algoliasearch-client-javascript/model/searchParams.ts +++ b/clients/algoliasearch-client-javascript/model/searchParams.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class SearchParams { /** * The text to search in the index. diff --git a/clients/algoliasearch-client-javascript/model/searchParamsString.ts b/clients/algoliasearch-client-javascript/model/searchParamsString.ts index d64b7587ef..968d23a198 100644 --- a/clients/algoliasearch-client-javascript/model/searchParamsString.ts +++ b/clients/algoliasearch-client-javascript/model/searchParamsString.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class SearchParamsString { 'params'?: string; diff --git a/clients/algoliasearch-client-javascript/model/searchResponse.ts b/clients/algoliasearch-client-javascript/model/searchResponse.ts index 8d36b775a8..21e3c7853f 100644 --- a/clients/algoliasearch-client-javascript/model/searchResponse.ts +++ b/clients/algoliasearch-client-javascript/model/searchResponse.ts @@ -1,4 +1,3 @@ -import { RequestFile } from './models'; import { Record } from './record'; import { SearchResponseFacetsStats } from './searchResponseFacetsStats'; diff --git a/clients/algoliasearch-client-javascript/model/searchResponseFacetsStats.ts b/clients/algoliasearch-client-javascript/model/searchResponseFacetsStats.ts index a929906956..ff2f3a37ef 100644 --- a/clients/algoliasearch-client-javascript/model/searchResponseFacetsStats.ts +++ b/clients/algoliasearch-client-javascript/model/searchResponseFacetsStats.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class SearchResponseFacetsStats { /** * The minimum value in the result set. diff --git a/clients/algoliasearch-client-javascript/model/snippetResult.ts b/clients/algoliasearch-client-javascript/model/snippetResult.ts index bb590bd75e..8b5b509181 100644 --- a/clients/algoliasearch-client-javascript/model/snippetResult.ts +++ b/clients/algoliasearch-client-javascript/model/snippetResult.ts @@ -1,5 +1,3 @@ -import { RequestFile } from './models'; - export class SnippetResult { /** * Markup text with occurrences highlighted. diff --git a/clients/algoliasearch-client-javascript/utils/Requester.ts b/clients/algoliasearch-client-javascript/utils/Requester.ts index 61a8c2b24a..1319da1bb1 100644 --- a/clients/algoliasearch-client-javascript/utils/Requester.ts +++ b/clients/algoliasearch-client-javascript/utils/Requester.ts @@ -63,7 +63,7 @@ export class Requester { req.on('error', (error) => { clearTimeout(connectTimeout); - clearTimeout(responseTimeout as NodeJS.Timeout); + clearTimeout(responseTimeout!); resolve({ status: 0, content: error.message, isTimedOut: false }); }); diff --git a/clients/algoliasearch-client-javascript/utils/Transporter.ts b/clients/algoliasearch-client-javascript/utils/Transporter.ts index 8a6a096e2d..ed8dd4dfeb 100644 --- a/clients/algoliasearch-client-javascript/utils/Transporter.ts +++ b/clients/algoliasearch-client-javascript/utils/Transporter.ts @@ -144,7 +144,7 @@ export class Transporter { method, url: serializeUrl(host, request.path, queryParameters), connectTimeout: getTimeout(timeoutsCount, this.timeouts.connect), - responseTimeout: getTimeout(timeoutsCount, requestOptions.timeout as number), + responseTimeout: getTimeout(timeoutsCount, requestOptions.timeout ?? this.timeouts.read), }; /** diff --git a/clients/utils/javascript/Requester.ts b/clients/utils/javascript/Requester.ts index 61a8c2b24a..1319da1bb1 100644 --- a/clients/utils/javascript/Requester.ts +++ b/clients/utils/javascript/Requester.ts @@ -63,7 +63,7 @@ export class Requester { req.on('error', (error) => { clearTimeout(connectTimeout); - clearTimeout(responseTimeout as NodeJS.Timeout); + clearTimeout(responseTimeout!); resolve({ status: 0, content: error.message, isTimedOut: false }); }); diff --git a/clients/utils/javascript/Transporter.ts b/clients/utils/javascript/Transporter.ts index 8a6a096e2d..ed8dd4dfeb 100644 --- a/clients/utils/javascript/Transporter.ts +++ b/clients/utils/javascript/Transporter.ts @@ -144,7 +144,7 @@ export class Transporter { method, url: serializeUrl(host, request.path, queryParameters), connectTimeout: getTimeout(timeoutsCount, this.timeouts.connect), - responseTimeout: getTimeout(timeoutsCount, requestOptions.timeout as number), + responseTimeout: getTimeout(timeoutsCount, requestOptions.timeout ?? this.timeouts.read), }; /** diff --git a/playground/javascript/app.ts b/playground/javascript/app.ts index 6d7edcde5e..e99e594fbf 100644 --- a/playground/javascript/app.ts +++ b/playground/javascript/app.ts @@ -1,4 +1,4 @@ -import { searchClient, HttpError } from 'algoliasearch-client-javascript'; +import { searchClient, ApiError } from 'algoliasearch-client-javascript'; import dotenv from 'dotenv'; dotenv.config(); @@ -22,8 +22,8 @@ async function testMultiQueries() { console.log(`[OK]`, res); } catch (e) { - if (e instanceof HttpError) { - return console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response); + if (e instanceof ApiError) { + return console.log(`[${e.status}] ${e.message}`, e.stackTrace); } console.log('[ERROR]', e); @@ -32,14 +32,14 @@ async function testMultiQueries() { async function testSearch() { try { - const res = await client.search('docsearch', { + const res = await client.search('test', { query: 'crawler', }); console.log(`[OK]`, res); } catch (e) { - if (e instanceof HttpError) { - return console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response); + if (e instanceof ApiError) { + return console.log(`[${e.status}] ${e.message}`, e.stackTrace); } console.log('[ERROR]', e); diff --git a/templates/javascript/api-all.mustache b/templates/javascript/api-all.mustache index e1457d3dc9..f3ed11450c 100644 --- a/templates/javascript/api-all.mustache +++ b/templates/javascript/api-all.mustache @@ -8,18 +8,10 @@ import { {{ classname }} } from './{{ classFilename }}'; export * from './{{ classFilename }}Interface' {{/withInterfaces}} {{/apis}} -import * as http from 'http'; - -export class HttpError extends Error { - constructor (public response: http.IncomingMessage, public body: any, public statusCode?: number) { - super('HTTP request failed'); - this.name = 'HttpError'; - } -} - -export { RequestFile } from '../model/models'; export class searchClient extends SearchApi{} +export * from '../utils/errors'; + export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}]; {{/apiInfo}} diff --git a/templates/javascript/api-single.mustache b/templates/javascript/api-single.mustache index f191f90e9d..5cc0362efd 100644 --- a/templates/javascript/api-single.mustache +++ b/templates/javascript/api-single.mustache @@ -12,8 +12,6 @@ import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../mode import { HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models'; {{/hasAuthMethods}} -import { HttpError, RequestFile } from './apis'; - {{#operations}} {{#description}} /** diff --git a/templates/javascript/model.mustache b/templates/javascript/model.mustache index f96acdcaab..d0ac52fa22 100644 --- a/templates/javascript/model.mustache +++ b/templates/javascript/model.mustache @@ -1,6 +1,5 @@ {{#models}} {{#model}} -import { RequestFile } from './models'; {{#tsImports}} import { {{classname}} } from '{{filename}}'; {{/tsImports}} diff --git a/templates/javascript/models.mustache b/templates/javascript/models.mustache index 551e865c0a..90757fbd55 100644 --- a/templates/javascript/models.mustache +++ b/templates/javascript/models.mustache @@ -8,18 +8,6 @@ export * from '{{{ classFilename }}}'; {{/model}} {{/models}} -import * as fs from 'fs'; - -export interface RequestDetailedFile { - value: Buffer; - options?: { - filename?: string; - contentType?: string; - } -} - -export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; - {{! Object serialization only relevant if generating APIs, too }} {{#generateApis}} From 5c13d4e2818f1847d84e3ebc99a7e739ff2cfcea Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Mon, 22 Nov 2021 11:48:51 +0100 Subject: [PATCH 4/6] remove broken parent --- .../model/errorBase.ts | 6 ++++-- .../algoliasearch-client-javascript/model/record.ts | 6 ++++-- templates/javascript/model.mustache | 11 +++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/clients/algoliasearch-client-javascript/model/errorBase.ts b/clients/algoliasearch-client-javascript/model/errorBase.ts index c9d4cb8e85..3d09e61548 100644 --- a/clients/algoliasearch-client-javascript/model/errorBase.ts +++ b/clients/algoliasearch-client-javascript/model/errorBase.ts @@ -1,7 +1,9 @@ /** * Error */ -export class ErrorBase extends null { +// Add this line back when we understnad where parent come from, but for now it's breaking the code +// export class ErrorBase extends null +export class ErrorBase { 'message'?: string; static discriminator: string | undefined = undefined; @@ -15,6 +17,6 @@ export class ErrorBase extends null { ]; static getAttributeTypeMap() { - return super.getAttributeTypeMap().concat(ErrorBase.attributeTypeMap); + return ErrorBase.attributeTypeMap; } } diff --git a/clients/algoliasearch-client-javascript/model/record.ts b/clients/algoliasearch-client-javascript/model/record.ts index f4a3de4042..5a1345ff1a 100644 --- a/clients/algoliasearch-client-javascript/model/record.ts +++ b/clients/algoliasearch-client-javascript/model/record.ts @@ -5,7 +5,9 @@ import { SnippetResult } from './snippetResult'; /** * A single record */ -export class Record extends null { +// Add this line back when we understnad where parent come from, but for now it's breaking the code +// export class Record extends null +export class Record { /** * Unique identifier of the object */ @@ -46,6 +48,6 @@ export class Record extends null { ]; static getAttributeTypeMap() { - return super.getAttributeTypeMap().concat(Record.attributeTypeMap); + return Record.attributeTypeMap; } } diff --git a/templates/javascript/model.mustache b/templates/javascript/model.mustache index d0ac52fa22..fc9d802168 100644 --- a/templates/javascript/model.mustache +++ b/templates/javascript/model.mustache @@ -10,7 +10,11 @@ import { {{classname}} } from '{{filename}}'; */ {{/description}} {{^isEnum}} -export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#parent}} +// Add this line back when we understnad where parent come from, but for now it's breaking the code +// export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}} +{{/parent}} +export class {{classname}} { {{#vars}} {{#description}} /** @@ -40,12 +44,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ ]; static getAttributeTypeMap() { - {{#parent}} - return super.getAttributeTypeMap().concat({{classname}}.attributeTypeMap); - {{/parent}} - {{^parent}} return {{classname}}.attributeTypeMap; - {{/parent}} } {{/isArray}} } From 721d0b36bb94f2f815874d75a080f46a5cd9b190 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Mon, 22 Nov 2021 12:06:48 +0100 Subject: [PATCH 5/6] fix typo --- clients/algoliasearch-client-javascript/model/errorBase.ts | 1 - clients/algoliasearch-client-javascript/model/record.ts | 1 - templates/javascript/model.mustache | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/clients/algoliasearch-client-javascript/model/errorBase.ts b/clients/algoliasearch-client-javascript/model/errorBase.ts index 3d09e61548..ab910b0cef 100644 --- a/clients/algoliasearch-client-javascript/model/errorBase.ts +++ b/clients/algoliasearch-client-javascript/model/errorBase.ts @@ -1,7 +1,6 @@ /** * Error */ -// Add this line back when we understnad where parent come from, but for now it's breaking the code // export class ErrorBase extends null export class ErrorBase { 'message'?: string; diff --git a/clients/algoliasearch-client-javascript/model/record.ts b/clients/algoliasearch-client-javascript/model/record.ts index 5a1345ff1a..e833f3e2aa 100644 --- a/clients/algoliasearch-client-javascript/model/record.ts +++ b/clients/algoliasearch-client-javascript/model/record.ts @@ -5,7 +5,6 @@ import { SnippetResult } from './snippetResult'; /** * A single record */ -// Add this line back when we understnad where parent come from, but for now it's breaking the code // export class Record extends null export class Record { /** diff --git a/templates/javascript/model.mustache b/templates/javascript/model.mustache index fc9d802168..bbb50e5cec 100644 --- a/templates/javascript/model.mustache +++ b/templates/javascript/model.mustache @@ -11,7 +11,7 @@ import { {{classname}} } from '{{filename}}'; {{/description}} {{^isEnum}} {{#parent}} -// Add this line back when we understnad where parent come from, but for now it's breaking the code +{{! TODO: Add this line back when we understand where parent come from, but for now it's breaking the code}} // export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}} {{/parent}} export class {{classname}} { From fba7222c80ecb2093d2d3e43737876b44ea93b9b Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Mon, 22 Nov 2021 16:52:07 +0100 Subject: [PATCH 6/6] review --- README.md | 4 ++-- playground/{javascript => }/.env.example | 3 +++ playground/javascript/app.ts | 13 ++++++++----- specs/schemas/Record.yml | 4 +++- specs/schemas/SearchResponse.yml | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) rename playground/{javascript => }/.env.example (67%) diff --git a/README.md b/README.md index cda1b7f9f7..e491854c59 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ yarn client:build # Testing clients -Go to the [`playground`](./playground) folder to test your client +The clients can be tested inside the [`playground`](./playground) folder ## JavaScript ```bash -cd playground/javascript && yarn start +yarn playground:js ``` # Troubleshooting diff --git a/playground/javascript/.env.example b/playground/.env.example similarity index 67% rename from playground/javascript/.env.example rename to playground/.env.example index c906f42033..88ab91239e 100644 --- a/playground/javascript/.env.example +++ b/playground/.env.example @@ -1,3 +1,6 @@ ALGOLIA_APPLICATION_ID="" ALGOLIA_ADMIN_KEY="" ALGOLIA_SEARCH_KEY="" + +SEARCH_INDEX="" +SEARCH_QUERY="" diff --git a/playground/javascript/app.ts b/playground/javascript/app.ts index e99e594fbf..c20f5f2a62 100644 --- a/playground/javascript/app.ts +++ b/playground/javascript/app.ts @@ -1,11 +1,14 @@ import { searchClient, ApiError } from 'algoliasearch-client-javascript'; import dotenv from 'dotenv'; -dotenv.config(); +dotenv.config({ path: '../.env' }); const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****'; const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****'; +const searchIndex = process.env.SEARCH_INDEX || 'test_index'; +const searchQuery = process.env.SEARCH_QUERY || 'test_query'; + // Init client with appId and apiKey const client = new searchClient(appId, apiKey); @@ -14,8 +17,8 @@ async function testMultiQueries() { const res = await client.multipleQueries({ requests: [ { - indexName: 'docsearch', - query: 'crawler', + indexName: searchIndex, + query: searchQuery, }, ], }); @@ -32,8 +35,8 @@ async function testMultiQueries() { async function testSearch() { try { - const res = await client.search('test', { - query: 'crawler', + const res = await client.search(searchIndex, { + query: searchQuery, }); console.log(`[OK]`, res); diff --git a/specs/schemas/Record.yml b/specs/schemas/Record.yml index 016dbfb1d2..564ef9bc6c 100644 --- a/specs/schemas/Record.yml +++ b/specs/schemas/Record.yml @@ -14,7 +14,7 @@ record: _rankingInfo: $ref: '#/rankingInfo' _distinctSeqID: - type: number + type: integer # Props highlightResult: @@ -75,9 +75,11 @@ rankingInfo: properties: lat: type: number + format: double description: 'Latitude of the matched location.' lng: type: number + format: double description: 'Longitude of the matched location.' distance: type: integer diff --git a/specs/schemas/SearchResponse.yml b/specs/schemas/SearchResponse.yml index 472f12b169..ce5c41877d 100644 --- a/specs/schemas/SearchResponse.yml +++ b/specs/schemas/SearchResponse.yml @@ -101,7 +101,7 @@ searchResponse: type: string description: The query string that will be searched, after normalization. processingTimeMS: - type: number + type: integer description: Time the server took to process the request, in milliseconds. example: 20 query: