Skip to content

Commit

Permalink
fix(specs): provide non clashing names for custom methods (#2369)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Dec 12, 2023
1 parent 4ad25d3 commit 8d71c2b
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.105
0.0.108
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('api', () => {
});

it('sets the user agent', async () => {
const req = (await client.post({
const req = (await client.customPost({
path: '/test',
})) as unknown as EchoResponse;

Expand Down Expand Up @@ -166,13 +166,13 @@ describe('api', () => {
region: 'eu',
});

const res1 = (await abtestingClient.get({
const res1 = (await abtestingClient.customGet({
path: 'abtestingClient',
})) as unknown as EchoResponse;
const res2 = (await analyticsClient.get({
const res2 = (await analyticsClient.customGet({
path: 'analyticsClient',
})) as unknown as EchoResponse;
const res3 = (await personalizationClient.get({
const res3 = (await personalizationClient.customGet({
path: 'personalizationClient',
})) as unknown as EchoResponse;

Expand Down Expand Up @@ -211,13 +211,13 @@ describe('api', () => {
region: 'eu',
});

const res1 = (await abtestingClient.get({
const res1 = (await abtestingClient.customGet({
path: 'abtestingClient',
})) as unknown as EchoResponse;
const res2 = (await analyticsClient.get({
const res2 = (await analyticsClient.customGet({
path: 'analyticsClient',
})) as unknown as EchoResponse;
const res3 = (await personalizationClient.get({
const res3 = (await personalizationClient.customGet({
path: 'personalizationClient',
})) as unknown as EchoResponse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Helpers {
/** The suffix of our client names. */
public static final String API_SUFFIX = "Client";

public static final Set<String> CUSTOM_METHODS = Set.of("del", "get", "post", "put");
public static final Set<String> CUSTOM_METHODS = Set.of("customDelete", "customGet", "customPost", "customPut");

private static JsonNode cacheConfig;
private static JsonNode cacheOpenApiToolsConfig;
Expand Down
6 changes: 3 additions & 3 deletions scripts/buildSpecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkForCache, exists, run, toAbsolutePath } from './common.js';
import { createSpinner } from './spinners.js';
import type { Spec } from './types.js';

const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'post'];
const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'customPost'];

/**
* This function will transform properties in the bundle depending on the context.
Expand Down Expand Up @@ -142,8 +142,8 @@ async function buildLiteSpec({
// Filter methods.
parsed.paths = Object.entries(parsed.paths).reduce(
(acc, [path, operations]) => {
for (const [method, operation] of Object.entries(operations)) {
if (method === 'post' && ALGOLIASEARCH_LITE_OPERATIONS.includes(operation.operationId)) {
for (const [, operation] of Object.entries(operations)) {
if (ALGOLIASEARCH_LITE_OPERATIONS.includes(operation.operationId)) {
return { ...acc, [path]: { post: operation } };
}
}
Expand Down
8 changes: 4 additions & 4 deletions specs/common/paths/customRequest.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
get:
operationId: get
operationId: customGet
$ref: '../schemas/CustomRequest.yml#/customRequest'

post:
operationId: post
operationId: customPost
requestBody:
description: Parameters to send with the custom request.
content:
Expand All @@ -13,7 +13,7 @@ post:
$ref: '../schemas/CustomRequest.yml#/customRequest'

put:
operationId: put
operationId: customPut
requestBody:
description: Parameters to send with the custom request.
content:
Expand All @@ -23,5 +23,5 @@ put:
$ref: '../schemas/CustomRequest.yml#/customRequest'

delete:
operationId: del
operationId: customDelete
$ref: '../schemas/CustomRequest.yml#/customRequest'
40 changes: 39 additions & 1 deletion templates/dart/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,45 @@ final class {{classname}} implements ApiClient {
}
{{/operation}}

@Deprecated('This operation has been deprecated, use `customPost` instead')
Future<Object> post({
required String path,
Map<String, Object>? parameters, Object? body,
RequestOptions? requestOptions,
}) async {
return this.customPost(path: path, parameters: parameters, requestOptions: requestOptions);
}

{{^isAlgoliasearchClient}}
@Deprecated('This operation has been deprecated, use `customPut` instead')
Future<Object> put({
required String path,
Map<String, Object>? parameters, Object? body,
RequestOptions? requestOptions,
}) async {
return customPut(path: path, parameters: parameters, requestOptions: requestOptions);
}

@Deprecated('This operation has been deprecated, use `customGet` instead')
Future<Object> get({
required String path,
Map<String, Object>? parameters, Object? body,
RequestOptions? requestOptions,
}) async {
return this.customGet(path: path, parameters: parameters, requestOptions: requestOptions);
}

@Deprecated('This operation has been deprecated, use `customDelete` instead')
Future<Object> del({
required String path,
Map<String, Object>? parameters, Object? body,
RequestOptions? requestOptions,
}) async {
return this.customDelete(path: path, parameters: parameters, requestOptions: requestOptions);
}
{{/isAlgoliasearchClient}}

@override
void dispose() => _retryStrategy.dispose();
}
{{/operations}}
{{/operations}}
18 changes: 12 additions & 6 deletions templates/javascript/clients/algoliasearch/builds/models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {
} from '{{{npmNamespace}}}/client-common';
import {
ErrorBase,
PutProps,
PostProps,
DelProps,
GetProps,
CustomPutProps,
CustomPostProps,
CustomDeleteProps,
CustomGetProps,
} from '{{{npmNamespace}}}/client-search/model';

export * from '{{{npmNamespace}}}/client-search/model';
Expand All @@ -23,7 +23,13 @@ export { PersonalizationClient } from '{{{npmNamespace}}}/client-personalization
export { AnalyticsClient } from '{{{npmNamespace}}}/client-analytics';
export { AbtestingClient } from '{{{npmNamespace}}}/client-abtesting';

export { ErrorBase, PutProps, PostProps, DelProps, GetProps };
export {
ErrorBase,
CustomPutProps,
CustomPostProps,
CustomDeleteProps,
CustomGetProps,
};

/**
* Options forwarded to the client initialized via the `init` method.
Expand All @@ -45,4 +51,4 @@ export type InitClientRegion<TRegion> = Partial<{
* Available regions of the initialized client.
*/
region: TRegion;
}>;
}>;
2 changes: 1 addition & 1 deletion tests/CTS/client/analytics/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"type": "method",
"object": "$client",
"path": "post",
"path": "customPost",
"parameters": {
"path": "/test"
},
Expand Down
6 changes: 3 additions & 3 deletions tests/CTS/client/common/commonApi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"type": "method",
"object": "$client",
"path": "post",
"path": "customPost",
"parameters": {
"path": "/test"
},
Expand All @@ -22,7 +22,7 @@
{
"type": "method",
"object": "$client",
"path": "get",
"path": "customGet",
"parameters": {
"path": "/test"
},
Expand All @@ -42,7 +42,7 @@
{
"type": "method",
"object": "$client",
"path": "post",
"path": "customPost",
"parameters": {
"path": "/test"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/CTS/client/insights/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"type": "method",
"object": "$client",
"path": "del",
"path": "customDelete",
"parameters": {
"path": "/test"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/CTS/client/recommend/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"type": "method",
"object": "$client",
"path": "get",
"path": "customGet",
"parameters": {
"path": "/test"
},
Expand All @@ -40,7 +40,7 @@
{
"type": "method",
"object": "$client",
"path": "post",
"path": "customPost",
"parameters": {
"path": "/test"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/CTS/client/search/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"type": "method",
"object": "$client",
"path": "get",
"path": "customGet",
"parameters": {
"path": "/test"
},
Expand All @@ -40,7 +40,7 @@
{
"type": "method",
"object": "$client",
"path": "post",
"path": "customPost",
"parameters": {
"path": "/test"
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8d71c2b

Please sign in to comment.