ng-openapi 0.0.41 → 0.0.42-pr-9-feature-http-resource-7fff090.0

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.
Files changed (4) hide show
  1. package/cli.cjs +427 -511
  2. package/index.d.ts +108 -23
  3. package/index.js +484 -516
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -73,12 +73,438 @@ var __async = (__this, __arguments, generator) => {
73
73
  // src/index.ts
74
74
  var index_exports = {};
75
75
  __export(index_exports, {
76
+ BASE_INTERCEPTOR_HEADER_COMMENT: () => BASE_INTERCEPTOR_HEADER_COMMENT,
77
+ HTTP_RESOURCE_GENERATOR_HEADER_COMMENT: () => HTTP_RESOURCE_GENERATOR_HEADER_COMMENT,
78
+ MAIN_INDEX_GENERATOR_HEADER_COMMENT: () => MAIN_INDEX_GENERATOR_HEADER_COMMENT,
79
+ PROVIDER_GENERATOR_HEADER_COMMENT: () => PROVIDER_GENERATOR_HEADER_COMMENT,
80
+ SERVICE_GENERATOR_HEADER_COMMENT: () => SERVICE_GENERATOR_HEADER_COMMENT,
81
+ SERVICE_INDEX_GENERATOR_HEADER_COMMENT: () => SERVICE_INDEX_GENERATOR_HEADER_COMMENT,
76
82
  SwaggerParser: () => SwaggerParser,
77
- generateFromConfig: () => generateFromConfig
83
+ TYPE_GENERATOR_HEADER_COMMENT: () => TYPE_GENERATOR_HEADER_COMMENT,
84
+ camelCase: () => camelCase,
85
+ collectUsedTypes: () => collectUsedTypes,
86
+ escapeString: () => escapeString,
87
+ extractPaths: () => extractPaths,
88
+ generateFromConfig: () => generateFromConfig,
89
+ getBasePathTokenName: () => getBasePathTokenName,
90
+ getClientContextTokenName: () => getClientContextTokenName,
91
+ getResponseType: () => getResponseType,
92
+ getResponseTypeFromResponse: () => getResponseTypeFromResponse,
93
+ getTypeScriptType: () => getTypeScriptType,
94
+ hasDuplicateFunctionNames: () => hasDuplicateFunctionNames,
95
+ inferResponseTypeFromContentType: () => inferResponseTypeFromContentType,
96
+ isPrimitiveType: () => isPrimitiveType,
97
+ kebabCase: () => kebabCase,
98
+ nullableType: () => nullableType,
99
+ pascalCase: () => pascalCase
78
100
  });
79
101
  module.exports = __toCommonJS(index_exports);
80
102
 
81
- // src/lib/core/swagger-parser.ts
103
+ // src/lib/core/generator.ts
104
+ var import_ts_morph6 = require("ts-morph");
105
+
106
+ // src/lib/generators/type/type.generator.ts
107
+ var import_ts_morph = require("ts-morph");
108
+
109
+ // ../shared/src/utils/string.utils.ts
110
+ function camelCase(str) {
111
+ const cleaned = str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
112
+ return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
113
+ }
114
+ __name(camelCase, "camelCase");
115
+ function kebabCase(str) {
116
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
117
+ }
118
+ __name(kebabCase, "kebabCase");
119
+ function pascalCase(str) {
120
+ return str.replace(/(?:^|[-_])([a-z])/g, (_, char) => char.toUpperCase());
121
+ }
122
+ __name(pascalCase, "pascalCase");
123
+
124
+ // ../shared/src/utils/type.utils.ts
125
+ function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, context = "type") {
126
+ let schema;
127
+ let nullable;
128
+ if (typeof schemaOrType === "string" || schemaOrType === void 0) {
129
+ schema = {
130
+ type: schemaOrType,
131
+ format: typeof formatOrNullable === "string" ? formatOrNullable : void 0
132
+ };
133
+ nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : isNullable;
134
+ } else {
135
+ schema = schemaOrType;
136
+ nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : schema.nullable;
137
+ }
138
+ if (!schema) {
139
+ return "any";
140
+ }
141
+ if (schema.$ref) {
142
+ const refName = schema.$ref.split("/").pop();
143
+ return nullableType(pascalCase(refName), nullable);
144
+ }
145
+ if (schema.type === "array") {
146
+ const itemType = schema.items ? getTypeScriptType(schema.items, config, void 0, void 0, context) : "unknown";
147
+ return nullable ? `(${itemType}[] | null)` : `${itemType}[]`;
148
+ }
149
+ switch (schema.type) {
150
+ case "string":
151
+ if (schema.enum) {
152
+ return schema.enum.map((value) => typeof value === "string" ? `'${escapeString(value)}'` : String(value)).join(" | ");
153
+ }
154
+ if (schema.format === "date" || schema.format === "date-time") {
155
+ const dateType = config.options.dateType === "Date" ? "Date" : "string";
156
+ return nullableType(dateType, nullable);
157
+ }
158
+ if (schema.format === "binary") {
159
+ const binaryType = context === "type" ? "Blob" : "File";
160
+ return nullableType(binaryType, nullable);
161
+ }
162
+ if (schema.format === "uuid" || schema.format === "email" || schema.format === "uri" || schema.format === "hostname" || schema.format === "ipv4" || schema.format === "ipv6") {
163
+ return nullableType("string", nullable);
164
+ }
165
+ return nullableType("string", nullable);
166
+ case "number":
167
+ case "integer":
168
+ return nullableType("number", nullable);
169
+ case "boolean":
170
+ return nullableType("boolean", nullable);
171
+ case "object":
172
+ return nullableType(context === "type" ? "Record<string, unknown>" : "any", nullable);
173
+ case "null":
174
+ return "null";
175
+ default:
176
+ console.warn(`Unknown swagger type: ${schema.type}`);
177
+ return nullableType("any", nullable);
178
+ }
179
+ }
180
+ __name(getTypeScriptType, "getTypeScriptType");
181
+ function nullableType(type, isNullable) {
182
+ return type + (isNullable ? " | null" : "");
183
+ }
184
+ __name(nullableType, "nullableType");
185
+ function escapeString(str) {
186
+ return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
187
+ }
188
+ __name(escapeString, "escapeString");
189
+
190
+ // ../shared/src/utils/functions/collect-used-types.ts
191
+ function collectUsedTypes(operations) {
192
+ const usedTypes = /* @__PURE__ */ new Set();
193
+ operations.forEach((operation) => {
194
+ var _a;
195
+ (_a = operation.parameters) == null ? void 0 : _a.forEach((param) => {
196
+ collectTypesFromSchema(param.schema || param, usedTypes);
197
+ });
198
+ if (operation.requestBody) {
199
+ collectTypesFromRequestBody(operation.requestBody, usedTypes);
200
+ }
201
+ if (operation.responses) {
202
+ Object.values(operation.responses).forEach((response) => {
203
+ collectTypesFromResponse(response, usedTypes);
204
+ });
205
+ }
206
+ });
207
+ return usedTypes;
208
+ }
209
+ __name(collectUsedTypes, "collectUsedTypes");
210
+ function collectTypesFromSchema(schema, usedTypes) {
211
+ if (!schema) return;
212
+ if (schema.$ref) {
213
+ const refName = schema.$ref.split("/").pop();
214
+ if (refName) {
215
+ usedTypes.add(pascalCase(refName));
216
+ }
217
+ }
218
+ if (schema.type === "array" && schema.items) {
219
+ collectTypesFromSchema(schema.items, usedTypes);
220
+ }
221
+ if (schema.type === "object" && schema.properties) {
222
+ Object.values(schema.properties).forEach((prop) => {
223
+ collectTypesFromSchema(prop, usedTypes);
224
+ });
225
+ }
226
+ if (schema.allOf) {
227
+ schema.allOf.forEach((subSchema) => {
228
+ collectTypesFromSchema(subSchema, usedTypes);
229
+ });
230
+ }
231
+ if (schema.oneOf) {
232
+ schema.oneOf.forEach((subSchema) => {
233
+ collectTypesFromSchema(subSchema, usedTypes);
234
+ });
235
+ }
236
+ if (schema.anyOf) {
237
+ schema.anyOf.forEach((subSchema) => {
238
+ collectTypesFromSchema(subSchema, usedTypes);
239
+ });
240
+ }
241
+ }
242
+ __name(collectTypesFromSchema, "collectTypesFromSchema");
243
+ function collectTypesFromRequestBody(requestBody, usedTypes) {
244
+ const content = requestBody.content || {};
245
+ Object.values(content).forEach((mediaType) => {
246
+ if (mediaType.schema) {
247
+ collectTypesFromSchema(mediaType.schema, usedTypes);
248
+ }
249
+ });
250
+ }
251
+ __name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
252
+ function collectTypesFromResponse(response, usedTypes) {
253
+ const content = response.content || {};
254
+ Object.values(content).forEach((mediaType) => {
255
+ if (mediaType.schema) {
256
+ collectTypesFromSchema(mediaType.schema, usedTypes);
257
+ }
258
+ });
259
+ }
260
+ __name(collectTypesFromResponse, "collectTypesFromResponse");
261
+
262
+ // ../shared/src/utils/functions/token-names.ts
263
+ function getClientContextTokenName(clientName = "default") {
264
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
265
+ return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
266
+ }
267
+ __name(getClientContextTokenName, "getClientContextTokenName");
268
+ function getBasePathTokenName(clientName = "default") {
269
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
270
+ return `BASE_PATH_${clientSuffix}`;
271
+ }
272
+ __name(getBasePathTokenName, "getBasePathTokenName");
273
+
274
+ // ../shared/src/utils/functions/duplicate-function-name.ts
275
+ function hasDuplicateFunctionNames(arr) {
276
+ return new Set(arr.map((fn) => fn.getName())).size !== arr.length;
277
+ }
278
+ __name(hasDuplicateFunctionNames, "hasDuplicateFunctionNames");
279
+
280
+ // ../shared/src/utils/functions/extract-paths.ts
281
+ function extractPaths(swaggerPaths = {}, methods = [
282
+ "get",
283
+ "post",
284
+ "put",
285
+ "patch",
286
+ "delete",
287
+ "options",
288
+ "head"
289
+ ]) {
290
+ const paths = [];
291
+ Object.entries(swaggerPaths).forEach(([path10, pathItem]) => {
292
+ methods.forEach((method) => {
293
+ if (pathItem[method]) {
294
+ const operation = pathItem[method];
295
+ paths.push({
296
+ path: path10,
297
+ method: method.toUpperCase(),
298
+ operationId: operation.operationId,
299
+ summary: operation.summary,
300
+ description: operation.description,
301
+ tags: operation.tags || [],
302
+ parameters: parseParameters(operation.parameters || [], pathItem.parameters || []),
303
+ requestBody: operation.requestBody,
304
+ responses: operation.responses || {}
305
+ });
306
+ }
307
+ });
308
+ });
309
+ return paths;
310
+ }
311
+ __name(extractPaths, "extractPaths");
312
+ function parseParameters(operationParams, pathParams) {
313
+ const allParams = [
314
+ ...pathParams,
315
+ ...operationParams
316
+ ];
317
+ return allParams.map((param) => ({
318
+ name: param.name,
319
+ in: param.in,
320
+ required: param.required || param.in === "path",
321
+ schema: param.schema,
322
+ type: param.type,
323
+ format: param.format,
324
+ description: param.description
325
+ }));
326
+ }
327
+ __name(parseParameters, "parseParameters");
328
+
329
+ // ../shared/src/utils/functions/extract-swagger-response-type.ts
330
+ function getResponseTypeFromResponse(response, responseTypeMapping) {
331
+ var _a;
332
+ const content = response.content || {};
333
+ if (Object.keys(content).length === 0) {
334
+ return "json";
335
+ }
336
+ const responseTypes = [];
337
+ for (const [contentType, mediaType] of Object.entries(content)) {
338
+ const schema = mediaType == null ? void 0 : mediaType.schema;
339
+ const mapping = responseTypeMapping || {};
340
+ if (mapping[contentType]) {
341
+ responseTypes.push({
342
+ type: mapping[contentType],
343
+ priority: 1,
344
+ contentType
345
+ });
346
+ continue;
347
+ }
348
+ if ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte") {
349
+ responseTypes.push({
350
+ type: "blob",
351
+ priority: 2,
352
+ contentType
353
+ });
354
+ continue;
355
+ }
356
+ if ((schema == null ? void 0 : schema.type) === "string" && ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte")) {
357
+ responseTypes.push({
358
+ type: "blob",
359
+ priority: 2,
360
+ contentType
361
+ });
362
+ continue;
363
+ }
364
+ const isPrimitive = isPrimitiveType(schema);
365
+ const inferredType = inferResponseTypeFromContentType(contentType);
366
+ let priority = 3;
367
+ let finalType = inferredType;
368
+ if (inferredType === "json" && isPrimitive) {
369
+ finalType = "text";
370
+ priority = 2;
371
+ } else if (inferredType === "json") {
372
+ priority = 2;
373
+ }
374
+ responseTypes.push({
375
+ type: finalType,
376
+ priority,
377
+ contentType,
378
+ isPrimitive
379
+ });
380
+ }
381
+ responseTypes.sort((a, b) => a.priority - b.priority);
382
+ return ((_a = responseTypes[0]) == null ? void 0 : _a.type) || "json";
383
+ }
384
+ __name(getResponseTypeFromResponse, "getResponseTypeFromResponse");
385
+ function isPrimitiveType(schema) {
386
+ if (!schema) return false;
387
+ const primitiveTypes = [
388
+ "string",
389
+ "number",
390
+ "integer",
391
+ "boolean"
392
+ ];
393
+ if (primitiveTypes.includes(schema.type)) {
394
+ return true;
395
+ }
396
+ if (schema.type === "array") {
397
+ return false;
398
+ }
399
+ if (schema.type === "object" || schema.properties) {
400
+ return false;
401
+ }
402
+ if (schema.$ref) {
403
+ return false;
404
+ }
405
+ if (schema.allOf || schema.oneOf || schema.anyOf) {
406
+ return false;
407
+ }
408
+ return false;
409
+ }
410
+ __name(isPrimitiveType, "isPrimitiveType");
411
+ function inferResponseTypeFromContentType(contentType) {
412
+ const normalizedType = contentType.split(";")[0].trim().toLowerCase();
413
+ if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
414
+ return "json";
415
+ }
416
+ if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
417
+ return "text";
418
+ }
419
+ if (normalizedType.startsWith("text/")) {
420
+ const binaryTextTypes = [
421
+ "text/rtf",
422
+ "text/cache-manifest",
423
+ "text/vcard",
424
+ "text/calendar"
425
+ ];
426
+ if (binaryTextTypes.includes(normalizedType)) {
427
+ return "blob";
428
+ }
429
+ return "text";
430
+ }
431
+ if (normalizedType === "application/x-www-form-urlencoded" || normalizedType === "multipart/form-data") {
432
+ return "text";
433
+ }
434
+ if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
435
+ return "text";
436
+ }
437
+ if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
438
+ return "arraybuffer";
439
+ }
440
+ return "blob";
441
+ }
442
+ __name(inferResponseTypeFromContentType, "inferResponseTypeFromContentType");
443
+ function getResponseType(response, config) {
444
+ const responseType = getResponseTypeFromResponse(response);
445
+ switch (responseType) {
446
+ case "blob":
447
+ return "Blob";
448
+ case "arraybuffer":
449
+ return "ArrayBuffer";
450
+ case "text":
451
+ return "string";
452
+ case "json": {
453
+ const content = response.content || {};
454
+ for (const [contentType, mediaType] of Object.entries(content)) {
455
+ if (inferResponseTypeFromContentType(contentType) === "json" && (mediaType == null ? void 0 : mediaType.schema)) {
456
+ return getTypeScriptType(mediaType.schema, config, mediaType.schema.nullable);
457
+ }
458
+ }
459
+ return "any";
460
+ }
461
+ default:
462
+ return "any";
463
+ }
464
+ }
465
+ __name(getResponseType, "getResponseType");
466
+
467
+ // ../shared/src/config/constants.ts
468
+ var disableLinting = `/* @ts-nocheck */
469
+ /* eslint-disable */
470
+ /* @noformat */
471
+ /* @formatter:off */
472
+ `;
473
+ var authorComment = `/**
474
+ * Generated by ng-openapi
475
+ `;
476
+ var defaultHeaderComment = disableLinting + authorComment;
477
+ var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
478
+ * Do not edit this file manually
479
+ */
480
+ `;
481
+ var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
482
+ * Do not edit this file manually
483
+ */
484
+ `;
485
+ var SERVICE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((controllerName) => defaultHeaderComment + `* Generated Angular service for ${controllerName} controller
486
+ * Do not edit this file manually
487
+ */
488
+ `, "SERVICE_GENERATOR_HEADER_COMMENT");
489
+ var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
490
+ * Do not edit this file manually
491
+ */
492
+ `;
493
+ var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
494
+ * Do not edit this file manually
495
+ */
496
+ `;
497
+ var BASE_INTERCEPTOR_HEADER_COMMENT = /* @__PURE__ */ __name((clientName) => defaultHeaderComment + `* Generated Base Interceptor for client ${clientName}
498
+ * Do not edit this file manually
499
+ */
500
+ `, "BASE_INTERCEPTOR_HEADER_COMMENT");
501
+ var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceName) => defaultHeaderComment + `* \`httpResource\` is still an experimental feature - NOT PRODUCTION READY
502
+ * Generated Angular service for ${resourceName}
503
+ * Do not edit this file manually
504
+ */
505
+ `, "HTTP_RESOURCE_GENERATOR_HEADER_COMMENT");
506
+
507
+ // ../shared/src/core/swagger-parser.ts
82
508
  var fs = __toESM(require("fs"));
83
509
  var path = __toESM(require("path"));
84
510
  var yaml = __toESM(require("js-yaml"));
@@ -122,7 +548,7 @@ var _SwaggerParser = class _SwaggerParser {
122
548
  const response = yield fetch(url, {
123
549
  method: "GET",
124
550
  headers: {
125
- "Accept": "application/json, application/yaml, text/yaml, text/plain, */*",
551
+ Accept: "application/json, application/yaml, text/yaml, text/plain, */*",
126
552
  "User-Agent": "ng-openapi"
127
553
  },
128
554
  // 30 second timeout
@@ -242,47 +668,6 @@ var _SwaggerParser = class _SwaggerParser {
242
668
  __name(_SwaggerParser, "SwaggerParser");
243
669
  var SwaggerParser = _SwaggerParser;
244
670
 
245
- // src/lib/core/generator.ts
246
- var import_ts_morph6 = require("ts-morph");
247
-
248
- // src/lib/generators/type/type.generator.ts
249
- var import_ts_morph = require("ts-morph");
250
-
251
- // src/lib/config/constants.ts
252
- var disableLinting = `/* @ts-nocheck */
253
- /* eslint-disable */
254
- /* @noformat */
255
- /* @formatter:off */
256
- `;
257
- var authorComment = `/**
258
- * Generated by ng-openapi
259
- `;
260
- var defaultHeaderComment = disableLinting + authorComment;
261
- var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
262
- * Do not edit this file manually
263
- */
264
- `;
265
- var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
266
- * Do not edit this file manually
267
- */
268
- `;
269
- var SERVICE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((controllerName) => defaultHeaderComment + `* Generated Angular service for ${controllerName} controller
270
- * Do not edit this file manually
271
- */
272
- `, "SERVICE_GENERATOR_HEADER_COMMENT");
273
- var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
274
- * Do not edit this file manually
275
- */
276
- `;
277
- var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
278
- * Do not edit this file manually
279
- */
280
- `;
281
- var BASE_INTERCEPTOR_HEADER_COMMENT = /* @__PURE__ */ __name((clientName) => defaultHeaderComment + `* Generated Base Interceptor for client ${clientName}
282
- * Do not edit this file manually
283
- */
284
- `, "BASE_INTERCEPTOR_HEADER_COMMENT");
285
-
286
671
  // src/lib/generators/type/type.generator.ts
287
672
  var _TypeGenerator = class _TypeGenerator {
288
673
  constructor(parser, outputRoot, config) {
@@ -323,6 +708,7 @@ var _TypeGenerator = class _TypeGenerator {
323
708
  Object.entries(definitions).forEach(([name, definition]) => {
324
709
  this.generateInterface(name, definition);
325
710
  });
711
+ this.sourceFile.formatText();
326
712
  this.sourceFile.saveSync();
327
713
  } catch (error) {
328
714
  console.error("Error in generate():", error);
@@ -695,6 +1081,7 @@ var _TokenGenerator = class _TokenGenerator {
695
1081
  `
696
1082
  });
697
1083
  }
1084
+ sourceFile.formatText();
698
1085
  sourceFile.saveSync();
699
1086
  }
700
1087
  getBasePathTokenName() {
@@ -847,6 +1234,7 @@ var _FileDownloadGenerator = class _FileDownloadGenerator {
847
1234
 
848
1235
  return fallbackFilename;`
849
1236
  });
1237
+ sourceFile.formatText();
850
1238
  sourceFile.saveSync();
851
1239
  }
852
1240
  };
@@ -981,6 +1369,7 @@ var _DateTransformerGenerator = class _DateTransformerGenerator {
981
1369
  }
982
1370
  ]
983
1371
  });
1372
+ sourceFile.formatText();
984
1373
  sourceFile.saveSync();
985
1374
  }
986
1375
  };
@@ -1024,6 +1413,7 @@ var _MainIndexGenerator = class _MainIndexGenerator {
1024
1413
  });
1025
1414
  }
1026
1415
  }
1416
+ sourceFile.formatText();
1027
1417
  sourceFile.saveSync();
1028
1418
  }
1029
1419
  };
@@ -1121,6 +1511,7 @@ var _ProviderGenerator = class _ProviderGenerator {
1121
1511
  ]
1122
1512
  });
1123
1513
  this.addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName);
1514
+ sourceFile.formatText();
1124
1515
  sourceFile.saveSync();
1125
1516
  }
1126
1517
  addMainProviderFunction(sourceFile, basePathTokenName, interceptorsTokenName, baseInterceptorClassName) {
@@ -1350,6 +1741,7 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
1350
1741
  }
1351
1742
  ]
1352
1743
  });
1744
+ sourceFile.formatText();
1353
1745
  sourceFile.saveSync();
1354
1746
  }
1355
1747
  getInterceptorsTokenName() {
@@ -1373,83 +1765,6 @@ var BaseInterceptorGenerator = _BaseInterceptorGenerator;
1373
1765
  var import_ts_morph5 = require("ts-morph");
1374
1766
  var path8 = __toESM(require("path"));
1375
1767
 
1376
- // src/lib/utils/string.utils.ts
1377
- function camelCase(str) {
1378
- const cleaned = str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
1379
- return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
1380
- }
1381
- __name(camelCase, "camelCase");
1382
- function pascalCase(str) {
1383
- return str.replace(/(?:^|[-_])([a-z])/g, (_, char) => char.toUpperCase());
1384
- }
1385
- __name(pascalCase, "pascalCase");
1386
-
1387
- // src/lib/utils/type.utils.ts
1388
- function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, context = "type") {
1389
- let schema;
1390
- let nullable;
1391
- if (typeof schemaOrType === "string" || schemaOrType === void 0) {
1392
- schema = {
1393
- type: schemaOrType,
1394
- format: typeof formatOrNullable === "string" ? formatOrNullable : void 0
1395
- };
1396
- nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : isNullable;
1397
- } else {
1398
- schema = schemaOrType;
1399
- nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : schema.nullable;
1400
- }
1401
- if (!schema) {
1402
- return "any";
1403
- }
1404
- if (schema.$ref) {
1405
- const refName = schema.$ref.split("/").pop();
1406
- return nullableType(pascalCase(refName), nullable);
1407
- }
1408
- if (schema.type === "array") {
1409
- const itemType = schema.items ? getTypeScriptType(schema.items, config, void 0, void 0, context) : "unknown";
1410
- return nullable ? `(${itemType}[] | null)` : `${itemType}[]`;
1411
- }
1412
- switch (schema.type) {
1413
- case "string":
1414
- if (schema.enum) {
1415
- return schema.enum.map((value) => typeof value === "string" ? `'${escapeString(value)}'` : String(value)).join(" | ");
1416
- }
1417
- if (schema.format === "date" || schema.format === "date-time") {
1418
- const dateType = config.options.dateType === "Date" ? "Date" : "string";
1419
- return nullableType(dateType, nullable);
1420
- }
1421
- if (schema.format === "binary") {
1422
- const binaryType = context === "type" ? "Blob" : "File";
1423
- return nullableType(binaryType, nullable);
1424
- }
1425
- if (schema.format === "uuid" || schema.format === "email" || schema.format === "uri" || schema.format === "hostname" || schema.format === "ipv4" || schema.format === "ipv6") {
1426
- return nullableType("string", nullable);
1427
- }
1428
- return nullableType("string", nullable);
1429
- case "number":
1430
- case "integer":
1431
- return nullableType("number", nullable);
1432
- case "boolean":
1433
- return nullableType("boolean", nullable);
1434
- case "object":
1435
- return nullableType(context === "type" ? "Record<string, unknown>" : "any", nullable);
1436
- case "null":
1437
- return "null";
1438
- default:
1439
- console.warn(`Unknown swagger type: ${schema.type}`);
1440
- return nullableType("any", nullable);
1441
- }
1442
- }
1443
- __name(getTypeScriptType, "getTypeScriptType");
1444
- function nullableType(type, isNullable) {
1445
- return type + (isNullable ? " | null" : "");
1446
- }
1447
- __name(nullableType, "nullableType");
1448
- function escapeString(str) {
1449
- return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
1450
- }
1451
- __name(escapeString, "escapeString");
1452
-
1453
1768
  // src/lib/generators/service/service-method/service-method-body.generator.ts
1454
1769
  var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
1455
1770
  constructor(config) {
@@ -1488,85 +1803,6 @@ var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
1488
1803
  const properties = ((_d = (_c = (_b = (_a = operation.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b["multipart/form-data"]) == null ? void 0 : _c.schema) == null ? void 0 : _d.properties) || {};
1489
1804
  return Object.keys(properties);
1490
1805
  }
1491
- getResponseTypeFromResponse(response) {
1492
- var _a, _b, _c;
1493
- const content = response.content || {};
1494
- if (Object.keys(content).length === 0) {
1495
- return "json";
1496
- }
1497
- const responseTypes = [];
1498
- for (const [contentType, mediaType] of Object.entries(content)) {
1499
- const schema = mediaType == null ? void 0 : mediaType.schema;
1500
- const mapping = ((_b = (_a = this.config) == null ? void 0 : _a.options) == null ? void 0 : _b.responseTypeMapping) || {};
1501
- if (mapping[contentType]) {
1502
- responseTypes.push({
1503
- type: mapping[contentType],
1504
- priority: 1,
1505
- contentType
1506
- });
1507
- continue;
1508
- }
1509
- if ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte") {
1510
- responseTypes.push({
1511
- type: "blob",
1512
- priority: 2,
1513
- contentType
1514
- });
1515
- continue;
1516
- }
1517
- if ((schema == null ? void 0 : schema.type) === "string" && ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte")) {
1518
- responseTypes.push({
1519
- type: "blob",
1520
- priority: 2,
1521
- contentType
1522
- });
1523
- continue;
1524
- }
1525
- const isPrimitive = this.isPrimitiveType(schema);
1526
- const inferredType = this.inferResponseTypeFromContentType(contentType);
1527
- let priority = 3;
1528
- let finalType = inferredType;
1529
- if (inferredType === "json" && isPrimitive) {
1530
- finalType = "text";
1531
- priority = 2;
1532
- } else if (inferredType === "json") {
1533
- priority = 2;
1534
- }
1535
- responseTypes.push({
1536
- type: finalType,
1537
- priority,
1538
- contentType,
1539
- isPrimitive
1540
- });
1541
- }
1542
- responseTypes.sort((a, b) => a.priority - b.priority);
1543
- return ((_c = responseTypes[0]) == null ? void 0 : _c.type) || "json";
1544
- }
1545
- isPrimitiveType(schema) {
1546
- if (!schema) return false;
1547
- const primitiveTypes = [
1548
- "string",
1549
- "number",
1550
- "integer",
1551
- "boolean"
1552
- ];
1553
- if (primitiveTypes.includes(schema.type)) {
1554
- return true;
1555
- }
1556
- if (schema.type === "array") {
1557
- return false;
1558
- }
1559
- if (schema.type === "object" || schema.properties) {
1560
- return false;
1561
- }
1562
- if (schema.$ref) {
1563
- return false;
1564
- }
1565
- if (schema.allOf || schema.oneOf || schema.anyOf) {
1566
- return false;
1567
- }
1568
- return false;
1569
- }
1570
1806
  createGenerationContext(operation) {
1571
1807
  var _a, _b;
1572
1808
  return {
@@ -1707,7 +1943,7 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
1707
1943
  for (const statusCode of successResponses) {
1708
1944
  const response = (_a = operation.responses) == null ? void 0 : _a[statusCode];
1709
1945
  if (!response) continue;
1710
- return this.getResponseTypeFromResponse(response);
1946
+ return getResponseTypeFromResponse(response);
1711
1947
  }
1712
1948
  return "json";
1713
1949
  }
@@ -1725,47 +1961,6 @@ return this.httpClient.${httpMethod}(url, requestOptions);`;
1725
1961
  ];
1726
1962
  return !invalidTypes.some((invalidType) => type.includes(invalidType));
1727
1963
  }
1728
- inferResponseTypeFromContentType(contentType) {
1729
- const normalizedType = contentType.split(";")[0].trim().toLowerCase();
1730
- if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
1731
- return "json";
1732
- }
1733
- if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
1734
- return "text";
1735
- }
1736
- if (normalizedType.startsWith("text/")) {
1737
- const binaryTextTypes = [
1738
- "text/rtf",
1739
- "text/cache-manifest",
1740
- "text/vcard",
1741
- "text/calendar"
1742
- ];
1743
- if (binaryTextTypes.includes(normalizedType)) {
1744
- return "blob";
1745
- }
1746
- return "text";
1747
- }
1748
- if (normalizedType === "application/x-www-form-urlencoded" || normalizedType === "multipart/form-data") {
1749
- return "text";
1750
- }
1751
- if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
1752
- return "text";
1753
- }
1754
- if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
1755
- return "arraybuffer";
1756
- }
1757
- return "blob";
1758
- }
1759
- generateContextHelper() {
1760
- return `
1761
- /**
1762
- * Creates HttpContext with client identification
1763
- */
1764
- private createContextWithClientId(existingContext?: HttpContext): HttpContext {
1765
- const context = existingContext || new HttpContext();
1766
- return context.set(this.clientContextToken, '${this.config.clientName || "default"}');
1767
- }`;
1768
- }
1769
1964
  };
1770
1965
  __name(_ServiceMethodBodyGenerator, "ServiceMethodBodyGenerator");
1771
1966
  var ServiceMethodBodyGenerator = _ServiceMethodBodyGenerator;
@@ -1830,7 +2025,7 @@ var _ServiceMethodParamsGenerator = class _ServiceMethodParamsGenerator {
1830
2025
  hasQuestionToken: !param.required
1831
2026
  });
1832
2027
  });
1833
- return params;
2028
+ return params.sort((a, b) => Number(a.hasQuestionToken) - Number(b.hasQuestionToken));
1834
2029
  }
1835
2030
  addOptionsParameter() {
1836
2031
  return [
@@ -1942,7 +2137,7 @@ var _ServiceMethodOverloadsGenerator = class _ServiceMethodOverloadsGenerator {
1942
2137
  if (!response) {
1943
2138
  return "any";
1944
2139
  }
1945
- return this.getResponseType(response);
2140
+ return getResponseType(response, this.config);
1946
2141
  }
1947
2142
  generateOverloadReturnType(responseType, observe) {
1948
2143
  switch (observe) {
@@ -1956,107 +2151,6 @@ var _ServiceMethodOverloadsGenerator = class _ServiceMethodOverloadsGenerator {
1956
2151
  throw new Error(`Unsupported observe type: ${observe}`);
1957
2152
  }
1958
2153
  }
1959
- getResponseTypeFromResponse(response) {
1960
- var _a, _b, _c;
1961
- const content = response.content || {};
1962
- if (Object.keys(content).length === 0) {
1963
- return "json";
1964
- }
1965
- const responseTypes = [];
1966
- for (const [contentType, mediaType] of Object.entries(content)) {
1967
- const schema = mediaType == null ? void 0 : mediaType.schema;
1968
- const mapping = ((_b = (_a = this.config) == null ? void 0 : _a.options) == null ? void 0 : _b.responseTypeMapping) || {};
1969
- if (mapping[contentType]) {
1970
- responseTypes.push({
1971
- type: mapping[contentType],
1972
- priority: 1,
1973
- contentType
1974
- });
1975
- continue;
1976
- }
1977
- if ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte") {
1978
- responseTypes.push({
1979
- type: "blob",
1980
- priority: 2,
1981
- contentType
1982
- });
1983
- continue;
1984
- }
1985
- if ((schema == null ? void 0 : schema.type) === "string" && ((schema == null ? void 0 : schema.format) === "binary" || (schema == null ? void 0 : schema.format) === "byte")) {
1986
- responseTypes.push({
1987
- type: "blob",
1988
- priority: 2,
1989
- contentType
1990
- });
1991
- continue;
1992
- }
1993
- const isPrimitive = this.isPrimitiveType(schema);
1994
- const inferredType = this.inferResponseTypeFromContentType(contentType);
1995
- let priority = 3;
1996
- let finalType = inferredType;
1997
- if (inferredType === "json" && isPrimitive) {
1998
- finalType = "text";
1999
- priority = 2;
2000
- } else if (inferredType === "json") {
2001
- priority = 2;
2002
- }
2003
- responseTypes.push({
2004
- type: finalType,
2005
- priority,
2006
- contentType,
2007
- isPrimitive
2008
- });
2009
- }
2010
- responseTypes.sort((a, b) => a.priority - b.priority);
2011
- return ((_c = responseTypes[0]) == null ? void 0 : _c.type) || "json";
2012
- }
2013
- isPrimitiveType(schema) {
2014
- if (!schema) return false;
2015
- const primitiveTypes = [
2016
- "string",
2017
- "number",
2018
- "integer",
2019
- "boolean"
2020
- ];
2021
- if (primitiveTypes.includes(schema.type)) {
2022
- return true;
2023
- }
2024
- if (schema.type === "array") {
2025
- return false;
2026
- }
2027
- if (schema.type === "object" || schema.properties) {
2028
- return false;
2029
- }
2030
- if (schema.$ref) {
2031
- return false;
2032
- }
2033
- if (schema.allOf || schema.oneOf || schema.anyOf) {
2034
- return false;
2035
- }
2036
- return false;
2037
- }
2038
- getResponseType(response) {
2039
- const responseType = this.getResponseTypeFromResponse(response);
2040
- switch (responseType) {
2041
- case "blob":
2042
- return "Blob";
2043
- case "arraybuffer":
2044
- return "ArrayBuffer";
2045
- case "text":
2046
- return "string";
2047
- case "json": {
2048
- const content = response.content || {};
2049
- for (const [contentType, mediaType] of Object.entries(content)) {
2050
- if (this.inferResponseTypeFromContentType(contentType) === "json" && (mediaType == null ? void 0 : mediaType.schema)) {
2051
- return getTypeScriptType(mediaType.schema, this.config, mediaType.schema.nullable);
2052
- }
2053
- }
2054
- return "any";
2055
- }
2056
- default:
2057
- return "any";
2058
- }
2059
- }
2060
2154
  determineResponseTypeForOperation(operation) {
2061
2155
  var _a;
2062
2156
  const successResponses = [
@@ -2069,41 +2163,10 @@ var _ServiceMethodOverloadsGenerator = class _ServiceMethodOverloadsGenerator {
2069
2163
  for (const statusCode of successResponses) {
2070
2164
  const response = (_a = operation.responses) == null ? void 0 : _a[statusCode];
2071
2165
  if (!response) continue;
2072
- return this.getResponseTypeFromResponse(response);
2166
+ return getResponseTypeFromResponse(response);
2073
2167
  }
2074
2168
  return "json";
2075
2169
  }
2076
- inferResponseTypeFromContentType(contentType) {
2077
- const normalizedType = contentType.split(";")[0].trim().toLowerCase();
2078
- if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
2079
- return "json";
2080
- }
2081
- if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
2082
- return "text";
2083
- }
2084
- if (normalizedType.startsWith("text/")) {
2085
- const binaryTextTypes = [
2086
- "text/rtf",
2087
- "text/cache-manifest",
2088
- "text/vcard",
2089
- "text/calendar"
2090
- ];
2091
- if (binaryTextTypes.includes(normalizedType)) {
2092
- return "blob";
2093
- }
2094
- return "text";
2095
- }
2096
- if (normalizedType === "application/x-www-form-urlencoded" || normalizedType === "multipart/form-data") {
2097
- return "text";
2098
- }
2099
- if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
2100
- return "text";
2101
- }
2102
- if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
2103
- return "arraybuffer";
2104
- }
2105
- return "blob";
2106
- }
2107
2170
  };
2108
2171
  __name(_ServiceMethodOverloadsGenerator, "ServiceMethodOverloadsGenerator");
2109
2172
  var ServiceMethodOverloadsGenerator = _ServiceMethodOverloadsGenerator;
@@ -2186,7 +2249,7 @@ var _ServiceGenerator = class _ServiceGenerator {
2186
2249
  }
2187
2250
  generate(outputRoot) {
2188
2251
  const outputDir = path8.join(outputRoot, "services");
2189
- const paths = this.extractPaths();
2252
+ const paths = extractPaths(this.spec.paths);
2190
2253
  if (paths.length === 0) {
2191
2254
  console.warn("No API paths found in the specification");
2192
2255
  return;
@@ -2196,53 +2259,6 @@ var _ServiceGenerator = class _ServiceGenerator {
2196
2259
  this.generateServiceFile(controllerName, operations, outputDir);
2197
2260
  });
2198
2261
  }
2199
- extractPaths() {
2200
- const paths = [];
2201
- const swaggerPaths = this.spec.paths || {};
2202
- Object.entries(swaggerPaths).forEach(([path10, pathItem]) => {
2203
- const methods = [
2204
- "get",
2205
- "post",
2206
- "put",
2207
- "patch",
2208
- "delete",
2209
- "options",
2210
- "head"
2211
- ];
2212
- methods.forEach((method) => {
2213
- if (pathItem[method]) {
2214
- const operation = pathItem[method];
2215
- paths.push({
2216
- path: path10,
2217
- method: method.toUpperCase(),
2218
- operationId: operation.operationId,
2219
- summary: operation.summary,
2220
- description: operation.description,
2221
- tags: operation.tags || [],
2222
- parameters: this.parseParameters(operation.parameters || [], pathItem.parameters || []),
2223
- requestBody: operation.requestBody,
2224
- responses: operation.responses || {}
2225
- });
2226
- }
2227
- });
2228
- });
2229
- return paths;
2230
- }
2231
- parseParameters(operationParams, pathParams) {
2232
- const allParams = [
2233
- ...pathParams,
2234
- ...operationParams
2235
- ];
2236
- return allParams.map((param) => ({
2237
- name: param.name,
2238
- in: param.in,
2239
- required: param.required || param.in === "path",
2240
- schema: param.schema,
2241
- type: param.type,
2242
- format: param.format,
2243
- description: param.description
2244
- }));
2245
- }
2246
2262
  groupPathsByController(paths) {
2247
2263
  const groups = {};
2248
2264
  paths.forEach((path10) => {
@@ -2269,80 +2285,15 @@ var _ServiceGenerator = class _ServiceGenerator {
2269
2285
  const sourceFile = this.project.createSourceFile(filePath, "", {
2270
2286
  overwrite: true
2271
2287
  });
2272
- const usedTypes = this.collectUsedTypes(operations);
2288
+ const usedTypes = collectUsedTypes(operations);
2273
2289
  this.addImports(sourceFile, usedTypes);
2274
2290
  this.addServiceClass(sourceFile, controllerName, operations);
2291
+ sourceFile.formatText();
2275
2292
  sourceFile.saveSync();
2276
2293
  }
2277
- collectUsedTypes(operations) {
2278
- const usedTypes = /* @__PURE__ */ new Set();
2279
- operations.forEach((operation) => {
2280
- var _a;
2281
- (_a = operation.parameters) == null ? void 0 : _a.forEach((param) => {
2282
- this.collectTypesFromSchema(param.schema || param, usedTypes);
2283
- });
2284
- if (operation.requestBody) {
2285
- this.collectTypesFromRequestBody(operation.requestBody, usedTypes);
2286
- }
2287
- if (operation.responses) {
2288
- Object.values(operation.responses).forEach((response) => {
2289
- this.collectTypesFromResponse(response, usedTypes);
2290
- });
2291
- }
2292
- });
2293
- return usedTypes;
2294
- }
2295
- collectTypesFromSchema(schema, usedTypes) {
2296
- if (!schema) return;
2297
- if (schema.$ref) {
2298
- const refName = schema.$ref.split("/").pop();
2299
- if (refName) {
2300
- usedTypes.add(pascalCase(refName));
2301
- }
2302
- }
2303
- if (schema.type === "array" && schema.items) {
2304
- this.collectTypesFromSchema(schema.items, usedTypes);
2305
- }
2306
- if (schema.type === "object" && schema.properties) {
2307
- Object.values(schema.properties).forEach((prop) => {
2308
- this.collectTypesFromSchema(prop, usedTypes);
2309
- });
2310
- }
2311
- if (schema.allOf) {
2312
- schema.allOf.forEach((subSchema) => {
2313
- this.collectTypesFromSchema(subSchema, usedTypes);
2314
- });
2315
- }
2316
- if (schema.oneOf) {
2317
- schema.oneOf.forEach((subSchema) => {
2318
- this.collectTypesFromSchema(subSchema, usedTypes);
2319
- });
2320
- }
2321
- if (schema.anyOf) {
2322
- schema.anyOf.forEach((subSchema) => {
2323
- this.collectTypesFromSchema(subSchema, usedTypes);
2324
- });
2325
- }
2326
- }
2327
- collectTypesFromRequestBody(requestBody, usedTypes) {
2328
- const content = requestBody.content || {};
2329
- Object.values(content).forEach((mediaType) => {
2330
- if (mediaType.schema) {
2331
- this.collectTypesFromSchema(mediaType.schema, usedTypes);
2332
- }
2333
- });
2334
- }
2335
- collectTypesFromResponse(response, usedTypes) {
2336
- const content = response.content || {};
2337
- Object.values(content).forEach((mediaType) => {
2338
- if (mediaType.schema) {
2339
- this.collectTypesFromSchema(mediaType.schema, usedTypes);
2340
- }
2341
- });
2342
- }
2343
2294
  addImports(sourceFile, usedTypes) {
2344
- const basePathTokenName = this.getBasePathTokenName();
2345
- const clientContextTokenName = this.getClientContextTokenName();
2295
+ const basePathTokenName = getBasePathTokenName(this.config.clientName);
2296
+ const clientContextTokenName = getClientContextTokenName(this.config.clientName);
2346
2297
  sourceFile.addImportDeclarations([
2347
2298
  {
2348
2299
  namedImports: [
@@ -2358,7 +2309,8 @@ var _ServiceGenerator = class _ServiceGenerator {
2358
2309
  "HttpHeaders",
2359
2310
  "HttpContext",
2360
2311
  "HttpResponse",
2361
- "HttpEvent"
2312
+ "HttpEvent",
2313
+ "HttpContextToken"
2362
2314
  ],
2363
2315
  moduleSpecifier: "@angular/common/http"
2364
2316
  },
@@ -2385,8 +2337,8 @@ var _ServiceGenerator = class _ServiceGenerator {
2385
2337
  }
2386
2338
  addServiceClass(sourceFile, controllerName, operations) {
2387
2339
  const className = `${controllerName}Service`;
2388
- const basePathTokenName = this.getBasePathTokenName();
2389
- const clientContextTokenName = this.getClientContextTokenName();
2340
+ const basePathTokenName = getBasePathTokenName(this.config.clientName);
2341
+ const clientContextTokenName = getClientContextTokenName(this.config.clientName);
2390
2342
  sourceFile.insertText(0, SERVICE_GENERATOR_HEADER_COMMENT(controllerName));
2391
2343
  const serviceClass = sourceFile.addClass({
2392
2344
  name: className,
@@ -2416,7 +2368,7 @@ var _ServiceGenerator = class _ServiceGenerator {
2416
2368
  });
2417
2369
  serviceClass.addProperty({
2418
2370
  name: "clientContextToken",
2419
- type: "any",
2371
+ type: "HttpContextToken<string>",
2420
2372
  scope: import_ts_morph5.Scope.Private,
2421
2373
  isReadonly: true,
2422
2374
  initializer: clientContextTokenName
@@ -2432,30 +2384,16 @@ var _ServiceGenerator = class _ServiceGenerator {
2432
2384
  }
2433
2385
  ],
2434
2386
  returnType: "HttpContext",
2435
- statements: `
2436
- const context = existingContext || new HttpContext();
2387
+ statements: `const context = existingContext || new HttpContext();
2437
2388
  return context.set(this.clientContextToken, '${this.config.clientName || "default"}');`
2438
2389
  });
2439
2390
  operations.forEach((operation) => {
2440
2391
  this.methodGenerator.addServiceMethod(serviceClass, operation);
2441
2392
  });
2442
- if (this.hasDuplicateMethodNames(serviceClass.getMethods())) {
2393
+ if (hasDuplicateFunctionNames(serviceClass.getMethods())) {
2443
2394
  throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
2444
2395
  }
2445
2396
  }
2446
- getClientContextTokenName() {
2447
- const clientName = this.config.clientName || "default";
2448
- const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
2449
- return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
2450
- }
2451
- getBasePathTokenName() {
2452
- const clientName = this.config.clientName || "default";
2453
- const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
2454
- return `BASE_PATH_${clientSuffix}`;
2455
- }
2456
- hasDuplicateMethodNames(arr) {
2457
- return new Set(arr.map((method) => method.getName())).size !== arr.length;
2458
- }
2459
2397
  };
2460
2398
  __name(_ServiceGenerator, "ServiceGenerator");
2461
2399
  var ServiceGenerator = _ServiceGenerator;
@@ -2520,7 +2458,7 @@ function validateInput(input) {
2520
2458
  __name(validateInput, "validateInput");
2521
2459
  function generateFromConfig(config) {
2522
2460
  return __async(this, null, function* () {
2523
- var _a;
2461
+ var _a, _b;
2524
2462
  validateInput(config.input);
2525
2463
  const outputPath = config.output;
2526
2464
  const generateServices = (_a = config.options.generateServices) != null ? _a : true;
@@ -2562,6 +2500,14 @@ function generateFromConfig(config) {
2562
2500
  const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
2563
2501
  baseInterceptorGenerator.generate(outputPath);
2564
2502
  }
2503
+ if ((_b = config.plugins) == null ? void 0 : _b.length) {
2504
+ for (const plugin of config.plugins) {
2505
+ const PluginClass = plugin;
2506
+ const pluginGenerator = yield PluginClass.create(config.input, project, config);
2507
+ pluginGenerator.generate(outputPath);
2508
+ }
2509
+ console.log(`\u2705 Plugins are generated`);
2510
+ }
2565
2511
  const mainIndexGenerator = new MainIndexGenerator(project, config);
2566
2512
  mainIndexGenerator.generateMainIndex(outputPath);
2567
2513
  const sourceInfo = `from ${inputType}: ${config.input}`;
@@ -2587,7 +2533,29 @@ function generateFromConfig(config) {
2587
2533
  __name(generateFromConfig, "generateFromConfig");
2588
2534
  // Annotate the CommonJS export names for ESM import in node:
2589
2535
  0 && (module.exports = {
2536
+ BASE_INTERCEPTOR_HEADER_COMMENT,
2537
+ HTTP_RESOURCE_GENERATOR_HEADER_COMMENT,
2538
+ MAIN_INDEX_GENERATOR_HEADER_COMMENT,
2539
+ PROVIDER_GENERATOR_HEADER_COMMENT,
2540
+ SERVICE_GENERATOR_HEADER_COMMENT,
2541
+ SERVICE_INDEX_GENERATOR_HEADER_COMMENT,
2590
2542
  SwaggerParser,
2591
- generateFromConfig
2543
+ TYPE_GENERATOR_HEADER_COMMENT,
2544
+ camelCase,
2545
+ collectUsedTypes,
2546
+ escapeString,
2547
+ extractPaths,
2548
+ generateFromConfig,
2549
+ getBasePathTokenName,
2550
+ getClientContextTokenName,
2551
+ getResponseType,
2552
+ getResponseTypeFromResponse,
2553
+ getTypeScriptType,
2554
+ hasDuplicateFunctionNames,
2555
+ inferResponseTypeFromContentType,
2556
+ isPrimitiveType,
2557
+ kebabCase,
2558
+ nullableType,
2559
+ pascalCase
2592
2560
  });
2593
2561
  //# sourceMappingURL=index.js.map