@accelbyte/codegen 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -114,7 +114,7 @@ ${generateImports(body, importStatements, makeNewImportVarMap$1(), getImportable
|
|
|
114
114
|
|
|
115
115
|
export class ${className} {
|
|
116
116
|
// @ts-ignore
|
|
117
|
-
constructor(private axiosInstance: AxiosInstance, private namespace: string, private cache = false) {}
|
|
117
|
+
constructor(private axiosInstance: AxiosInstance, private namespace: string, private cache = false, private isValidationEnabled = true) {}
|
|
118
118
|
${body}
|
|
119
119
|
}
|
|
120
120
|
`;
|
|
@@ -139,6 +139,7 @@ export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
|
|
|
139
139
|
const namespace = args?.namespace ? args?.namespace : sdkAssembly.namespace
|
|
140
140
|
const cache = args?.cache ? args?.cache : sdkAssembly.cache
|
|
141
141
|
const requestConfig = ApiUtils.mergedConfigs(sdkAssembly.config, args)
|
|
142
|
+
const isValidationEnabled = args?.isValidationEnabled !== false
|
|
142
143
|
${body}
|
|
143
144
|
|
|
144
145
|
return {
|
|
@@ -1059,7 +1060,8 @@ const templateMethod = ({
|
|
|
1059
1060
|
bodyParams,
|
|
1060
1061
|
queryParams,
|
|
1061
1062
|
isFormUrlEncoded,
|
|
1062
|
-
responseClass
|
|
1063
|
+
responseClass,
|
|
1064
|
+
deprecated
|
|
1063
1065
|
}) => {
|
|
1064
1066
|
let methodParams = "";
|
|
1065
1067
|
let methodParamsNoTypes = "";
|
|
@@ -1095,7 +1097,7 @@ const templateMethod = ({
|
|
|
1095
1097
|
const isDelete = ["delete"].includes(httpMethod);
|
|
1096
1098
|
let dataPayload = "{params}";
|
|
1097
1099
|
const descriptionText = description ? `
|
|
1098
|
-
|
|
1100
|
+
/**${deprecated ? "\n * @deprecated" : ""}
|
|
1099
1101
|
* ${description.replace(/\n/g, "\n * ")}
|
|
1100
1102
|
*/` : "";
|
|
1101
1103
|
let formPayloadString = "";
|
|
@@ -1130,13 +1132,13 @@ const templateMethod = ({
|
|
|
1130
1132
|
const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
|
|
1131
1133
|
const resultPromise = this.axiosInstance.${httpMethod}(url, ${dataPayload})
|
|
1132
1134
|
|
|
1133
|
-
${httpMethod === "get" ? ` const res = () => Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')
|
|
1135
|
+
${httpMethod === "get" ? ` const res = () => this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)
|
|
1134
1136
|
|
|
1135
1137
|
if (!this.cache) {
|
|
1136
1138
|
return SdkCache.withoutCache(res)
|
|
1137
1139
|
}
|
|
1138
1140
|
const cacheKey = url + CodeGenUtil.hashCode(JSON.stringify({ params }))
|
|
1139
|
-
return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')` : ""}
|
|
1141
|
+
return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)` : ""}
|
|
1140
1142
|
}
|
|
1141
1143
|
`;
|
|
1142
1144
|
if (!isGuardInvoked) {
|
|
@@ -1168,7 +1170,8 @@ const templateApiMethod = ({
|
|
|
1168
1170
|
responseClass,
|
|
1169
1171
|
classGenName,
|
|
1170
1172
|
methodParams,
|
|
1171
|
-
methodParamsNoTypes
|
|
1173
|
+
methodParamsNoTypes,
|
|
1174
|
+
deprecated
|
|
1172
1175
|
}) => {
|
|
1173
1176
|
let methodSignature = "";
|
|
1174
1177
|
let newPath = `'${path}'`;
|
|
@@ -1199,7 +1202,7 @@ const templateApiMethod = ({
|
|
|
1199
1202
|
--data-raw '{ ${curlParams}}'`;
|
|
1200
1203
|
}
|
|
1201
1204
|
const descriptionText = description ? `
|
|
1202
|
-
|
|
1205
|
+
/**${deprecated ? "\n * @deprecated" : ""}
|
|
1203
1206
|
* ${description.replace(/\n/g, "\n * ")}
|
|
1204
1207
|
*/` : "";
|
|
1205
1208
|
const resolvedResponseClass = responseClass || "unknown";
|
|
@@ -1207,7 +1210,7 @@ const templateApiMethod = ({
|
|
|
1207
1210
|
const methodImpl = `
|
|
1208
1211
|
${descriptionText}
|
|
1209
1212
|
async function ${classMethod}(${methodParams}): Promise<${responseType}> {
|
|
1210
|
-
const $ = new ${classGenName}(Network.create(requestConfig), namespace, cache)
|
|
1213
|
+
const $ = new ${classGenName}(Network.create(requestConfig), namespace, cache, isValidationEnabled)
|
|
1211
1214
|
const resp = await $.${classMethod}(${methodParamsNoTypes})
|
|
1212
1215
|
if (resp.error) throw resp.error
|
|
1213
1216
|
return resp.response.data
|
|
@@ -1320,7 +1323,7 @@ class SwaggerReaderHelpers {
|
|
|
1320
1323
|
console.error(JSON.stringify({ path, httpMethod }, null, 2));
|
|
1321
1324
|
throw error;
|
|
1322
1325
|
});
|
|
1323
|
-
if (!endpoint.tags
|
|
1326
|
+
if (!endpoint.tags)
|
|
1324
1327
|
continue;
|
|
1325
1328
|
const [tag] = endpoint.tags;
|
|
1326
1329
|
const pathWithBase = `${api.basePath ?? ""}${path}`;
|
|
@@ -1352,6 +1355,7 @@ class SwaggerReaderHelpers {
|
|
|
1352
1355
|
const isFormUrlEncoded = ParserUtils.isFormUrlEncoded(httpMethod, endpoint.consumes);
|
|
1353
1356
|
const pathParams = ParserUtils.filterPathParams(endpoint.parameters);
|
|
1354
1357
|
let bodyParams = ParserUtils.filterBodyParams(endpoint.parameters);
|
|
1358
|
+
const deprecated = !!endpoint.deprecated;
|
|
1355
1359
|
if (endpoint.requestBody) {
|
|
1356
1360
|
bodyParams = [
|
|
1357
1361
|
{
|
|
@@ -1370,7 +1374,8 @@ class SwaggerReaderHelpers {
|
|
|
1370
1374
|
bodyParams,
|
|
1371
1375
|
queryParams,
|
|
1372
1376
|
isFormUrlEncoded,
|
|
1373
|
-
responseClass
|
|
1377
|
+
responseClass,
|
|
1378
|
+
deprecated
|
|
1374
1379
|
});
|
|
1375
1380
|
tagToEndpointClassesRecord[tag] = (tagToEndpointClassesRecord[tag] || "") + methodImpl;
|
|
1376
1381
|
const [generatedMethodString, snippetMethod, snippetShell] = templateApiMethod({
|
|
@@ -1383,7 +1388,8 @@ class SwaggerReaderHelpers {
|
|
|
1383
1388
|
responseClass,
|
|
1384
1389
|
classGenName,
|
|
1385
1390
|
methodParams,
|
|
1386
|
-
methodParamsNoTypes
|
|
1391
|
+
methodParamsNoTypes,
|
|
1392
|
+
deprecated
|
|
1387
1393
|
});
|
|
1388
1394
|
tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
|
|
1389
1395
|
tagToSdkFunctionNamesRecord[tag] = (tagToSdkFunctionNamesRecord[tag] || "") + classMethod + ",";
|
|
@@ -1393,10 +1399,9 @@ class SwaggerReaderHelpers {
|
|
|
1393
1399
|
const resultSnippet = templateSdkSnippet(serviceNameTitle, apiGenName, snippetMethod);
|
|
1394
1400
|
const currentSnippetMap = {};
|
|
1395
1401
|
snippetMap[pathWithBase][httpMethod] = currentSnippetMap;
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1402
|
+
currentSnippetMap.web = resultSnippet;
|
|
1403
|
+
const generatedDirName = isAdminEndpoint ? "generated-admin" : "generated-public";
|
|
1404
|
+
currentSnippetMap.webGit = GIT_URL + `/sdk-${sdkName}/src/${generatedDirName}/${apiGenName}.ts`;
|
|
1400
1405
|
currentSnippetMap.shell = snippetShell;
|
|
1401
1406
|
}
|
|
1402
1407
|
}
|