@accelbyte/codegen 2.1.0-experimental.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.
@@ -91,7 +91,7 @@ ${generateImports(body, importStatements, makeNewImportVarMap$1(), getImportable
91
91
 
92
92
  export class ${className} {
93
93
  // @ts-ignore
94
- constructor(private axiosInstance: AxiosInstance, private namespace: string, private cache = false) {}
94
+ constructor(private axiosInstance: AxiosInstance, private namespace: string, private cache = false, private isValidationEnabled = true) {}
95
95
  ${body}
96
96
  }
97
97
  `;
@@ -116,6 +116,7 @@ export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
116
116
  const namespace = args?.namespace ? args?.namespace : sdkAssembly.namespace
117
117
  const cache = args?.cache ? args?.cache : sdkAssembly.cache
118
118
  const requestConfig = ApiUtils.mergedConfigs(sdkAssembly.config, args)
119
+ const isValidationEnabled = args?.isValidationEnabled !== false
119
120
  ${body}
120
121
 
121
122
  return {
@@ -1036,7 +1037,8 @@ const templateMethod = ({
1036
1037
  bodyParams,
1037
1038
  queryParams,
1038
1039
  isFormUrlEncoded,
1039
- responseClass
1040
+ responseClass,
1041
+ deprecated
1040
1042
  }) => {
1041
1043
  let methodParams = "";
1042
1044
  let methodParamsNoTypes = "";
@@ -1072,7 +1074,7 @@ const templateMethod = ({
1072
1074
  const isDelete = ["delete"].includes(httpMethod);
1073
1075
  let dataPayload = "{params}";
1074
1076
  const descriptionText = description ? `
1075
- /**
1077
+ /**${deprecated ? "\n * @deprecated" : ""}
1076
1078
  * ${description.replace(/\n/g, "\n * ")}
1077
1079
  */` : "";
1078
1080
  let formPayloadString = "";
@@ -1107,13 +1109,13 @@ const templateMethod = ({
1107
1109
  const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
1108
1110
  const resultPromise = this.axiosInstance.${httpMethod}(url, ${dataPayload})
1109
1111
 
1110
- ${httpMethod === "get" ? ` const res = () => Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')
1112
+ ${httpMethod === "get" ? ` const res = () => this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)
1111
1113
 
1112
1114
  if (!this.cache) {
1113
1115
  return SdkCache.withoutCache(res)
1114
1116
  }
1115
1117
  const cacheKey = url + CodeGenUtil.hashCode(JSON.stringify({ params }))
1116
- return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}')` : ""}
1118
+ return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)` : ""}
1117
1119
  }
1118
1120
  `;
1119
1121
  if (!isGuardInvoked) {
@@ -1145,7 +1147,8 @@ const templateApiMethod = ({
1145
1147
  responseClass,
1146
1148
  classGenName,
1147
1149
  methodParams,
1148
- methodParamsNoTypes
1150
+ methodParamsNoTypes,
1151
+ deprecated
1149
1152
  }) => {
1150
1153
  let methodSignature = "";
1151
1154
  let newPath = `'${path}'`;
@@ -1176,7 +1179,7 @@ const templateApiMethod = ({
1176
1179
  --data-raw '{ ${curlParams}}'`;
1177
1180
  }
1178
1181
  const descriptionText = description ? `
1179
- /**
1182
+ /**${deprecated ? "\n * @deprecated" : ""}
1180
1183
  * ${description.replace(/\n/g, "\n * ")}
1181
1184
  */` : "";
1182
1185
  const resolvedResponseClass = responseClass || "unknown";
@@ -1184,7 +1187,7 @@ const templateApiMethod = ({
1184
1187
  const methodImpl = `
1185
1188
  ${descriptionText}
1186
1189
  async function ${classMethod}(${methodParams}): Promise<${responseType}> {
1187
- const $ = new ${classGenName}(Network.create(requestConfig), namespace, cache)
1190
+ const $ = new ${classGenName}(Network.create(requestConfig), namespace, cache, isValidationEnabled)
1188
1191
  const resp = await $.${classMethod}(${methodParamsNoTypes})
1189
1192
  if (resp.error) throw resp.error
1190
1193
  return resp.response.data
@@ -1297,7 +1300,7 @@ class SwaggerReaderHelpers {
1297
1300
  console.error(JSON.stringify({ path, httpMethod }, null, 2));
1298
1301
  throw error;
1299
1302
  });
1300
- if (!endpoint.tags || endpoint.deprecated)
1303
+ if (!endpoint.tags)
1301
1304
  continue;
1302
1305
  const [tag] = endpoint.tags;
1303
1306
  const pathWithBase = `${api.basePath ?? ""}${path}`;
@@ -1329,6 +1332,7 @@ class SwaggerReaderHelpers {
1329
1332
  const isFormUrlEncoded = ParserUtils.isFormUrlEncoded(httpMethod, endpoint.consumes);
1330
1333
  const pathParams = ParserUtils.filterPathParams(endpoint.parameters);
1331
1334
  let bodyParams = ParserUtils.filterBodyParams(endpoint.parameters);
1335
+ const deprecated = !!endpoint.deprecated;
1332
1336
  if (endpoint.requestBody) {
1333
1337
  bodyParams = [
1334
1338
  {
@@ -1347,7 +1351,8 @@ class SwaggerReaderHelpers {
1347
1351
  bodyParams,
1348
1352
  queryParams,
1349
1353
  isFormUrlEncoded,
1350
- responseClass
1354
+ responseClass,
1355
+ deprecated
1351
1356
  });
1352
1357
  tagToEndpointClassesRecord[tag] = (tagToEndpointClassesRecord[tag] || "") + methodImpl;
1353
1358
  const [generatedMethodString, snippetMethod, snippetShell] = templateApiMethod({
@@ -1360,7 +1365,8 @@ class SwaggerReaderHelpers {
1360
1365
  responseClass,
1361
1366
  classGenName,
1362
1367
  methodParams,
1363
- methodParamsNoTypes
1368
+ methodParamsNoTypes,
1369
+ deprecated
1364
1370
  });
1365
1371
  tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
1366
1372
  tagToSdkFunctionNamesRecord[tag] = (tagToSdkFunctionNamesRecord[tag] || "") + classMethod + ",";
@@ -1370,10 +1376,9 @@ class SwaggerReaderHelpers {
1370
1376
  const resultSnippet = templateSdkSnippet(serviceNameTitle, apiGenName, snippetMethod);
1371
1377
  const currentSnippetMap = {};
1372
1378
  snippetMap[pathWithBase][httpMethod] = currentSnippetMap;
1373
- if (!isAdminEndpoint) {
1374
- currentSnippetMap.web = !isAdminEndpoint ? resultSnippet : "";
1375
- currentSnippetMap.webGit = !isAdminEndpoint ? GIT_URL + `/sdk-${sdkName}/src/generated-public/${serviceName}/${apiGenName}.ts` : "";
1376
- }
1379
+ currentSnippetMap.web = resultSnippet;
1380
+ const generatedDirName = isAdminEndpoint ? "generated-admin" : "generated-public";
1381
+ currentSnippetMap.webGit = GIT_URL + `/sdk-${sdkName}/src/${generatedDirName}/${apiGenName}.ts`;
1377
1382
  currentSnippetMap.shell = snippetShell;
1378
1383
  }
1379
1384
  }