Skip to content

Commit

Permalink
Merge branch 'main' into fix/review-common-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Jul 19, 2023
2 parents 1121c39 + 550313a commit 3277490
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ final class SearchClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.post,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType,
growable: growable)),
) as ReturnType;
}
if (targetType == 'Object') {
return value;
}
break;
}
throw Exception('Cannot deserialize');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class DioRequester implements Requester {
options: Options(
method: request.method,
headers: request.headers,
contentType: request.body != null ? Headers.jsonContentType : null,
sendTimeout: request.timeout,
receiveTimeout: request.timeout,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ final class InsightsClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.delete,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -100,8 +99,7 @@ final class InsightsClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.get,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -137,8 +135,7 @@ final class InsightsClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.post,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -201,8 +198,7 @@ final class InsightsClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.put,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType,
growable: growable)),
) as ReturnType;
}
if (targetType == 'Object') {
return value;
}
break;
}
throw Exception('Cannot deserialize');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ final class SearchClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.delete,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -775,8 +774,7 @@ final class SearchClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.get,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -1457,8 +1455,7 @@ final class SearchClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.post,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down Expand Up @@ -1495,8 +1492,7 @@ final class SearchClient implements ApiClient {
);
final request = ApiRequest(
method: RequestMethod.put,
path: r'/1{path}'
.replaceAll('{' r'path' '}', Uri.encodeComponent(path.toString())),
path: r'/1{path}'.replaceAll('{' r'path' '}', path),
queryParams: {
...?parameters,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ ReturnType deserialize<ReturnType, BaseType>(dynamic value, String targetType,
growable: growable)),
) as ReturnType;
}
if (targetType == 'Object') {
return value;
}
break;
}
throw Exception('Cannot deserialize');
Expand Down
1 change: 1 addition & 0 deletions config/generation.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const patterns = [
'!clients/algoliasearch-client-javascript/.yarn/**',
'!clients/algoliasearch-client-javascript/scripts/**',
'!clients/algoliasearch-client-javascript/tests/**',
'!clients/algoliasearch-client-javascript/packages/**/package.json',
'!clients/algoliasearch-client-javascript/packages/requester-*/**',
'!clients/algoliasearch-client-javascript/packages/client-common/**',
'!clients/algoliasearch-client-javascript/packages/algoliasearch/__tests__/**',
Expand Down
15 changes: 8 additions & 7 deletions scripts/__tests__/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { getClientsConfigField } from '../config.js';
jest.unstable_mockModule('execa', () => {
return {
execaCommand: jest.fn(),
execa: jest.fn(),
};
});

const { capitalize, createClientName, gitCommit } = await import(
'../common.js'
);
const { execaCommand } = await import('execa');
const { execa } = await import('execa');

describe('gitCommit', () => {
afterEach(() => {
Expand All @@ -20,9 +21,9 @@ describe('gitCommit', () => {

it('commits with message', () => {
gitCommit({ message: 'chore: does something' });
expect(execaCommand).toHaveBeenCalledTimes(1);
expect(execaCommand).toHaveBeenCalledWith(
'git commit -m "chore: does something"',
expect(execa).toHaveBeenCalledTimes(1);
expect(execa).toHaveBeenCalledWith(
'git', ["commit", "-m", "chore: does something"],
{ cwd: expect.any(String) }
);
});
Expand All @@ -47,9 +48,9 @@ describe('gitCommit', () => {
message: 'chore: does something',
coAuthors: [author, ...coAuthors],
});
expect(execaCommand).toHaveBeenCalledTimes(1);
expect(execaCommand).toHaveBeenCalledWith(
'git commit -m "chore: does something\n\n\nCo-authored-by: them <them@algolia.com>\nCo-authored-by: me <me@algolia.com>\nCo-authored-by: you <you@algolia.com>"',
expect(execa).toHaveBeenCalledTimes(1);
expect(execa).toHaveBeenCalledWith(
'git', ["commit", "-m", "chore: does something\n\n\nCo-authored-by: them <them@algolia.com>\nCo-authored-by: me <me@algolia.com>\nCo-authored-by: you <you@algolia.com>"],
{ cwd: expect.any(String) }
);
});
Expand Down
4 changes: 2 additions & 2 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fsp from 'fs/promises';
import path from 'path';

import { Octokit } from '@octokit/rest';
import { execaCommand } from 'execa';
import { execaCommand, execa } from 'execa';
import type { ExecaError } from 'execa';
import { hashElement } from 'folder-hash';
import { remove } from 'fs-extra';
Expand Down Expand Up @@ -154,7 +154,7 @@ export async function gitCommit({
? `${message}\n\n\n${coAuthors.join('\n')}`
: message;

await execaCommand(`git commit -m "${messageWithCoAuthors}"`, { cwd });
await execa('git', ['commit', '-m', messageWithCoAuthors], { cwd });
}

export async function checkForCache({
Expand Down
7 changes: 6 additions & 1 deletion templates/dart/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ final class {{classname}} implements ApiClient {
{{/isFreeFormObject}}
{{/requiredParams}}
final request = ApiRequest(
method: RequestMethod.{{#lambda.snakecase}}{{httpMethod}}{{/lambda.snakecase}},
method: RequestMethod.{{#lambda.snakecase}}{{httpMethod}}{{/lambda.snakecase}},
{{^vendorExtensions.x-is-custom-request}}
path: r'{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{{baseName}}}' '}', Uri.encodeComponent({{{paramName}}}.toString())){{/pathParams}},
{{/vendorExtensions.x-is-custom-request}}
{{#vendorExtensions.x-is-custom-request}}
path: r'{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{{baseName}}}' '}', {{{paramName}}}){{/pathParams}},
{{/vendorExtensions.x-is-custom-request}}
{{#vendorExtensions.x-use-read-transporter}}
isRead : {{{vendorExtensions.x-use-read-transporter}}},
{{/vendorExtensions.x-use-read-transporter}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');
value.values.map((dynamic v) => deserialize<BaseType, BaseType>(v, targetType, growable: growable)),
) as ReturnType;
}
if (targetType == 'Object') {
return value;
}
break;
}
throw Exception('Cannot deserialize');
Expand Down

0 comments on commit 3277490

Please sign in to comment.