diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/config/Requester.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/config/Requester.java index 1051876a4c..d368fb0634 100644 --- a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/config/Requester.java +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/config/Requester.java @@ -4,35 +4,30 @@ import java.io.Closeable; /** - * Represents a mechanism for executing HTTP requests and deserializing - * responses. It provides - * methods for making requests and returning the desired object representation. - * Implementations of + * Represents a mechanism for executing HTTP requests and deserializing responses. It provides + * methods for making requests and returning the desired object representation. Implementations of * this interface should ensure proper resource management. */ public interface Requester extends Closeable { /** - * Executes an HTTP request and deserializes the response into a specified Java - * type. + * Executes an HTTP request and deserializes the response into a specified Java type. * - * @param The type of the returned object. - * @param httpRequest The HTTP request to be executed. + * @param The type of the returned object. + * @param httpRequest The HTTP request to be executed. * @param requestOptions Optional request options. - * @param returnType The class of the response. - * @param innerType The inner class type if the response is a container - * type. + * @param returnType The class of the response. + * @param innerType The inner class type if the response is a container type. * @return The deserialized response. */ T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class returnType, Class innerType); /** - * Executes an HTTP request and deserializes the response into a specified type - * reference. + * Executes an HTTP request and deserializes the response into a specified type reference. * - * @param The type of the returned object. - * @param httpRequest The HTTP request to be executed. + * @param The type of the returned object. + * @param httpRequest The HTTP request to be executed. * @param requestOptions Optional request options. - * @param returnType The type reference of the response. + * @param returnType The type reference of the response. * @return The deserialized response. */ T execute(HttpRequest httpRequest, RequestOptions requestOptions, TypeReference returnType); diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java index d64be28f74..a0780750f4 100644 --- a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java @@ -20,10 +20,8 @@ import okio.BufferedSink; /** - * HttpRequester is responsible for making HTTP requests using the OkHttp - * client. It provides a - * mechanism for request serialization and deserialization using a given - * {@link JsonSerializer}. + * HttpRequester is responsible for making HTTP requests using the OkHttp client. It provides a + * mechanism for request serialization and deserialization using a given {@link JsonSerializer}. */ public final class HttpRequester implements Requester { @@ -35,11 +33,11 @@ public final class HttpRequester implements Requester { /** Private constructor initialized using the builder pattern. */ private HttpRequester(Builder builder, ClientConfig config) { OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder() - .connectTimeout(config.getConnectTimeout()) - .readTimeout(config.getReadTimeout()) - .writeTimeout(config.getWriteTimeout()) - .addInterceptor(new HeaderInterceptor(config.getDefaultHeaders())) - .addNetworkInterceptor(new LogInterceptor(config.getLogger(), config.getLogLevel())); + .connectTimeout(config.getConnectTimeout()) + .readTimeout(config.getReadTimeout()) + .writeTimeout(config.getWriteTimeout()) + .addInterceptor(new HeaderInterceptor(config.getDefaultHeaders())) + .addNetworkInterceptor(new LogInterceptor(config.getLogger(), config.getLogLevel())); builder.interceptors.forEach(clientBuilder::addInterceptor); builder.networkInterceptors.forEach(clientBuilder::addNetworkInterceptor); if (config.getCompressionType() == CompressionType.GZIP) { @@ -53,8 +51,7 @@ private HttpRequester(Builder builder, ClientConfig config) { } @Override - public T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class returnType, - Class innerType) { + public T execute(HttpRequest httpRequest, RequestOptions requestOptions, Class returnType, Class innerType) { return execute(httpRequest, requestOptions, serializer.getJavaType(returnType, innerType)); } @@ -80,8 +77,7 @@ private T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp RequestBody requestBody = createRequestBody(httpRequest); // Build the HTTP request. - Request request = new Request.Builder().url(url).headers(headers).method(httpRequest.getMethod(), requestBody) - .build(); + Request request = new Request.Builder().url(url).headers(headers).method(httpRequest.getMethod(), requestBody).build(); // Get or adjust the HTTP client according to request options. OkHttpClient client = getOkHttpClient(requestOptions); @@ -110,9 +106,9 @@ private T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp @Nonnull private static HttpUrl createHttpUrl(@Nonnull HttpRequest request, RequestOptions requestOptions) { HttpUrl.Builder urlBuilder = new HttpUrl.Builder() - .scheme("https") - .host("algolia.com") // will be overridden by the retry strategy - .encodedPath(request.getPath()); + .scheme("https") + .host("algolia.com") // will be overridden by the retry strategy + .encodedPath(request.getPath()); request.getQueryParameters().forEach(urlBuilder::addEncodedQueryParameter); if (requestOptions != null) { requestOptions.getQueryParameters().forEach(urlBuilder::addEncodedQueryParameter); @@ -160,15 +156,11 @@ private Headers createHeaders(@Nonnull HttpRequest request, RequestOptions reque return builder.build(); } - /** - * Returns a suitable OkHttpClient instance based on the provided request - * options. - */ + /** Returns a suitable OkHttpClient instance based on the provided request options. */ @Nonnull private OkHttpClient getOkHttpClient(RequestOptions requestOptions) { // Return the default client if no request options are provided. - if (requestOptions == null) - return httpClient; + if (requestOptions == null) return httpClient; // Create a new client builder from the default client and adjust timeouts if // provided. @@ -184,8 +176,7 @@ private OkHttpClient getOkHttpClient(RequestOptions requestOptions) { @Override public void close() throws IOException { - if (isClosed.get()) - return; + if (isClosed.get()) return; httpClient.dispatcher().executorService().shutdown(); httpClient.connectionPool().evictAll(); if (httpClient.cache() != null) { @@ -195,8 +186,7 @@ public void close() throws IOException { } /** - * The Builder class for HttpRequester. It provides a mechanism for constructing - * an instance of + * The Builder class for HttpRequester. It provides a mechanism for constructing an instance of * HttpRequester with customized configurations. */ public static class Builder { diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/internal/HttpRequester.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/internal/HttpRequester.scala index f34bad424a..9852516423 100644 --- a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/internal/HttpRequester.scala +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/internal/HttpRequester.scala @@ -45,12 +45,14 @@ private[algoliasearch] class HttpRequester private ( } override def setAlgoliaApiKey(apiKey: String): Unit = { - httpClient.newBuilder().addInterceptor(new Interceptor { - override def intercept(chain: Interceptor.Chain): Response = { - val request = chain.request().newBuilder().addHeader("X-Algolia-API-Key", apiKey).build() - chain.proceed(request) - } - }) + httpClient + .newBuilder() + .addInterceptor(new Interceptor { + override def intercept(chain: Interceptor.Chain): Response = { + val request = chain.request().newBuilder().addHeader("X-Algolia-API-Key", apiKey).build() + chain.proceed(request) + } + }) } private val jsonSerializer = JsonSerializer()(builder.formats) diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift index 002254ac60..43b7e6ea6d 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift @@ -42,7 +42,7 @@ open class Transporter { self.requestBuilder = requestBuilder } - + public func setAlgoliaApiKey(apiKey: String) { self.configuration.defaultHeaders?.updateValue(apiKey, forKey: "X-Algolia-API-Key") } diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index 727c80ae5c..1009bd84d4 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -10,6 +10,7 @@ import java.util.Map; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenResponse; import org.openapitools.codegen.SupportingFile; public class TestsClient extends TestsGenerator { @@ -114,9 +115,25 @@ public void run(Map models, Map stepOut.put("returnsBoolean", ope.returnType.equals("Boolean")); // ruby requires a ? for boolean functions. } + stepOut.put("isHelper", (boolean) ope.vendorExtensions.getOrDefault("x-helper", false)); + + // default to true because most api calls are asynchronous + stepOut.put("isAsync", (boolean) ope.vendorExtensions.getOrDefault("x-asynchronous-helper", true)); + // Determines whether the endpoint is expected to return a response payload + // deserialized and therefore a variable to store it into. + stepOut.put("hasResponsePayload", true); + + for (CodegenResponse response : ope.responses) { + if (response.code.equals("204")) { + stepOut.put("hasResponsePayload", false); + } + } + // set on testOut because we need to wrap everything for java. testOut.put("isHelper", (boolean) ope.vendorExtensions.getOrDefault("x-helper", false)); - testOut.put("isAsync", (boolean) ope.vendorExtensions.getOrDefault("x-asynchronous-helper", true)); // default to true because most api calls are asynchronous + + // default to true because most api calls are asynchronous + testOut.put("isAsync", (boolean) ope.vendorExtensions.getOrDefault("x-asynchronous-helper", true)); } stepOut.put("method", step.method); diff --git a/scripts/cts/testServer/apiKey.ts b/scripts/cts/testServer/apiKey.ts new file mode 100644 index 0000000000..76149c9b94 --- /dev/null +++ b/scripts/cts/testServer/apiKey.ts @@ -0,0 +1,35 @@ +import type { Server } from 'http'; + +import { expect } from 'chai'; +import type { Express, Request, Response } from 'express'; + +import { setupServer } from '.'; + +function addRoutes(app: Express): void { + app.get('/check-api-key/1', (req: Request, res: Response) => { + const headerName = 'x-algolia-api-key'; + + // eslint-disable-next-line no-unused-expressions + expect(headerName in req.headers).to.be.true; + + const headerAPIKeyValue = req.headers[headerName]; + expect(headerAPIKeyValue).to.equal('test-api-key'); + + res.status(200).json({ headerAPIKeyValue }); + }); + app.get('/check-api-key/2', (req: Request, res: Response) => { + const headerName = 'x-algolia-api-key'; + + // eslint-disable-next-line no-unused-expressions + expect(headerName in req.headers).to.be.true; + + const headerAPIKeyValue = req.headers[headerName]; + expect(headerAPIKeyValue).to.equal('updated-api-key'); + + res.status(200).json({ headerAPIKeyValue }); + }); +} + +export function apiKeyServer(): Promise { + return setupServer('apiKey', 6683, addRoutes); +} diff --git a/scripts/cts/testServer/index.ts b/scripts/cts/testServer/index.ts index c44dfb0adb..27b1477b0c 100644 --- a/scripts/cts/testServer/index.ts +++ b/scripts/cts/testServer/index.ts @@ -6,6 +6,7 @@ import type { Express } from 'express'; import { createSpinner } from '../../spinners'; import type { CTSType } from '../runCts'; +import { apiKeyServer } from './apiKey'; import { benchmarkServer } from './benchmark'; import { chunkWrapperServer } from './chunkWrapper'; import { gzipServer } from './gzip'; @@ -24,6 +25,7 @@ export async function startTestServer(suites: Record): Promise replaceAllObjectsServer(), chunkWrapperServer(), waitForApiKeyServer(), + apiKeyServer(), ); } if (suites.benchmark) { @@ -61,7 +63,7 @@ export async function setupServer(name: string, port: number, addRoutes: (app: E }); // catch all error handler - app.use((err, req, res, _) => { + app.use((err, _req, res, _) => { // eslint-disable-next-line no-console console.error(err.message); res.status(500).send({ message: err.message }); diff --git a/scripts/cts/testServer/waitFor.ts b/scripts/cts/testServer/waitFor.ts index 9e3eb7d949..68f68e4b6e 100644 --- a/scripts/cts/testServer/waitFor.ts +++ b/scripts/cts/testServer/waitFor.ts @@ -114,13 +114,13 @@ function addRoutes(app: Express): void { } }); - app.get('/1/indexes/:indexName/task/:taskID', (req, res) => { + app.get('/1/indexes/:indexName/task/:taskID', (_req, res) => { res.status(200).json({ status: 'published', }); }); - app.get('/1/task/:taskID', (req, res) => { + app.get('/1/task/:taskID', (_req, res) => { res.status(200).json({ status: 'published', }); diff --git a/specs/common/helpers/setAlgoliaApiKey.yml b/specs/common/helpers/setAlgoliaApiKey.yml index 3c5989ca1d..93da40ab6e 100644 --- a/specs/common/helpers/setAlgoliaApiKey.yml +++ b/specs/common/helpers/setAlgoliaApiKey.yml @@ -16,11 +16,7 @@ method: schema: type: string responses: - '200': - description: OK - content: - application/json: - schema: - type: string + '204': + description: No content. '400': $ref: '../../common/responses/IndexNotFound.yml' diff --git a/templates/csharp/tests/client/method.mustache b/templates/csharp/tests/client/method.mustache index 2436bd70e6..eb74ea8948 100644 --- a/templates/csharp/tests/client/method.mustache +++ b/templates/csharp/tests/client/method.mustache @@ -1,2 +1,2 @@ -{{^useEchoRequester}}var res = {{/useEchoRequester}}{{> tests/method}}; +{{^useEchoRequester}}{{#hasResponsePayload}}var res = {{/hasResponsePayload}}{{/useEchoRequester}}{{> tests/method}}; {{#useEchoRequester}}EchoResponse result = _echo.LastResponse;{{/useEchoRequester}} \ No newline at end of file diff --git a/templates/csharp/tests/client/tests.mustache b/templates/csharp/tests/client/tests.mustache index 232c779a44..1d32f8e178 100644 --- a/templates/csharp/tests/client/tests.mustache +++ b/templates/csharp/tests/client/tests.mustache @@ -6,6 +6,7 @@ var client = new {{client}}(new {{clientPrefix}}Config("appId", "apiKey"{{#hasRegionalHost}},"{{defaultRegion}}"{{/hasRegionalHost}}), _echo); {{/autoCreateClient}} {{#steps}} + { {{#times}} for (int i = 0; i < {{.}}; i++) { {{/times}} @@ -39,6 +40,7 @@ {{#times}} } {{/times}} + } {{/steps}} } {{/tests}} \ No newline at end of file diff --git a/templates/dart/tests/client/client.mustache b/templates/dart/tests/client/client.mustache index c333e0f5e3..b476ae3400 100644 --- a/templates/dart/tests/client/client.mustache +++ b/templates/dart/tests/client/client.mustache @@ -20,7 +20,8 @@ void main() { options: ClientOptions(requester: requester), ); {{/autoCreateClient}} - {{#steps}} + {{#steps}} + { {{#isError}} await expectError( '{{{expectedError}}}', @@ -45,6 +46,7 @@ void main() { {{/match}} {{#dynamicTemplate}}{{/dynamicTemplate}} {{/isError}} + } {{/steps}} } ); diff --git a/templates/dart/tests/client/method.mustache b/templates/dart/tests/client/method.mustache index 15baf9e21e..07f6b44e5f 100644 --- a/templates/dart/tests/client/method.mustache +++ b/templates/dart/tests/client/method.mustache @@ -1,5 +1,5 @@ try { - final res = await client.{{method}}( + {{#hasResponsePayload}}final res = {{/hasResponsePayload}}await client.{{method}}( {{#parametersWithDataType}} {{> tests/request_param}} {{/parametersWithDataType}} diff --git a/templates/go/client.mustache b/templates/go/client.mustache index 4b557b877d..b2b08d78bd 100644 --- a/templates/go/client.mustache +++ b/templates/go/client.mustache @@ -141,7 +141,7 @@ func (c *APIClient) GetConfiguration() *{{#lambda.titlecase}}{{#lambda.camelcase } // Allow update of stored API key used to authenticate requests. -func (c *APIClient) SetApiKey(apiKey string) { +func (c *APIClient) SetAlgoliaApiKey(apiKey string) { c.cfg.ApiKey = apiKey } diff --git a/templates/go/tests/client/method.mustache b/templates/go/tests/client/method.mustache index 58b2d3316e..0ab15503bd 100644 --- a/templates/go/tests/client/method.mustache +++ b/templates/go/tests/client/method.mustache @@ -1 +1 @@ -res, err = {{> tests/method}} \ No newline at end of file +{{#hasResponsePayload}}res, err = {{/hasResponsePayload}}{{> tests/method}} \ No newline at end of file diff --git a/templates/go/tests/client/tests.mustache b/templates/go/tests/client/tests.mustache index 3834085ea7..e5010e9676 100644 --- a/templates/go/tests/client/tests.mustache +++ b/templates/go/tests/client/tests.mustache @@ -15,6 +15,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{testType}}{{/lambda.titlecase}}{ {{/autoCreateClient}} _ = echo {{#steps}} + { {{#times}} for i := 0; i < {{.}}; i++ { {{/times}} @@ -54,6 +55,7 @@ func Test{{#lambda.titlecase}}{{clientPrefix}}{{testType}}{{/lambda.titlecase}}{ {{#times}} } {{/times}} + } {{/steps}} } diff --git a/templates/java/tests/client/method.mustache b/templates/java/tests/client/method.mustache index 535638be3b..72a9846754 100644 --- a/templates/java/tests/client/method.mustache +++ b/templates/java/tests/client/method.mustache @@ -1,2 +1,2 @@ -{{^useEchoRequester}}{{{returnType}}} res = {{/useEchoRequester}}{{> tests/method}}; +{{^useEchoRequester}}{{#hasResponsePayload}}{{{returnType}}} res = {{/hasResponsePayload}}{{/useEchoRequester}}{{> tests/method}}; {{#useEchoRequester}}EchoResponse result = echo.getLastResponse();{{/useEchoRequester}} \ No newline at end of file diff --git a/templates/java/tests/client/tests.mustache b/templates/java/tests/client/tests.mustache index 1a1abece5a..001d499170 100644 --- a/templates/java/tests/client/tests.mustache +++ b/templates/java/tests/client/tests.mustache @@ -6,8 +6,8 @@ void {{testType}}Test{{testIndex}}() { {{client}} client = createClient(); {{/autoCreateClient}} - {{#isHelper}}assertDoesNotThrow(() -> { {{/isHelper}} {{#steps}} + { {{#times}} for (int i = 0; i < {{.}}; i++) { {{/times}} @@ -20,8 +20,9 @@ void {{testType}}Test{{testIndex}}() { } {{/isError}} {{^isError}} + {{#isHelper}}assertDoesNotThrow(() -> { {{/isHelper}} {{#dynamicTemplate}}{{/dynamicTemplate}} - {{#testUserAgent}} + {{#testUserAgent}} { String regexp = {{#match}}{{> tests/generateParams}}{{/match}}; assertTrue(result.headers.get("user-agent").matches(regexp), "Expected " + result.headers.get("user-agent") + " to match the following regex: " + regexp); @@ -42,11 +43,12 @@ void {{testType}}Test{{testIndex}}() { assertDoesNotThrow(() -> JSONAssert.assertEquals({{#match}}{{> tests/generateParams}}{{/match}}, json.writeValueAsString(res), JSONCompareMode.STRICT)); {{/match.isPrimitive}} {{/testResponse}} + {{#isHelper}} });{{/isHelper}} {{/isError}} {{#times}} } {{/times}} + } {{/steps}} - {{#isHelper}} });{{/isHelper}} } {{/tests}} \ No newline at end of file diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index f6f64e0a5b..af58a4b4cd 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -78,9 +78,9 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({ /** * Helper method to switch the API key used to authenticate the requests. * - * @param apiKey - The new API Key to use. + * @param apiKey.apiKey - The new API Key to use. */ - setAlgoliaApiKey(apiKey: string): void { + setAlgoliaApiKey({ apiKey }: { apiKey: string }): void { auth.setAlgoliaApiKey(apiKey); }, @@ -159,4 +159,4 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({ }; } -{{/operations}} +{{/operations}} \ No newline at end of file diff --git a/templates/javascript/tests/client/benchmark.mustache b/templates/javascript/tests/client/benchmark.mustache index 7376e7ca22..21893a540b 100644 --- a/templates/javascript/tests/client/benchmark.mustache +++ b/templates/javascript/tests/client/benchmark.mustache @@ -1,5 +1,5 @@ // {{generationBanner}} -/* eslint-disable @typescript-eslint/no-unused-vars, require-await */ +/* eslint-disable @typescript-eslint/no-unused-vars, require-await, no-lone-blocks */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { {{client}}, {{#lambda.titlecase}}{{client}}{{/lambda.titlecase}} } from '{{{import}}}'; @@ -12,4 +12,4 @@ function createClient(): {{#lambda.titlecase}}{{client}}{{/lambda.titlecase}} { {{#blocksBenchmark}} {{> tests/client/tests}} -{{/blocksBenchmark}} +{{/blocksBenchmark}} \ No newline at end of file diff --git a/templates/javascript/tests/client/client.mustache b/templates/javascript/tests/client/client.mustache index 83cbf6e946..80c6342fb0 100644 --- a/templates/javascript/tests/client/client.mustache +++ b/templates/javascript/tests/client/client.mustache @@ -1,5 +1,5 @@ // {{generationBanner}} -/* eslint-disable @typescript-eslint/no-unused-vars, require-await */ +/* eslint-disable @typescript-eslint/no-unused-vars, require-await, no-lone-blocks */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { {{client}}, {{#lambda.titlecase}}{{client}}{{/lambda.titlecase}} } from '{{{import}}}'; import { echoRequester } from '@algolia/requester-node-http'; diff --git a/templates/javascript/tests/client/method.mustache b/templates/javascript/tests/client/method.mustache index ba7d0c9ef2..0e0148208c 100644 --- a/templates/javascript/tests/client/method.mustache +++ b/templates/javascript/tests/client/method.mustache @@ -1 +1 @@ -const result = {{> tests/method}}{{#useEchoRequester}} as unknown as EchoResponse{{/useEchoRequester}}; \ No newline at end of file +{{#hasResponsePayload}}const result = {{/hasResponsePayload}}{{> tests/method}}{{#useEchoRequester}} as unknown as EchoResponse{{/useEchoRequester}}; \ No newline at end of file diff --git a/templates/javascript/tests/client/tests.mustache b/templates/javascript/tests/client/tests.mustache index 905c51a4a7..7bcbe18f9d 100644 --- a/templates/javascript/tests/client/tests.mustache +++ b/templates/javascript/tests/client/tests.mustache @@ -7,6 +7,7 @@ describe('{{testType}}', () => { {{/autoCreateClient}} {{#steps}} + { {{#times}} for (let i = 0; i < {{.}}; i++) { {{/times}} @@ -47,6 +48,7 @@ describe('{{testType}}', () => { {{#times}} } {{/times}} + } {{/steps}} }, 15000); diff --git a/templates/kotlin/tests/client/tests.mustache b/templates/kotlin/tests/client/tests.mustache index 5be4b6e026..574b0e1796 100644 --- a/templates/kotlin/tests/client/tests.mustache +++ b/templates/kotlin/tests/client/tests.mustache @@ -5,6 +5,7 @@ fun `{{#lambda.replaceBacktick}}{{{testName}}}{{/lambda.replaceBacktick}}`() = r val client = {{client}}(appId = "appId", apiKey = "apiKey",{{#hasRegionalHost}}region = "{{defaultRegion}}",{{/hasRegionalHost}}) {{/autoCreateClient}} {{#steps}} + { {{#times}} for (i in 1..{{.}}) { {{/times}} @@ -62,6 +63,7 @@ fun `{{#lambda.replaceBacktick}}{{{testName}}}{{/lambda.replaceBacktick}}`() = r {{#times}} } {{/times}} + } {{/steps}} } {{/tests}} \ No newline at end of file diff --git a/templates/php/tests/client/method.mustache b/templates/php/tests/client/method.mustache index dcb5b3e70e..80d209dab8 100644 --- a/templates/php/tests/client/method.mustache +++ b/templates/php/tests/client/method.mustache @@ -1 +1 @@ -{{^useEchoRequester}}$res = {{/useEchoRequester}}{{> tests/method}}; \ No newline at end of file +{{^useEchoRequester}}{{#hasResponsePayload}}$res = {{/hasResponsePayload}}{{/useEchoRequester}}{{> tests/method}}; \ No newline at end of file diff --git a/templates/php/tests/client/tests.mustache b/templates/php/tests/client/tests.mustache index 923f57352a..68a741cb12 100644 --- a/templates/php/tests/client/tests.mustache +++ b/templates/php/tests/client/tests.mustache @@ -6,6 +6,7 @@ public function test{{testIndex}}{{testType}}() $client = $this->createClient(self::APP_ID, self::API_KEY); {{/autoCreateClient}} {{#steps}} + { {{#times}} for ($i = 1; $i <= {{.}}; $i++) { {{/times}} @@ -62,6 +63,7 @@ public function test{{testIndex}}{{testType}}() {{#times}} } {{/times}} + } {{/steps}} } diff --git a/templates/python/tests/client/method.mustache b/templates/python/tests/client/method.mustache index 13983a8a67..612c96495e 100644 --- a/templates/python/tests/client/method.mustache +++ b/templates/python/tests/client/method.mustache @@ -1 +1 @@ -{{^isError}}_req = {{/isError}}{{#isAsync}}await {{/isAsync}}self._client.{{#lambda.snakecase}}{{{method}}}{{/lambda.snakecase}}{{#useEchoRequester}}_with_http_info{{/useEchoRequester}}({{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file +{{^isError}}{{#hasResponsePayload}}_req = {{/hasResponsePayload}}{{/isError}}{{#isAsync}}await {{/isAsync}}self._client.{{#lambda.snakecase}}{{{method}}}{{/lambda.snakecase}}{{#useEchoRequester}}_with_http_info{{/useEchoRequester}}({{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file diff --git a/templates/ruby/tests/client/method.mustache b/templates/ruby/tests/client/method.mustache index 93128e5fb8..4558a56d39 100644 --- a/templates/ruby/tests/client/method.mustache +++ b/templates/ruby/tests/client/method.mustache @@ -1 +1 @@ -{{^isError}}req = {{/isError}}client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{#useEchoRequester}}_with_http_info{{/useEchoRequester}}{{#returnsBoolean}}?{{/returnsBoolean}}({{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file +{{^isError}}{{#hasResponsePayload}}req = {{/hasResponsePayload}}{{/isError}}client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{#useEchoRequester}}_with_http_info{{/useEchoRequester}}{{#returnsBoolean}}?{{/returnsBoolean}}({{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file diff --git a/templates/scala/tests/client/method.mustache b/templates/scala/tests/client/method.mustache index a987c7917b..1f3ee378a1 100644 --- a/templates/scala/tests/client/method.mustache +++ b/templates/scala/tests/client/method.mustache @@ -1,4 +1,4 @@ -{{^useEchoRequester}}var res = Await.result{{/useEchoRequester}}{{#useEchoRequester}}Await.ready{{/useEchoRequester}}( - {{> tests/method}}, +{{^useEchoRequester}}{{#hasResponsePayload}}var res = {{/hasResponsePayload}}{{#isAsync}}Await.result{{/isAsync}}{{/useEchoRequester}}{{#isAsync}}{{#useEchoRequester}}Await.ready{{/useEchoRequester}}({{/isAsync}} + {{> tests/method}}{{#isAsync}}, Duration.Inf -) \ No newline at end of file +){{/isAsync}} \ No newline at end of file diff --git a/templates/swift/tests/client/method.mustache b/templates/swift/tests/client/method.mustache index eca4157878..a7db68963d 100644 --- a/templates/swift/tests/client/method.mustache +++ b/templates/swift/tests/client/method.mustache @@ -1,4 +1,4 @@ -let response{{#isGeneric}}: Response<{{{returnType}}}>{{/isGeneric}} = {{> tests/method}} +{{#hasResponsePayload}}let response{{#isGeneric}}: Response<{{{returnType}}}>{{/isGeneric}} = {{/hasResponsePayload}}{{> tests/method}} {{^isHelper}} {{^isBenchmark}} let responseBodyData = try XCTUnwrap(response.bodyData) diff --git a/templates/swift/tests/client/tests.mustache b/templates/swift/tests/client/tests.mustache index e7ea6e855f..a86e3632b4 100644 --- a/templates/swift/tests/client/tests.mustache +++ b/templates/swift/tests/client/tests.mustache @@ -11,6 +11,7 @@ {{/autoCreateClient}} {{#steps}} + {{^isCreateClient}} do { {{/isCreateClient}} {{#times}} for i in 1...{{.}} { {{/times}} @@ -68,6 +69,7 @@ {{#times}} } {{/times}} + {{^isCreateClient}} } {{/isCreateClient}} {{/steps}} } {{/tests}} \ No newline at end of file diff --git a/tests/CTS/client/common/switchApiKey.json b/tests/CTS/client/common/setAlgoliaApiKey.json similarity index 59% rename from tests/CTS/client/common/switchApiKey.json rename to tests/CTS/client/common/setAlgoliaApiKey.json index a71af07870..18f753d029 100644 --- a/tests/CTS/client/common/switchApiKey.json +++ b/tests/CTS/client/common/setAlgoliaApiKey.json @@ -1,23 +1,33 @@ [ { "testName": "switch API key", + "autoCreateClient": false, "steps": [ { "type": "createClient", "parameters": { "appId": "test-app-id", - "apiKey": "test-api-key" + "apiKey": "test-api-key", + "region": "us", + "customHosts": [ + { + "host": "${{localhost}}", + "port": 6683 + } + ] } }, { "type": "method", "method": "customGet", "parameters": { - "path": "check-api-key" + "path": "check-api-key/1" }, "expected": { "type": "response", - "match": "test-api-key" + "match": { + "headerAPIKeyValue": "test-api-key" + } } }, { @@ -31,11 +41,13 @@ "type": "method", "method": "customGet", "parameters": { - "path": "check-api-key" + "path": "check-api-key/2" }, "expected": { "type": "response", - "match": "updated-api-key" + "match": { + "headerAPIKeyValue": "updated-api-key" + } } } ]