Skip to content

Commit d9b6f8f

Browse files
committed
Fix more formatting issues
1 parent 2154aa4 commit d9b6f8f

2 files changed

Lines changed: 63 additions & 101 deletions

File tree

code-generator/src/definitions.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ const generateField = (f: Field, modelName: string) => {
4444
}
4545
if (f.name.includes("-")) {
4646
p += ` @SerializedName("${f.name}")\n`;
47-
f.name = f.name.replace(
48-
/-([a-z])/g,
49-
(_match, p1: string) => p1.toUpperCase(),
47+
f.name = f.name.replace(/-([a-z])/g, (_match, p1: string) =>
48+
p1.toUpperCase(),
5049
);
5150
}
5251
if (f.name.includes(":")) {
@@ -83,12 +82,10 @@ const generateField = (f: Field, modelName: string) => {
8382
p = ` * Required\n ${p}`;
8483
}
8584
if (f.description) {
86-
p = ` * ${
87-
escapeJavaDoc(f.description)
88-
?.trim()
89-
.split("\n")
90-
.join("\n * ")
91-
}\n ${p}`;
85+
p = ` * ${escapeJavaDoc(f.description)
86+
?.trim()
87+
.split("\n")
88+
.join("\n * ")}\n ${p}`;
9289
}
9390
p = `/**\n ${p}`;
9491
return p;

code-generator/src/paths.ts

Lines changed: 57 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const generatePathMethod = (
2020
if (withParameter && ${parameter} != null)
2121
{
2222
return ${
23-
hasParent ? "parent.path()" : '""'
24-
} + "/${token}/" + ${parameter};
23+
hasParent ? "parent.path()" : '""'
24+
} + "/${token}/" + ${parameter};
2525
}
2626
return ${hasParent ? "parent.path()" : '""'} + "/${token}";
2727
}
@@ -58,33 +58,27 @@ const generateConstructor = (
5858
const result = ["public RestClient rc;"];
5959
if (parentPaths.length > 0) {
6060
result.push(
61-
`public com.ringcentral.paths.${
62-
parentPaths
63-
.join(".")
64-
.toLowerCase()
65-
}.Index parent;`,
61+
`public com.ringcentral.paths.${parentPaths
62+
.join(".")
63+
.toLowerCase()}.Index parent;`,
6664
);
6765
}
6866
if (parameter) {
6967
result.push(`public String ${parameter};`);
7068
}
7169
if (parentPaths.length > 0) {
7270
if (defaultValue) {
73-
result.push(`public Index(com.ringcentral.paths.${
74-
parentPaths
75-
.join(".")
76-
.toLowerCase()
77-
}.Index parent)
71+
result.push(`public Index(com.ringcentral.paths.${parentPaths
72+
.join(".")
73+
.toLowerCase()}.Index parent)
7874
{
7975
this(parent, "${defaultValue}");
8076
}`);
8177
}
8278
result.push(
83-
`public Index(com.ringcentral.paths.${
84-
parentPaths
85-
.join(".")
86-
.toLowerCase()
87-
}.Index parent${parameter ? `, String ${parameter}` : ""})
79+
`public Index(com.ringcentral.paths.${parentPaths
80+
.join(".")
81+
.toLowerCase()}.Index parent${parameter ? `, String ${parameter}` : ""})
8882
{`,
8983
);
9084
result.push("this.parent = parent;");
@@ -117,16 +111,14 @@ const generateOperationMethod = (
117111
// comments
118112
const comments = ["/**"];
119113
comments.push(
120-
`${
121-
(
122-
operation.description ||
123-
operation.summary ||
124-
capitalCase(operation.operationId)
125-
)
126-
.split("\n")
127-
.map((l) => ` * ${escapeJavaDoc(l)}`)
128-
.join("\n")
129-
}`,
114+
`${(
115+
operation.description ||
116+
operation.summary ||
117+
capitalCase(operation.operationId)
118+
)
119+
.split("\n")
120+
.map((l) => ` * ${escapeJavaDoc(l)}`)
121+
.join("\n")}`,
130122
);
131123
comments.push(` * HTTP Method: ${operation.method}`);
132124
comments.push(` * Endpoint: ${operation.endpoint}`);
@@ -160,19 +152,15 @@ const generateOperationMethod = (
160152
if (operation.bodyParameters) {
161153
if (operation.bodyType) {
162154
methodParams.push(
163-
`${
164-
capitalizeFirstLetter(
165-
operation.bodyType,
166-
)
167-
} ${operation.bodyParameters}`,
155+
`${capitalizeFirstLetter(
156+
operation.bodyType,
157+
)} ${operation.bodyParameters}`,
168158
);
169159
} else {
170160
methodParams.push(
171-
`${
172-
capitalizeFirstLetter(
173-
operation.bodyParameters,
174-
)
175-
} ${operation.bodyParameters}`,
161+
`${capitalizeFirstLetter(
162+
operation.bodyParameters,
163+
)} ${operation.bodyParameters}`,
176164
);
177165
}
178166
}
@@ -200,49 +188,40 @@ const generateOperationMethod = (
200188

201189
// result
202190
result += `
203-
public ${responseType} ${operation.method2}(${
204-
methodParams.join(
205-
", ",
206-
)
207-
}) throws com.ringcentral.RestException, java.io.IOException
191+
public ${responseType} ${operation.method2}(${methodParams.join(
192+
", ",
193+
)}) throws com.ringcentral.RestException, java.io.IOException
208194
{\n`;
209195
if (operation.withParameter) {
210196
result += ` if (${parameter} == null)
211197
{
212198
throw new IllegalArgumentException("Parameter ${parameter} cannot be null");
213199
}\n`;
214200
}
215-
result += ` okhttp3.ResponseBody rb = this.rc.${operation.method}(${
216-
requestParams.join(
217-
", ",
218-
)
219-
});`;
201+
result += ` okhttp3.ResponseBody rb = this.rc.${operation.method}(${requestParams.join(
202+
", ",
203+
)});`;
220204
if (responseType === "String") {
221205
result += "\n return rb.string();";
222206
} else if (responseType === "byte[]") {
223207
result += "\n return rb.bytes();";
224208
} else {
225-
result +=
226-
`\n return com.ringcentral.Utils.gson.fromJson(rb.string(), ${responseType}.class);`;
209+
result += `\n return com.ringcentral.Utils.gson.fromJson(rb.string(), ${responseType}.class);`;
227210
}
228211
result += "\n }";
229212

230213
// overloading
231214
if (operation.queryParameters) {
232215
methodParams.pop();
233216
result += `
234-
public ${responseType} ${operation.method2}(${
235-
methodParams.join(
236-
", ",
237-
)
238-
}) throws com.ringcentral.RestException, java.io.IOException
217+
public ${responseType} ${operation.method2}(${methodParams.join(
218+
", ",
219+
)}) throws com.ringcentral.RestException, java.io.IOException
239220
{
240-
return this.${operation.method2}(${
241-
[
221+
return this.${operation.method2}(${[
242222
...methodParams.map((mp) => R.last(mp.split(" "))),
243223
"null",
244-
].join(", ")
245-
});
224+
].join(", ")});
246225
}`;
247226
}
248227

@@ -266,38 +245,30 @@ for (const item of parsed.paths) {
266245
continue;
267246
}
268247
const code = `
269-
package com.ringcentral.paths.${
270-
itemPaths
271-
.join(".")
272-
.replace(/-/g, "")
273-
.toLowerCase()
274-
};
248+
package com.ringcentral.paths.${itemPaths
249+
.join(".")
250+
.replace(/-/g, "")
251+
.toLowerCase()};
275252
276253
import com.ringcentral.*;
277254
import com.ringcentral.definitions.*;
278255
279256
public class Index
280257
{
281-
${
282-
generateConstructor(
258+
${generateConstructor(
283259
item.parameter,
284260
item.defaultParameter,
285261
R.init(itemPaths),
286-
)
287-
}
288-
${
289-
generatePathMethod(
262+
)}
263+
${generatePathMethod(
290264
item.parameter,
291265
lastPath,
292266
itemPaths.length > 1,
293267
item.noParentParameter,
294-
)
295-
}
296-
${
297-
item.operations
298-
.map((operation) => generateOperationMethod(operation, item.parameter))
299-
.join("\n\n")
300-
}
268+
)}
269+
${item.operations
270+
.map((operation) => generateOperationMethod(operation, item.parameter))
271+
.join("\n\n")}
301272
}
302273
`;
303274
const folder = path.join(outputDir, ...itemPaths).toLowerCase();
@@ -306,27 +277,21 @@ ${
306277

307278
// bridge methods
308279
if (item.paths.length > 1) {
309-
let code = ` public com.ringcentral.paths.${
310-
itemPaths
311-
.join(".")
312-
.toLowerCase()
313-
}.Index ${camelCase(lastItemPath)}(${
280+
let code = ` public com.ringcentral.paths.${itemPaths
281+
.join(".")
282+
.toLowerCase()}.Index ${camelCase(lastItemPath)}(${
314283
item.parameter ? `String ${item.parameter}` : ""
315284
})
316285
{
317-
return new com.ringcentral.paths.${
318-
itemPaths
319-
.join(".")
320-
.toLowerCase()
321-
}.Index(this${item.parameter ? `, ${item.parameter}` : ""});
286+
return new com.ringcentral.paths.${itemPaths
287+
.join(".")
288+
.toLowerCase()}.Index(this${item.parameter ? `, ${item.parameter}` : ""});
322289
}
323290
`;
324291
if (item.parameter) {
325-
code = `public com.ringcentral.paths.${
326-
itemPaths
327-
.join(".")
328-
.toLowerCase()
329-
}.Index ${camelCase(lastItemPath)}()
292+
code = `public com.ringcentral.paths.${itemPaths
293+
.join(".")
294+
.toLowerCase()}.Index ${camelCase(lastItemPath)}()
330295
{
331296
return this.${camelCase(lastItemPath)}(${
332297
item.defaultParameter ? `"${item.defaultParameter}"` : "null"

0 commit comments

Comments
 (0)