ng-openapi 0.0.25-alpha.4 → 0.0.25-alpha.5
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.
- package/cli.cjs +84 -10
- package/index.js +84 -10
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -425,12 +425,14 @@ var TokenGenerator = class {
|
|
|
425
425
|
});
|
|
426
426
|
sourceFile.addImportDeclaration({
|
|
427
427
|
namedImports: [
|
|
428
|
-
"HttpInterceptor"
|
|
428
|
+
"HttpInterceptor",
|
|
429
|
+
"HttpContextToken"
|
|
429
430
|
],
|
|
430
431
|
moduleSpecifier: "@angular/common/http"
|
|
431
432
|
});
|
|
432
433
|
const basePathTokenName = this.getBasePathTokenName();
|
|
433
434
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
435
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
434
436
|
sourceFile.addVariableStatement({
|
|
435
437
|
isExported: true,
|
|
436
438
|
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
@@ -463,6 +465,20 @@ var TokenGenerator = class {
|
|
|
463
465
|
leadingTrivia: `/**
|
|
464
466
|
* Injection token for the ${this.clientName} client HTTP interceptor instances
|
|
465
467
|
*/
|
|
468
|
+
`
|
|
469
|
+
});
|
|
470
|
+
sourceFile.addVariableStatement({
|
|
471
|
+
isExported: true,
|
|
472
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
473
|
+
declarations: [
|
|
474
|
+
{
|
|
475
|
+
name: clientContextTokenName,
|
|
476
|
+
initializer: `new HttpContextToken<string>(() => '${this.clientName}')`
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
leadingTrivia: `/**
|
|
480
|
+
* HttpContext token to identify requests belonging to the ${this.clientName} client
|
|
481
|
+
*/
|
|
466
482
|
`
|
|
467
483
|
});
|
|
468
484
|
if (this.clientName === "default") {
|
|
@@ -478,6 +494,20 @@ var TokenGenerator = class {
|
|
|
478
494
|
leadingTrivia: `/**
|
|
479
495
|
* @deprecated Use ${basePathTokenName} instead
|
|
480
496
|
*/
|
|
497
|
+
`
|
|
498
|
+
});
|
|
499
|
+
sourceFile.addVariableStatement({
|
|
500
|
+
isExported: true,
|
|
501
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
502
|
+
declarations: [
|
|
503
|
+
{
|
|
504
|
+
name: "CLIENT_CONTEXT_TOKEN",
|
|
505
|
+
initializer: clientContextTokenName
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
leadingTrivia: `/**
|
|
509
|
+
* @deprecated Use ${clientContextTokenName} instead
|
|
510
|
+
*/
|
|
481
511
|
`
|
|
482
512
|
});
|
|
483
513
|
}
|
|
@@ -491,6 +521,10 @@ var TokenGenerator = class {
|
|
|
491
521
|
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
492
522
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
493
523
|
}
|
|
524
|
+
getClientContextTokenName() {
|
|
525
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
526
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
527
|
+
}
|
|
494
528
|
};
|
|
495
529
|
|
|
496
530
|
// src/lib/generators/utility/file-download.generator.ts
|
|
@@ -1040,6 +1074,7 @@ var BaseInterceptorGenerator = class {
|
|
|
1040
1074
|
sourceFile.insertText(0, BASE_INTERCEPTOR_HEADER_COMMENT(this.#clientName));
|
|
1041
1075
|
const basePathTokenName = this.getBasePathTokenName();
|
|
1042
1076
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1077
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
1043
1078
|
sourceFile.addImportDeclarations([
|
|
1044
1079
|
{
|
|
1045
1080
|
namedImports: [
|
|
@@ -1066,7 +1101,8 @@ var BaseInterceptorGenerator = class {
|
|
|
1066
1101
|
{
|
|
1067
1102
|
namedImports: [
|
|
1068
1103
|
basePathTokenName,
|
|
1069
|
-
interceptorsTokenName
|
|
1104
|
+
interceptorsTokenName,
|
|
1105
|
+
clientContextTokenName
|
|
1070
1106
|
],
|
|
1071
1107
|
moduleSpecifier: "../tokens"
|
|
1072
1108
|
}
|
|
@@ -1085,11 +1121,11 @@ var BaseInterceptorGenerator = class {
|
|
|
1085
1121
|
],
|
|
1086
1122
|
properties: [
|
|
1087
1123
|
{
|
|
1088
|
-
name: "
|
|
1124
|
+
name: "clientName",
|
|
1089
1125
|
type: "string",
|
|
1090
1126
|
scope: import_ts_morph3.Scope.Private,
|
|
1091
1127
|
isReadonly: true,
|
|
1092
|
-
initializer: `
|
|
1128
|
+
initializer: `'${this.#clientName}'`
|
|
1093
1129
|
},
|
|
1094
1130
|
{
|
|
1095
1131
|
name: "httpInterceptors",
|
|
@@ -1097,6 +1133,13 @@ var BaseInterceptorGenerator = class {
|
|
|
1097
1133
|
scope: import_ts_morph3.Scope.Private,
|
|
1098
1134
|
isReadonly: true,
|
|
1099
1135
|
initializer: `inject(${interceptorsTokenName})`
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
name: "clientContextToken",
|
|
1139
|
+
type: "any",
|
|
1140
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1141
|
+
isReadonly: true,
|
|
1142
|
+
initializer: clientContextTokenName
|
|
1100
1143
|
}
|
|
1101
1144
|
],
|
|
1102
1145
|
methods: [
|
|
@@ -1114,8 +1157,11 @@ var BaseInterceptorGenerator = class {
|
|
|
1114
1157
|
],
|
|
1115
1158
|
returnType: "Observable<HttpEvent<any>>",
|
|
1116
1159
|
statements: `
|
|
1117
|
-
//
|
|
1118
|
-
|
|
1160
|
+
// Check if this request belongs to this client using HttpContext
|
|
1161
|
+
const requestClientName = req.context.get(this.clientContextToken);
|
|
1162
|
+
|
|
1163
|
+
if (requestClientName !== this.clientName) {
|
|
1164
|
+
// This request doesn't belong to this client, pass it through
|
|
1119
1165
|
return next.handle(req);
|
|
1120
1166
|
}
|
|
1121
1167
|
|
|
@@ -1143,6 +1189,10 @@ var BaseInterceptorGenerator = class {
|
|
|
1143
1189
|
const clientSuffix = this.#clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1144
1190
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1145
1191
|
}
|
|
1192
|
+
getClientContextTokenName() {
|
|
1193
|
+
const clientSuffix = this.#clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1194
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
1195
|
+
}
|
|
1146
1196
|
capitalizeFirst(str) {
|
|
1147
1197
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1148
1198
|
}
|
|
@@ -1245,6 +1295,7 @@ var ServiceMethodBodyGenerator = class {
|
|
|
1245
1295
|
this.generateQueryParams(context),
|
|
1246
1296
|
this.generateHeaders(context),
|
|
1247
1297
|
this.generateMultipartFormData(operation, context),
|
|
1298
|
+
this.generateContextHelper(),
|
|
1248
1299
|
this.generateRequestOptions(context),
|
|
1249
1300
|
this.generateHttpRequest(operation, context)
|
|
1250
1301
|
];
|
|
@@ -1439,9 +1490,7 @@ ${formDataAppends}`;
|
|
|
1439
1490
|
}
|
|
1440
1491
|
options.push("reportProgress: options?.reportProgress");
|
|
1441
1492
|
options.push("withCredentials: options?.withCredentials");
|
|
1442
|
-
|
|
1443
|
-
options.push("context: options?.context");
|
|
1444
|
-
}
|
|
1493
|
+
options.push("context: this.createContextWithClientId(options?.context)");
|
|
1445
1494
|
const formattedOptions = options.filter((opt) => opt && !opt.includes("undefined")).join(",\n ");
|
|
1446
1495
|
return `
|
|
1447
1496
|
const requestOptions: any = {
|
|
@@ -1533,6 +1582,16 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
|
|
|
1533
1582
|
}
|
|
1534
1583
|
return "blob";
|
|
1535
1584
|
}
|
|
1585
|
+
generateContextHelper() {
|
|
1586
|
+
return `
|
|
1587
|
+
/**
|
|
1588
|
+
* Creates HttpContext with client identification
|
|
1589
|
+
*/
|
|
1590
|
+
private createContextWithClientId(existingContext?: HttpContext): HttpContext {
|
|
1591
|
+
const context = existingContext || new HttpContext();
|
|
1592
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');
|
|
1593
|
+
}`;
|
|
1594
|
+
}
|
|
1536
1595
|
};
|
|
1537
1596
|
|
|
1538
1597
|
// src/lib/generators/service/service-method/service-method-params.generator.ts
|
|
@@ -2094,6 +2153,7 @@ var ServiceGenerator = class {
|
|
|
2094
2153
|
}
|
|
2095
2154
|
addImports(sourceFile, usedTypes) {
|
|
2096
2155
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2156
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2097
2157
|
sourceFile.addImportDeclarations([
|
|
2098
2158
|
{
|
|
2099
2159
|
namedImports: [
|
|
@@ -2121,7 +2181,8 @@ var ServiceGenerator = class {
|
|
|
2121
2181
|
},
|
|
2122
2182
|
{
|
|
2123
2183
|
namedImports: [
|
|
2124
|
-
basePathTokenName
|
|
2184
|
+
basePathTokenName,
|
|
2185
|
+
clientContextTokenName
|
|
2125
2186
|
],
|
|
2126
2187
|
moduleSpecifier: "../tokens"
|
|
2127
2188
|
}
|
|
@@ -2136,6 +2197,7 @@ var ServiceGenerator = class {
|
|
|
2136
2197
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2137
2198
|
const className = `${controllerName}Service`;
|
|
2138
2199
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2200
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2139
2201
|
sourceFile.insertText(0, SERVICE_GENERATOR_HEADER_COMMENT(controllerName));
|
|
2140
2202
|
const serviceClass = sourceFile.addClass({
|
|
2141
2203
|
name: className,
|
|
@@ -2163,6 +2225,13 @@ var ServiceGenerator = class {
|
|
|
2163
2225
|
isReadonly: true,
|
|
2164
2226
|
initializer: `inject(${basePathTokenName})`
|
|
2165
2227
|
});
|
|
2228
|
+
serviceClass.addProperty({
|
|
2229
|
+
name: "clientContextToken",
|
|
2230
|
+
type: "any",
|
|
2231
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2232
|
+
isReadonly: true,
|
|
2233
|
+
initializer: clientContextTokenName
|
|
2234
|
+
});
|
|
2166
2235
|
operations.forEach((operation) => {
|
|
2167
2236
|
this.methodGenerator.addServiceMethod(serviceClass, operation);
|
|
2168
2237
|
});
|
|
@@ -2170,6 +2239,11 @@ var ServiceGenerator = class {
|
|
|
2170
2239
|
throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
|
|
2171
2240
|
}
|
|
2172
2241
|
}
|
|
2242
|
+
getClientContextTokenName() {
|
|
2243
|
+
const clientName = this.config.clientName || "default";
|
|
2244
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2245
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
2246
|
+
}
|
|
2173
2247
|
getBasePathTokenName() {
|
|
2174
2248
|
const clientName = this.config.clientName || "default";
|
|
2175
2249
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
package/index.js
CHANGED
|
@@ -472,12 +472,14 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
472
472
|
});
|
|
473
473
|
sourceFile.addImportDeclaration({
|
|
474
474
|
namedImports: [
|
|
475
|
-
"HttpInterceptor"
|
|
475
|
+
"HttpInterceptor",
|
|
476
|
+
"HttpContextToken"
|
|
476
477
|
],
|
|
477
478
|
moduleSpecifier: "@angular/common/http"
|
|
478
479
|
});
|
|
479
480
|
const basePathTokenName = this.getBasePathTokenName();
|
|
480
481
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
482
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
481
483
|
sourceFile.addVariableStatement({
|
|
482
484
|
isExported: true,
|
|
483
485
|
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
@@ -510,6 +512,20 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
510
512
|
leadingTrivia: `/**
|
|
511
513
|
* Injection token for the ${this.clientName} client HTTP interceptor instances
|
|
512
514
|
*/
|
|
515
|
+
`
|
|
516
|
+
});
|
|
517
|
+
sourceFile.addVariableStatement({
|
|
518
|
+
isExported: true,
|
|
519
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
520
|
+
declarations: [
|
|
521
|
+
{
|
|
522
|
+
name: clientContextTokenName,
|
|
523
|
+
initializer: `new HttpContextToken<string>(() => '${this.clientName}')`
|
|
524
|
+
}
|
|
525
|
+
],
|
|
526
|
+
leadingTrivia: `/**
|
|
527
|
+
* HttpContext token to identify requests belonging to the ${this.clientName} client
|
|
528
|
+
*/
|
|
513
529
|
`
|
|
514
530
|
});
|
|
515
531
|
if (this.clientName === "default") {
|
|
@@ -525,6 +541,20 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
525
541
|
leadingTrivia: `/**
|
|
526
542
|
* @deprecated Use ${basePathTokenName} instead
|
|
527
543
|
*/
|
|
544
|
+
`
|
|
545
|
+
});
|
|
546
|
+
sourceFile.addVariableStatement({
|
|
547
|
+
isExported: true,
|
|
548
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
549
|
+
declarations: [
|
|
550
|
+
{
|
|
551
|
+
name: "CLIENT_CONTEXT_TOKEN",
|
|
552
|
+
initializer: clientContextTokenName
|
|
553
|
+
}
|
|
554
|
+
],
|
|
555
|
+
leadingTrivia: `/**
|
|
556
|
+
* @deprecated Use ${clientContextTokenName} instead
|
|
557
|
+
*/
|
|
528
558
|
`
|
|
529
559
|
});
|
|
530
560
|
}
|
|
@@ -538,6 +568,10 @@ var _TokenGenerator = class _TokenGenerator {
|
|
|
538
568
|
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
539
569
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
540
570
|
}
|
|
571
|
+
getClientContextTokenName() {
|
|
572
|
+
const clientSuffix = this.clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
573
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
574
|
+
}
|
|
541
575
|
};
|
|
542
576
|
__name(_TokenGenerator, "TokenGenerator");
|
|
543
577
|
var TokenGenerator = _TokenGenerator;
|
|
@@ -1083,6 +1117,7 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1083
1117
|
sourceFile.insertText(0, BASE_INTERCEPTOR_HEADER_COMMENT(__privateGet(this, _clientName)));
|
|
1084
1118
|
const basePathTokenName = this.getBasePathTokenName();
|
|
1085
1119
|
const interceptorsTokenName = this.getInterceptorsTokenName();
|
|
1120
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
1086
1121
|
sourceFile.addImportDeclarations([
|
|
1087
1122
|
{
|
|
1088
1123
|
namedImports: [
|
|
@@ -1109,7 +1144,8 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1109
1144
|
{
|
|
1110
1145
|
namedImports: [
|
|
1111
1146
|
basePathTokenName,
|
|
1112
|
-
interceptorsTokenName
|
|
1147
|
+
interceptorsTokenName,
|
|
1148
|
+
clientContextTokenName
|
|
1113
1149
|
],
|
|
1114
1150
|
moduleSpecifier: "../tokens"
|
|
1115
1151
|
}
|
|
@@ -1128,11 +1164,11 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1128
1164
|
],
|
|
1129
1165
|
properties: [
|
|
1130
1166
|
{
|
|
1131
|
-
name: "
|
|
1167
|
+
name: "clientName",
|
|
1132
1168
|
type: "string",
|
|
1133
1169
|
scope: import_ts_morph3.Scope.Private,
|
|
1134
1170
|
isReadonly: true,
|
|
1135
|
-
initializer: `
|
|
1171
|
+
initializer: `'${__privateGet(this, _clientName)}'`
|
|
1136
1172
|
},
|
|
1137
1173
|
{
|
|
1138
1174
|
name: "httpInterceptors",
|
|
@@ -1140,6 +1176,13 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1140
1176
|
scope: import_ts_morph3.Scope.Private,
|
|
1141
1177
|
isReadonly: true,
|
|
1142
1178
|
initializer: `inject(${interceptorsTokenName})`
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
name: "clientContextToken",
|
|
1182
|
+
type: "any",
|
|
1183
|
+
scope: import_ts_morph3.Scope.Private,
|
|
1184
|
+
isReadonly: true,
|
|
1185
|
+
initializer: clientContextTokenName
|
|
1143
1186
|
}
|
|
1144
1187
|
],
|
|
1145
1188
|
methods: [
|
|
@@ -1157,8 +1200,11 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1157
1200
|
],
|
|
1158
1201
|
returnType: "Observable<HttpEvent<any>>",
|
|
1159
1202
|
statements: `
|
|
1160
|
-
//
|
|
1161
|
-
|
|
1203
|
+
// Check if this request belongs to this client using HttpContext
|
|
1204
|
+
const requestClientName = req.context.get(this.clientContextToken);
|
|
1205
|
+
|
|
1206
|
+
if (requestClientName !== this.clientName) {
|
|
1207
|
+
// This request doesn't belong to this client, pass it through
|
|
1162
1208
|
return next.handle(req);
|
|
1163
1209
|
}
|
|
1164
1210
|
|
|
@@ -1186,6 +1232,10 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1186
1232
|
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1187
1233
|
return `HTTP_INTERCEPTORS_${clientSuffix}`;
|
|
1188
1234
|
}
|
|
1235
|
+
getClientContextTokenName() {
|
|
1236
|
+
const clientSuffix = __privateGet(this, _clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
1237
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
1238
|
+
}
|
|
1189
1239
|
capitalizeFirst(str) {
|
|
1190
1240
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1191
1241
|
}
|
|
@@ -1289,6 +1339,7 @@ var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
|
|
|
1289
1339
|
this.generateQueryParams(context),
|
|
1290
1340
|
this.generateHeaders(context),
|
|
1291
1341
|
this.generateMultipartFormData(operation, context),
|
|
1342
|
+
this.generateContextHelper(),
|
|
1292
1343
|
this.generateRequestOptions(context),
|
|
1293
1344
|
this.generateHttpRequest(operation, context)
|
|
1294
1345
|
];
|
|
@@ -1488,9 +1539,7 @@ ${formDataAppends}`;
|
|
|
1488
1539
|
}
|
|
1489
1540
|
options.push("reportProgress: options?.reportProgress");
|
|
1490
1541
|
options.push("withCredentials: options?.withCredentials");
|
|
1491
|
-
|
|
1492
|
-
options.push("context: options?.context");
|
|
1493
|
-
}
|
|
1542
|
+
options.push("context: this.createContextWithClientId(options?.context)");
|
|
1494
1543
|
const formattedOptions = options.filter((opt) => opt && !opt.includes("undefined")).join(",\n ");
|
|
1495
1544
|
return `
|
|
1496
1545
|
const requestOptions: any = {
|
|
@@ -1584,6 +1633,16 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
|
|
|
1584
1633
|
}
|
|
1585
1634
|
return "blob";
|
|
1586
1635
|
}
|
|
1636
|
+
generateContextHelper() {
|
|
1637
|
+
return `
|
|
1638
|
+
/**
|
|
1639
|
+
* Creates HttpContext with client identification
|
|
1640
|
+
*/
|
|
1641
|
+
private createContextWithClientId(existingContext?: HttpContext): HttpContext {
|
|
1642
|
+
const context = existingContext || new HttpContext();
|
|
1643
|
+
return context.set(this.clientContextToken, '${this.config.clientName || "default"}');
|
|
1644
|
+
}`;
|
|
1645
|
+
}
|
|
1587
1646
|
};
|
|
1588
1647
|
__name(_ServiceMethodBodyGenerator, "ServiceMethodBodyGenerator");
|
|
1589
1648
|
var ServiceMethodBodyGenerator = _ServiceMethodBodyGenerator;
|
|
@@ -2146,6 +2205,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2146
2205
|
}
|
|
2147
2206
|
addImports(sourceFile, usedTypes) {
|
|
2148
2207
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2208
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2149
2209
|
sourceFile.addImportDeclarations([
|
|
2150
2210
|
{
|
|
2151
2211
|
namedImports: [
|
|
@@ -2173,7 +2233,8 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2173
2233
|
},
|
|
2174
2234
|
{
|
|
2175
2235
|
namedImports: [
|
|
2176
|
-
basePathTokenName
|
|
2236
|
+
basePathTokenName,
|
|
2237
|
+
clientContextTokenName
|
|
2177
2238
|
],
|
|
2178
2239
|
moduleSpecifier: "../tokens"
|
|
2179
2240
|
}
|
|
@@ -2188,6 +2249,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2188
2249
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2189
2250
|
const className = `${controllerName}Service`;
|
|
2190
2251
|
const basePathTokenName = this.getBasePathTokenName();
|
|
2252
|
+
const clientContextTokenName = this.getClientContextTokenName();
|
|
2191
2253
|
sourceFile.insertText(0, SERVICE_GENERATOR_HEADER_COMMENT(controllerName));
|
|
2192
2254
|
const serviceClass = sourceFile.addClass({
|
|
2193
2255
|
name: className,
|
|
@@ -2215,6 +2277,13 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2215
2277
|
isReadonly: true,
|
|
2216
2278
|
initializer: `inject(${basePathTokenName})`
|
|
2217
2279
|
});
|
|
2280
|
+
serviceClass.addProperty({
|
|
2281
|
+
name: "clientContextToken",
|
|
2282
|
+
type: "any",
|
|
2283
|
+
scope: import_ts_morph4.Scope.Private,
|
|
2284
|
+
isReadonly: true,
|
|
2285
|
+
initializer: clientContextTokenName
|
|
2286
|
+
});
|
|
2218
2287
|
operations.forEach((operation) => {
|
|
2219
2288
|
this.methodGenerator.addServiceMethod(serviceClass, operation);
|
|
2220
2289
|
});
|
|
@@ -2222,6 +2291,11 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2222
2291
|
throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
|
|
2223
2292
|
}
|
|
2224
2293
|
}
|
|
2294
|
+
getClientContextTokenName() {
|
|
2295
|
+
const clientName = this.config.clientName || "default";
|
|
2296
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2297
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
2298
|
+
}
|
|
2225
2299
|
getBasePathTokenName() {
|
|
2226
2300
|
const clientName = this.config.clientName || "default";
|
|
2227
2301
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|