Skip to content

Commit a5c233e

Browse files
authored
style: code format (#128)
1 parent ffbdac7 commit a5c233e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+180
-185
lines changed

examples/apis/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
9191
const _baseUrl = baseUrl.replace(/\/$/, "");
9292
return {
9393
getBooks: (option?: RequestOption): Promise<Response$getBooks$Status$200["application/json"]> => {
94-
const url = _baseUrl + `/get/books`;
94+
const url = `${_baseUrl}/get/books`;
9595
const headers = {
9696
Accept: "application/json",
9797
};
@@ -105,7 +105,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
105105
);
106106
},
107107
searchBooks: (params: Params$searchBooks, option?: RequestOption): Promise<Response$searchBooks$Status$200["application/json"]> => {
108-
const url = _baseUrl + `/search/books`;
108+
const url = `${_baseUrl}/search/books`;
109109
const headers = {
110110
Accept: "application/json",
111111
};

examples/apis/sample-axios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const apiClientImpl: ApiClient<RequestOption> = {
3333
options?: RequestOption,
3434
): Promise<any> => {
3535
const query = generateQueryString(queryParameters);
36-
const requestUrl = query ? url + "?" + encodeURI(query) : url;
36+
const requestUrl = query ? `${url}?${encodeURI(query)}` : url;
3737
const response = await axios.default.request({
3838
url: requestUrl,
3939
method: convertHttpMethodToAxiosMethod(httpMethod),

examples/apis/sample-debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const apiClientImpl: ApiClient<RequestOption> = {
1515
options?: RequestOption,
1616
): Promise<any> => {
1717
const query = generateQueryString(queryParameters);
18-
const requestUrl = query ? url + "?" + encodeURI(query) : url;
18+
const requestUrl = query ? `${url}?${encodeURI(query)}` : url;
1919
console.log({
2020
httpMethod,
2121
url,

examples/apis/sample-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const apiClientImpl: ApiClient<RequestOption> = {
1717
options?: RequestOption,
1818
): Promise<any> => {
1919
const query = generateQueryString(queryParameters);
20-
const requestUrl = query ? url + "?" + encodeURI(query) : url;
20+
const requestUrl = query ? `${url}?${encodeURI(query)}` : url;
2121
const response = await fetch(requestUrl, {
2222
body: JSON.stringify(requestBody),
2323
headers,

examples/apis/sample-superagent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const apiClientImpl: ApiClient<RequestOption> = {
1919
options?: RequestOption,
2020
): Promise<any> => {
2121
const query = generateQueryString(queryParameters);
22-
const requestUrl = query ? url + "?" + encodeURI(query) : url;
22+
const requestUrl = query ? `${url}?${encodeURI(query)}` : url;
2323

2424
return new Promise((resolve, reject) => {
2525
const agent = Superagent;

examples/readme-sample/ast-code-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TsGenerator } from "@himenon/openapi-typescript-code-generator/dist/api";
22
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
33

4-
interface Option {}
4+
type Option = {};
55

66
const factory = TsGenerator.Factory.create();
77

examples/readme-sample/text-base-code-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface Option {
55
}
66

77
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[], option): string[] => {
8-
if (option && option.showLog) {
8+
if (option?.showLog) {
99
console.log("show log message");
1010
}
1111
return ["Hello world"];

examples/readme-sample/use-extract-schema-params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Types from "@himenon/openapi-typescript-code-generator/dist/types";
22

3-
interface Option {}
3+
type Option = {};
44

55
const generator: Types.CodeGenerator.GenerateFunction<Option> = (payload: Types.CodeGenerator.Params[]): string[] => {
66
return payload.map(params => {

jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
testEnvironment: "node",
99
extensionsToTreatAsEsm: [".ts", ".tsx"],
1010
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
11-
transformIgnorePatterns: [`/node_modules/(?!|dot-prop)`],
11+
transformIgnorePatterns: ["/node_modules/(?!|dot-prop)"],
1212
transform: {
1313
"^.+\\.(t|j)sx?$": "@swc/jest",
1414
},

jest.snapshot.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
testEnvironment: "node",
99
extensionsToTreatAsEsm: [".ts", ".tsx"],
1010
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
11-
transformIgnorePatterns: [`/node_modules/(?!|dot-prop)`],
11+
transformIgnorePatterns: ["/node_modules/(?!|dot-prop)"],
1212
transform: {
1313
"^.+\\.(t|j)sx?$": [
1414
"@swc/jest",

scripts/tools/shell.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execa, ExecaChildProcess } from "execa";
1+
import { ExecaChildProcess, execa } from "execa";
22

33
export const shell = (command: string, cwd: string = process.cwd()): ExecaChildProcess<string> => {
44
return execa(command, {

src/code-templates/_shared/ApiClientArgument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const createHeaders = (factory: TsGenerator.Factory.Type, { convertedParams }: C
6969
members.push(
7070
factory.PropertySignature.create({
7171
readOnly: false,
72-
name: `Accept`,
72+
name: "Accept",
7373
optional: false,
7474
type: factory.TypeReferenceNode.create({ name: "U" }),
7575
}),

src/code-templates/_shared/ApiClientInterface.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import ts from "typescript";
22

33
import type { TsGenerator } from "../../api";
44
import type { CodeGenerator } from "../../types";
5-
import type { Option } from "./types";
65
import type { MethodType } from "./MethodBody/types";
6+
import type { Option } from "./types";
77

88
const httpMethodList: string[] = ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
99

@@ -190,7 +190,7 @@ export const create = (
190190
}),
191191
});
192192

193-
const successResponseNames = list.map(item => item.convertedParams.responseSuccessNames).flat();
193+
const successResponseNames = list.flatMap(item => item.convertedParams.responseSuccessNames);
194194

195195
const errorResponseNamespace = factory.Namespace.create({
196196
export: true,
@@ -238,7 +238,7 @@ export const create = (
238238
name: "RequestArgs",
239239
members: [
240240
factory.PropertySignature.create({
241-
name: `httpMethod`,
241+
name: "httpMethod",
242242
readOnly: true,
243243
optional: false,
244244
type: factory.TypeReferenceNode.create({ name: "HttpMethod" }),
@@ -250,25 +250,25 @@ export const create = (
250250
type: factory.TypeReferenceNode.create({ name: "string" }),
251251
}),
252252
factory.PropertySignature.create({
253-
name: `headers`,
253+
name: "headers",
254254
readOnly: false,
255255
optional: false,
256256
type: objectLikeOrAnyType,
257257
}),
258258
factory.PropertySignature.create({
259-
name: `requestBody`,
259+
name: "requestBody",
260260
readOnly: false,
261261
optional: true,
262262
type: objectLikeOrAnyType,
263263
}),
264264
factory.PropertySignature.create({
265-
name: `requestBodyEncoding`,
265+
name: "requestBodyEncoding",
266266
readOnly: false,
267267
optional: true,
268268
type: factory.TypeReferenceNode.create({ name: "Record<string, Encoding>" }),
269269
}),
270270
factory.PropertySignature.create({
271-
name: `queryParameters`,
271+
name: "queryParameters",
272272
optional: true,
273273
readOnly: false,
274274
type: factory.UnionTypeNode.create({

src/code-templates/_shared/MethodBody/CallRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import ts from "typescript";
33
import type { TsGenerator } from "../../../api";
44
import type { CodeGenerator } from "../../../types";
55
import * as Utils from "../utils";
6-
import type { MethodType } from "./types";
76
import { createEncodingMap } from "./createEncodingMap";
7+
import type { MethodType } from "./types";
88

99
export interface Params {
1010
httpMethod: string;

src/code-templates/_shared/MethodBody/PathParameter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import ts from "typescript";
22

33
import type { TsGenerator } from "../../../api";
44
import type { CodeGenerator } from "../../../types";
5-
import * as Utils from "../utils";
65
import { escapeText2 as escapeText } from "../../../utils";
6+
import * as Utils from "../utils";
77
import type { MethodType } from "./types";
88

99
export const isPathParameter = (params: any): params is CodeGenerator.PickedParameter => {

src/code-templates/_shared/MethodBody/__tests__/PathParameter-test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,76 +45,76 @@ describe("PathParameter Test", () => {
4545
return getText(expression);
4646
};
4747
test("generateUrlTemplateExpression", () => {
48-
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toEqual("`/${params.parameter.a}`;" + EOL);
49-
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toEqual("`/${params.parameter.a}/`;" + EOL);
50-
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toEqual("`/a/${params.parameter.b}`;" + EOL);
51-
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toEqual("`/a/${params.parameter.b}/`;" + EOL);
52-
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toEqual("`/a/${params.parameter.b}/c`;" + EOL);
53-
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toEqual("`/a/${params.parameter.b}/c/`;" + EOL);
54-
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toEqual("`/a/b/${params.parameter.c}`;" + EOL);
55-
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toEqual("`/a/b/${params.parameter.c}`;" + EOL);
56-
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toEqual("`/a/b/${params.parameter.c}/`;" + EOL);
57-
expect(generate("/a/b/{c}.json", [{ in: "path", name: "c", required: true }])).toEqual("`/a/b/${params.parameter.c}.json`;" + EOL);
48+
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toEqual(`\`/\${params.parameter.a}\`;${EOL}`);
49+
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toEqual(`\`/\${params.parameter.a}/\`;${EOL}`);
50+
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toEqual(`\`/a/\${params.parameter.b}\`;${EOL}`);
51+
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toEqual(`\`/a/\${params.parameter.b}/\`;${EOL}`);
52+
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toEqual(`\`/a/\${params.parameter.b}/c\`;${EOL}`);
53+
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toEqual(`\`/a/\${params.parameter.b}/c/\`;${EOL}`);
54+
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toEqual(`\`/a/b/\${params.parameter.c}\`;${EOL}`);
55+
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toEqual(`\`/a/b/\${params.parameter.c}\`;${EOL}`);
56+
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toEqual(`\`/a/b/\${params.parameter.c}/\`;${EOL}`);
57+
expect(generate("/a/b/{c}.json", [{ in: "path", name: "c", required: true }])).toEqual(`\`/a/b/\${params.parameter.c}.json\`;${EOL}`);
5858
expect(generate("/{a}.json/{a}.json/{a}.json", [{ in: "path", name: "a", required: true }])).toEqual(
59-
"`/${params.parameter.a}.json/${params.parameter.a}.json/${params.parameter.a}.json`;" + EOL,
59+
`\`/\${params.parameter.a}.json/\${params.parameter.a}.json/\${params.parameter.a}.json\`;${EOL}`,
6060
);
6161
expect(generate("/.json.{a}.json/{a}.json.{a}", [{ in: "path", name: "a", required: true }])).toEqual(
62-
"`/.json.${params.parameter.a}.json/${params.parameter.a}.json.${params.parameter.a}`;" + EOL,
62+
`\`/.json.\${params.parameter.a}.json/\${params.parameter.a}.json.\${params.parameter.a}\`;${EOL}`,
6363
);
6464

6565
expect(
6666
generate("/{a}/{b}", [
6767
{ in: "path", name: "a", required: true },
6868
{ in: "path", name: "b", required: true },
6969
]),
70-
).toBe("`/${params.parameter.a}/${params.parameter.b}`;" + EOL);
70+
).toBe(`\`/\${params.parameter.a}/\${params.parameter.b}\`;${EOL}`);
7171
expect(
7272
generate("/{a}/{b}/", [
7373
{ in: "path", name: "a", required: true },
7474
{ in: "path", name: "b", required: true },
7575
]),
76-
).toBe("`/${params.parameter.a}/${params.parameter.b}/`;" + EOL);
76+
).toBe(`\`/\${params.parameter.a}/\${params.parameter.b}/\`;${EOL}`);
7777
expect(
7878
generate("/{a}/{b}/c", [
7979
{ in: "path", name: "a", required: true },
8080
{ in: "path", name: "b", required: true },
8181
]),
82-
).toBe("`/${params.parameter.a}/${params.parameter.b}/c`;" + EOL);
82+
).toBe(`\`/\${params.parameter.a}/\${params.parameter.b}/c\`;${EOL}`);
8383
expect(
8484
generate("/{a}/{b}/c/", [
8585
{ in: "path", name: "a", required: true },
8686
{ in: "path", name: "b", required: true },
8787
]),
88-
).toBe("`/${params.parameter.a}/${params.parameter.b}/c/`;" + EOL);
88+
).toBe(`\`/\${params.parameter.a}/\${params.parameter.b}/c/\`;${EOL}`);
8989
expect(
9090
generate("/{a}/b/{c}", [
9191
{ in: "path", name: "a", required: true },
9292
{ in: "path", name: "c", required: true },
9393
]),
94-
).toBe("`/${params.parameter.a}/b/${params.parameter.c}`;" + EOL);
94+
).toBe(`\`/\${params.parameter.a}/b/\${params.parameter.c}\`;${EOL}`);
9595
expect(
9696
generate("/{a}/b/{c}/", [
9797
{ in: "path", name: "a", required: true },
9898
{ in: "path", name: "c", required: true },
9999
]),
100-
).toBe("`/${params.parameter.a}/b/${params.parameter.c}/`;" + EOL);
100+
).toBe(`\`/\${params.parameter.a}/b/\${params.parameter.c}/\`;${EOL}`);
101101
expect(
102102
generate("/a/{b}/{c}", [
103103
{ in: "path", name: "b", required: true },
104104
{ in: "path", name: "c", required: true },
105105
]),
106-
).toBe("`/a/${params.parameter.b}/${params.parameter.c}`;" + EOL);
106+
).toBe(`\`/a/\${params.parameter.b}/\${params.parameter.c}\`;${EOL}`);
107107
expect(
108108
generate("/a/{b}/{c}/", [
109109
{ in: "path", name: "b", required: true },
110110
{ in: "path", name: "c", required: true },
111111
]),
112-
).toBe("`/a/${params.parameter.b}/${params.parameter.c}/`;" + EOL);
112+
).toBe(`\`/a/\${params.parameter.b}/\${params.parameter.c}/\`;${EOL}`);
113113
expect(
114114
generate("/a/{b}...{c}/", [
115115
{ in: "path", name: "b", required: true },
116116
{ in: "path", name: "c", required: true },
117117
]),
118-
).toBe("`/a/${params.parameter.b}...${params.parameter.c}/`;" + EOL);
118+
).toBe(`\`/a/\${params.parameter.b}...\${params.parameter.c}/\`;${EOL}`);
119119
});
120120
});

src/code-templates/_shared/MethodBody/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as CallRequest from "./CallRequest";
88
import * as HeaderParameter from "./HeaderParameter";
99
import * as PathParameter from "./PathParameter";
1010
import * as QueryParameter from "./QueryParameter";
11-
import type { MethodType } from "./types";
1211
import { createEncodingMap } from "./createEncodingMap";
12+
import type { MethodType } from "./types";
1313

1414
export const create = (factory: TsGenerator.Factory.Type, params: CodeGenerator.Params, methodType: MethodType): ts.Statement[] => {
1515
const statements: ts.Statement[] = [];
@@ -27,7 +27,7 @@ export const create = (factory: TsGenerator.Factory.Type, params: CodeGenerator.
2727
if (convertedParams.has2OrMoreRequestContentTypes) {
2828
initialHeaderObject["Content-Type"] = {
2929
type: "variable",
30-
value: `params.headers.Content-Type`,
30+
value: "params.headers.Content-Type",
3131
};
3232
} else if (convertedParams.requestFirstContentType) {
3333
initialHeaderObject["Content-Type"] = {
@@ -36,12 +36,12 @@ export const create = (factory: TsGenerator.Factory.Type, params: CodeGenerator.
3636
};
3737
}
3838
if (convertedParams.has2OrMoreSuccessResponseContentTypes) {
39-
initialHeaderObject["Accept"] = {
39+
initialHeaderObject.Accept = {
4040
type: "variable",
41-
value: `params.headers.Accept`,
41+
value: "params.headers.Accept",
4242
};
4343
} else if (convertedParams.successResponseFirstContentType) {
44-
initialHeaderObject["Accept"] = {
44+
initialHeaderObject.Accept = {
4545
type: "string",
4646
value: convertedParams.successResponseFirstContentType,
4747
};

0 commit comments

Comments
 (0)