@ng-openapi/http-resource 0.1.3-pr-127-fix-125-sanitize-generated-identifiers-9082a48.0 → 0.1.3

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/index.cjs +84 -710
  2. package/index.d.ts +1 -0
  3. package/index.js +84 -710
  4. package/package.json +1 -1
package/index.cjs CHANGED
@@ -38,238 +38,6 @@ module.exports = __toCommonJS(index_exports);
38
38
  // src/lib/http-resource.generator.ts
39
39
  var import_ts_morph = require("ts-morph");
40
40
 
41
- // ../../shared/src/errors.ts
42
- var NG_OPENAPI_ERROR_BRAND = "__ngOpenApiError";
43
- var ERROR_LINEAGE = /* @__PURE__ */ new WeakMap();
44
- var FALLBACK_LINEAGE = Object.freeze([
45
- "NgOpenApiError"
46
- ]);
47
- function registerError(cls, lineage) {
48
- ERROR_LINEAGE.set(cls, Object.freeze([
49
- ...lineage
50
- ]));
51
- return cls;
52
- }
53
- __name(registerError, "registerError");
54
- function inheritedLineage(cls) {
55
- for (let current = cls; typeof current === "function"; current = Object.getPrototypeOf(current)) {
56
- const lineage = ERROR_LINEAGE.get(current);
57
- if (lineage) {
58
- return lineage;
59
- }
60
- }
61
- return FALLBACK_LINEAGE;
62
- }
63
- __name(inheritedLineage, "inheritedLineage");
64
- var NgOpenApiError = class extends Error {
65
- static {
66
- __name(this, "NgOpenApiError");
67
- }
68
- /** The underlying error that caused this one, when there is one. */
69
- cause;
70
- constructor(message, cause) {
71
- super(message);
72
- const lineage = inheritedLineage(new.target);
73
- this.name = lineage[0];
74
- this.cause = cause;
75
- Object.defineProperty(this, NG_OPENAPI_ERROR_BRAND, {
76
- value: lineage,
77
- enumerable: false,
78
- writable: false,
79
- configurable: false
80
- });
81
- }
82
- /**
83
- * `message` and `name` are non-enumerable on Error, so the default
84
- * JSON.stringify dropped both — the least useful possible serialization for
85
- * something that exists to be logged.
86
- *
87
- * The payload is spread rather than enumerated: `source`, `issues`,
88
- * `operation`, `names` and `placeholders` are why these classes are typed
89
- * in the first place, and listing fields by hand silently drops whichever
90
- * ones a later subclass adds.
91
- */
92
- toJSON() {
93
- const cause = this.cause instanceof Error ? this.cause.message : this.cause;
94
- return {
95
- name: this.name,
96
- message: this.message,
97
- ...cause === void 0 ? {} : {
98
- cause
99
- },
100
- // Own enumerable properties: the brand is deliberately not one.
101
- ...Object.fromEntries(Object.entries(this).filter(([key]) => key !== "cause"))
102
- };
103
- }
104
- /**
105
- * Recognizes branded errors from another bundled copy of this module, so
106
- * `error instanceof SpecLoadError` works for a plugin-thrown error too.
107
- * The prototype chain is checked first, so a caller's own subclass of these
108
- * classes still matches even though it carries no lineage entry.
109
- *
110
- * Never throws and never runs foreign code: both reflective reads sit
111
- * inside the try, because a Proxy traps `getPrototypeOf` just as readily as
112
- * `getOwnPropertyDescriptor`.
113
- */
114
- static [Symbol.hasInstance](value) {
115
- if (typeof value !== "object" || value === null) {
116
- return false;
117
- }
118
- try {
119
- if (Object.prototype.isPrototypeOf.call(this.prototype, value)) {
120
- return true;
121
- }
122
- const expected = ERROR_LINEAGE.get(this)?.[0];
123
- if (expected === void 0) {
124
- return false;
125
- }
126
- const descriptor = Object.getOwnPropertyDescriptor(value, NG_OPENAPI_ERROR_BRAND);
127
- if (!descriptor || descriptor.enumerable || !("value" in descriptor)) {
128
- return false;
129
- }
130
- return Array.isArray(descriptor.value) && descriptor.value.includes(expected);
131
- } catch {
132
- return false;
133
- }
134
- }
135
- };
136
- registerError(NgOpenApiError, [
137
- "NgOpenApiError"
138
- ]);
139
- var SpecLoadError = class extends NgOpenApiError {
140
- static {
141
- __name(this, "SpecLoadError");
142
- }
143
- /** The file path or URL that failed to load. */
144
- source;
145
- constructor(message, source, cause) {
146
- super(message, cause);
147
- this.source = source;
148
- }
149
- };
150
- registerError(SpecLoadError, [
151
- "SpecLoadError",
152
- "NgOpenApiError"
153
- ]);
154
- var SpecParseError = class extends NgOpenApiError {
155
- static {
156
- __name(this, "SpecParseError");
157
- }
158
- /** The file path or URL the content came from, when known. */
159
- source;
160
- constructor(message, source, cause) {
161
- super(message, cause);
162
- this.source = source;
163
- }
164
- };
165
- registerError(SpecParseError, [
166
- "SpecParseError",
167
- "NgOpenApiError"
168
- ]);
169
- function describeOperation(operation) {
170
- const location = `(${operation.method}) ${operation.path}`;
171
- return operation.operationId ? `${operation.operationId} (${location})` : location;
172
- }
173
- __name(describeOperation, "describeOperation");
174
- function captureOperation(operation) {
175
- return Object.freeze({
176
- operationId: operation.operationId,
177
- method: operation.method,
178
- path: operation.path
179
- });
180
- }
181
- __name(captureOperation, "captureOperation");
182
- var InvalidIdentifierError = class extends NgOpenApiError {
183
- static {
184
- __name(this, "InvalidIdentifierError");
185
- }
186
- /** The rejected name, verbatim; absent when no name could be derived. */
187
- identifier;
188
- /** The operation whose name was being derived. */
189
- operation;
190
- constructor(message, operation, identifier) {
191
- super(message);
192
- this.operation = captureOperation(operation);
193
- this.identifier = identifier;
194
- }
195
- };
196
- registerError(InvalidIdentifierError, [
197
- "InvalidIdentifierError",
198
- "NgOpenApiError"
199
- ]);
200
- var DuplicateGeneratedNameError = class extends NgOpenApiError {
201
- static {
202
- __name(this, "DuplicateGeneratedNameError");
203
- }
204
- /** The colliding generated names. */
205
- names;
206
- /** The operations that produced them, when known. */
207
- operations;
208
- constructor(message, names, operations = []) {
209
- super(message);
210
- this.names = Object.freeze([
211
- ...names
212
- ]);
213
- this.operations = Object.freeze(operations.map(captureOperation));
214
- }
215
- };
216
- registerError(DuplicateGeneratedNameError, [
217
- "DuplicateGeneratedNameError",
218
- "NgOpenApiError"
219
- ]);
220
- var UnresolvedPathTemplateError = class extends NgOpenApiError {
221
- static {
222
- __name(this, "UnresolvedPathTemplateError");
223
- }
224
- /** The path as written in the spec. */
225
- path;
226
- /** Placeholder names with no declared parameter. */
227
- placeholders;
228
- constructor(message, path3, placeholders) {
229
- super(message);
230
- this.path = path3;
231
- this.placeholders = Object.freeze([
232
- ...placeholders
233
- ]);
234
- }
235
- };
236
- registerError(UnresolvedPathTemplateError, [
237
- "UnresolvedPathTemplateError",
238
- "NgOpenApiError"
239
- ]);
240
- var ConfigValidationError = class extends NgOpenApiError {
241
- static {
242
- __name(this, "ConfigValidationError");
243
- }
244
- issues;
245
- constructor(issues) {
246
- super(`Invalid ng-openapi configuration:
247
- ${issues.map((issue) => ` - ${issue}`).join("\n")}`);
248
- this.issues = Object.freeze([
249
- ...issues
250
- ]);
251
- }
252
- };
253
- registerError(ConfigValidationError, [
254
- "ConfigValidationError",
255
- "NgOpenApiError"
256
- ]);
257
- var ConfigLoadError = class extends NgOpenApiError {
258
- static {
259
- __name(this, "ConfigLoadError");
260
- }
261
- /** Path of the config file that failed to load. */
262
- source;
263
- constructor(message, source, cause) {
264
- super(message, cause);
265
- this.source = source;
266
- }
267
- };
268
- registerError(ConfigLoadError, [
269
- "ConfigLoadError",
270
- "NgOpenApiError"
271
- ]);
272
-
273
41
  // ../../../node_modules/js-yaml/dist/js-yaml.mjs
274
42
  function isNothing(subject) {
275
43
  return typeof subject === "undefined" || subject === null;
@@ -2972,73 +2740,17 @@ var safeLoad = renamed("safeLoad", "load");
2972
2740
  var safeLoadAll = renamed("safeLoadAll", "loadAll");
2973
2741
  var safeDump = renamed("safeDump", "dump");
2974
2742
 
2975
- // ../../shared/src/utils/content-types.constants.ts
2976
- var CONTENT_TYPES = {
2977
- MULTIPART: "multipart/form-data",
2978
- FORM_URLENCODED: "application/x-www-form-urlencoded",
2979
- JSON: "application/json"
2980
- };
2981
-
2982
- // ../../shared/src/emit/literal.emit.ts
2983
- function quoteLiteral(value) {
2984
- return `'${escapeSingleQuoted(value)}'`;
2985
- }
2986
- __name(quoteLiteral, "quoteLiteral");
2987
- function escapeSingleQuoted(value) {
2988
- return value.replace(/[\\']/g, (char) => `\\${char}`).replace(/\r/g, "\\r").replace(/\n/g, "\\n");
2989
- }
2990
- __name(escapeSingleQuoted, "escapeSingleQuoted");
2991
- function escapeTemplateLiteral(value) {
2992
- return value.replace(/[\\`]/g, (char) => `\\${char}`).replace(/\$\{/g, "\\${").replace(/\r/g, "\\r");
2993
- }
2994
- __name(escapeTemplateLiteral, "escapeTemplateLiteral");
2995
- function emitObjectKey(name, quoteStyle = "double") {
2996
- const quoted = quoteStyle === "single" ? quoteLiteral(name) : `"${escapeDoubleQuoted(name)}"`;
2997
- return name === "__proto__" ? `[${quoted}]` : quoted;
2998
- }
2999
- __name(emitObjectKey, "emitObjectKey");
3000
- function escapeDoubleQuoted(value) {
3001
- return value.replace(/[\\"]/g, (char) => `\\${char}`).replace(/\r/g, "\\r").replace(/\n/g, "\\n");
3002
- }
3003
- __name(escapeDoubleQuoted, "escapeDoubleQuoted");
3004
- function escapeJsDoc(text) {
3005
- return text.replace(/\*\//g, "*\\/");
3006
- }
3007
- __name(escapeJsDoc, "escapeJsDoc");
3008
- function emitDocs(description) {
3009
- return typeof description === "string" && description ? [
3010
- escapeJsDoc(description)
3011
- ] : void 0;
3012
- }
3013
- __name(emitDocs, "emitDocs");
3014
-
3015
2743
  // ../../shared/src/utils/string.utils.ts
3016
- var IDENTIFIER_SEPARATORS = /(?:_|[^\p{ID_Continue}$])+(.)?/gu;
3017
- var INVALID_IDENTIFIER_START = /^[^\p{ID_Start}$_]/u;
3018
- function toIdentifier(converted) {
3019
- if (converted === "") {
3020
- return "_";
3021
- }
3022
- return converted.replace(INVALID_IDENTIFIER_START, (char) => `_${char}`);
3023
- }
3024
- __name(toIdentifier, "toIdentifier");
3025
- function isValidIdentifier(name) {
3026
- return /^[\p{ID_Start}$_][\p{ID_Continue}$]*$/u.test(name);
3027
- }
3028
- __name(isValidIdentifier, "isValidIdentifier");
3029
2744
  function camelCase(str2) {
3030
- const converted = str2.replace(IDENTIFIER_SEPARATORS, (_, char) => char ? char.toUpperCase() : "").replace(/^./u, (char) => char.toLowerCase());
3031
- return toIdentifier(converted);
2745
+ return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
3032
2746
  }
3033
2747
  __name(camelCase, "camelCase");
3034
2748
  function pascalCase(str2) {
3035
- const converted = str2.replace(IDENTIFIER_SEPARATORS, (_, char) => char ? char.toUpperCase() : "").replace(/^./u, (char) => char.toUpperCase());
3036
- return toIdentifier(converted);
2749
+ return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
3037
2750
  }
3038
2751
  __name(pascalCase, "pascalCase");
3039
2752
  function pascalCaseForEnums(str2) {
3040
- const converted = str2.replace(/[^a-zA-Z0-9]/g, "_").replace(/(?:^|_)([a-z])/g, (_, char) => char.toUpperCase()).replace(/^([0-9])/, "_$1");
3041
- return converted === "" ? "_" : converted;
2753
+ return str2.replace(/[^a-zA-Z0-9]/g, "_").replace(/(?:^|_)([a-z])/g, (_, char) => char.toUpperCase()).replace(/^([0-9])/, "_$1");
3042
2754
  }
3043
2755
  __name(pascalCaseForEnums, "pascalCaseForEnums");
3044
2756
 
@@ -3084,7 +2796,7 @@ function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, c
3084
2796
  switch (schema2.type) {
3085
2797
  case "string":
3086
2798
  if (schema2.enum) {
3087
- return schema2.enum.map((value) => typeof value === "string" ? `'${escapeSingleQuoted(value)}'` : String(value)).join(" | ");
2799
+ return schema2.enum.map((value) => typeof value === "string" ? `'${escapeString2(value)}'` : String(value)).join(" | ");
3088
2800
  }
3089
2801
  if (schema2.format === "date" || schema2.format === "date-time") {
3090
2802
  const dateType = config.options.dateType === "Date" ? "Date" : "string";
@@ -3120,6 +2832,10 @@ function nullableType(type2, isNullable) {
3120
2832
  return type2 + (isNullable ? " | null" : "");
3121
2833
  }
3122
2834
  __name(nullableType, "nullableType");
2835
+ function escapeString2(str2) {
2836
+ return str2.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
2837
+ }
2838
+ __name(escapeString2, "escapeString");
3123
2839
 
3124
2840
  // ../../shared/src/utils/functions/extract-swagger-response-type.ts
3125
2841
  function getResponseTypeFromResponse(response, responseTypeMapping) {
@@ -3268,7 +2984,7 @@ __name(getResponseType, "getResponseType");
3268
2984
 
3269
2985
  // ../../shared/src/emit/headers.emit.ts
3270
2986
  function emitDefaultHeadersMerge(optionsExpression, customHeaders) {
3271
- const defaultsLiteral = Object.entries(customHeaders).map(([key, value]) => `${emitObjectKey(key, "single")}: ${quoteLiteral(value)}`).join(", ");
2987
+ const defaultsLiteral = Object.entries(customHeaders).map(([key, value]) => `'${key}': '${value}'`).join(", ");
3272
2988
  return `
3273
2989
  // Add default headers if not already present
3274
2990
  let headers = ${optionsExpression}?.headers;
@@ -3280,238 +2996,12 @@ ${emitDefaultHeaderGuards(customHeaders)}
3280
2996
  }
3281
2997
  __name(emitDefaultHeadersMerge, "emitDefaultHeadersMerge");
3282
2998
  function emitDefaultHeaderGuards(customHeaders) {
3283
- return Object.entries(customHeaders).map(([key, value]) => {
3284
- const name = quoteLiteral(key);
3285
- return `if (!headers.has(${name})) {
3286
- headers = headers.set(${name}, ${quoteLiteral(value)});
3287
- }`;
3288
- }).join("\n");
2999
+ return Object.entries(customHeaders).map(([key, value]) => `if (!headers.has('${key}')) {
3000
+ headers = headers.set('${key}', '${value}');
3001
+ }`).join("\n");
3289
3002
  }
3290
3003
  __name(emitDefaultHeaderGuards, "emitDefaultHeaderGuards");
3291
3004
 
3292
- // ../../shared/src/utils/functions/get-request-body-type.ts
3293
- function getRequestBodyType(requestBody, config) {
3294
- const content = requestBody.content || {};
3295
- const jsonContent = content[CONTENT_TYPES.JSON];
3296
- if (jsonContent?.schema) {
3297
- return getTypeScriptType(jsonContent.schema, config, jsonContent.schema.nullable);
3298
- }
3299
- return "any";
3300
- }
3301
- __name(getRequestBodyType, "getRequestBodyType");
3302
-
3303
- // ../../shared/src/utils/functions/is-data-type-interface.ts
3304
- function isDataTypeInterface(type2) {
3305
- const invalidTypes = [
3306
- "any",
3307
- "File",
3308
- "string",
3309
- "number",
3310
- "boolean",
3311
- "object",
3312
- "unknown",
3313
- "[]",
3314
- "Array"
3315
- ];
3316
- return !invalidTypes.some((invalidType) => type2.includes(invalidType));
3317
- }
3318
- __name(isDataTypeInterface, "isDataTypeInterface");
3319
-
3320
- // ../../shared/src/utils/functions/argument-names.ts
3321
- var RESERVED_WORDS = [
3322
- "arguments",
3323
- "await",
3324
- "break",
3325
- "case",
3326
- "catch",
3327
- "class",
3328
- "const",
3329
- "continue",
3330
- "debugger",
3331
- "default",
3332
- "delete",
3333
- "do",
3334
- "else",
3335
- "enum",
3336
- "eval",
3337
- "export",
3338
- "extends",
3339
- "false",
3340
- "finally",
3341
- "for",
3342
- "function",
3343
- "if",
3344
- "implements",
3345
- "import",
3346
- "in",
3347
- "instanceof",
3348
- "interface",
3349
- "let",
3350
- "new",
3351
- "null",
3352
- "package",
3353
- "private",
3354
- "protected",
3355
- "public",
3356
- "return",
3357
- "static",
3358
- "super",
3359
- "switch",
3360
- "this",
3361
- "throw",
3362
- "true",
3363
- "try",
3364
- "typeof",
3365
- "var",
3366
- "void",
3367
- "while",
3368
- "with",
3369
- "yield"
3370
- ];
3371
- var SERVICE_ARGUMENT_PROFILE = Object.freeze({
3372
- reserved: Object.freeze([
3373
- "observe",
3374
- "options",
3375
- "url",
3376
- "params",
3377
- "headers",
3378
- "formData",
3379
- "formBody"
3380
- ]),
3381
- bindsRequestBody: true
3382
- });
3383
- var RESOURCE_ARGUMENT_PROFILE = Object.freeze({
3384
- reserved: Object.freeze([
3385
- "resourceOptions",
3386
- "requestOptions",
3387
- "params",
3388
- "headers"
3389
- ]),
3390
- bindsRequestBody: false
3391
- });
3392
- var REQUEST_BODY_KEY = /* @__PURE__ */ Symbol("requestBody");
3393
- function resolveArgumentNames(operation, config, profile) {
3394
- let byConfig = RESOLVED.get(operation);
3395
- if (!byConfig) {
3396
- byConfig = /* @__PURE__ */ new WeakMap();
3397
- RESOLVED.set(operation, byConfig);
3398
- }
3399
- let byProfile = byConfig.get(config);
3400
- if (!byProfile) {
3401
- byProfile = /* @__PURE__ */ new WeakMap();
3402
- byConfig.set(config, byProfile);
3403
- }
3404
- const cached = byProfile.get(profile);
3405
- if (cached) {
3406
- return cached;
3407
- }
3408
- const resolved = computeArgumentNames(operation, config, profile);
3409
- byProfile.set(profile, resolved);
3410
- return resolved;
3411
- }
3412
- __name(resolveArgumentNames, "resolveArgumentNames");
3413
- var RESOLVED = /* @__PURE__ */ new WeakMap();
3414
- function computeArgumentNames(operation, config, profile) {
3415
- const entries = [
3416
- ...operation.pathParams.map((param) => ({
3417
- key: param.name,
3418
- base: camelCase(param.name)
3419
- })),
3420
- ...operation.formDataFields.map((field) => ({
3421
- key: field,
3422
- base: camelCase(field)
3423
- })),
3424
- ...operation.urlEncodedFields.map((field) => ({
3425
- key: field,
3426
- base: camelCase(field)
3427
- }))
3428
- ];
3429
- const bodyBase = profile.bindsRequestBody ? jsonBodyIdentifier(operation, config) : void 0;
3430
- if (bodyBase !== void 0) {
3431
- entries.push({
3432
- key: REQUEST_BODY_KEY,
3433
- base: bodyBase
3434
- });
3435
- }
3436
- entries.push(...operation.queryParams.map((param) => ({
3437
- key: param.name,
3438
- base: camelCase(param.name)
3439
- })));
3440
- const identifiers = /* @__PURE__ */ new Map();
3441
- const used = /* @__PURE__ */ new Set([
3442
- ...profile.reserved,
3443
- ...RESERVED_WORDS
3444
- ]);
3445
- const renamed2 = [];
3446
- const merged = /* @__PURE__ */ new Set();
3447
- for (const { key, base } of entries) {
3448
- if (identifiers.has(key)) {
3449
- if (typeof key === "string") {
3450
- merged.add(key);
3451
- }
3452
- continue;
3453
- }
3454
- let identifier = base;
3455
- let suffix = 2;
3456
- while (used.has(identifier)) {
3457
- identifier = `${base}${suffix}`;
3458
- suffix++;
3459
- }
3460
- if (identifier !== base) {
3461
- renamed2.push(Object.freeze({
3462
- source: typeof key === "string" ? key : base,
3463
- identifier
3464
- }));
3465
- }
3466
- used.add(identifier);
3467
- identifiers.set(key, identifier);
3468
- }
3469
- return {
3470
- // The fallback runs the *same* rules the resolver would have, rather
3471
- // than a bare camelCase: an unregistered wire name otherwise came back
3472
- // as `class` or `options`, names the resolver never assigns.
3473
- // Uniquified against everything already assigned, not just the reserved
3474
- // words: an unregistered wire name that camelCases onto an identifier
3475
- // this operation already bound would otherwise alias it — compiling
3476
- // fine and sending the wrong value. Only reachable for operations built
3477
- // outside the normalizer, but the resolver is public API.
3478
- of: /* @__PURE__ */ __name((wireName) => identifiers.get(wireName) ?? deriveLocalName(camelCase(wireName), [
3479
- ...used
3480
- ]), "of"),
3481
- body: identifiers.get(REQUEST_BODY_KEY),
3482
- all: Object.freeze([
3483
- ...identifiers.values()
3484
- ]),
3485
- renamed: Object.freeze(renamed2),
3486
- merged: Object.freeze([
3487
- ...merged
3488
- ])
3489
- };
3490
- }
3491
- __name(computeArgumentNames, "computeArgumentNames");
3492
- function jsonBodyIdentifier(operation, config) {
3493
- if (!operation.requestBody || operation.isMultipart) {
3494
- return void 0;
3495
- }
3496
- if (!operation.requestBody.content?.[CONTENT_TYPES.JSON]) {
3497
- return void 0;
3498
- }
3499
- const bodyType = getRequestBodyType(operation.requestBody, config);
3500
- return isDataTypeInterface(bodyType) ? camelCase(bodyType) : "requestBody";
3501
- }
3502
- __name(jsonBodyIdentifier, "jsonBodyIdentifier");
3503
- function deriveLocalName(base, taken) {
3504
- const used = new Set(taken);
3505
- let name = base;
3506
- let suffix = 2;
3507
- while (used.has(name)) {
3508
- name = `${base}${suffix}`;
3509
- suffix++;
3510
- }
3511
- return name;
3512
- }
3513
- __name(deriveLocalName, "deriveLocalName");
3514
-
3515
3005
  // ../../shared/src/emit/url.emit.ts
3516
3006
  function plainParamValue(identifier) {
3517
3007
  return identifier;
@@ -3521,34 +3011,24 @@ function signalAwareParamValue(identifier) {
3521
3011
  return `typeof ${identifier} === 'function' ? ${identifier}() : ${identifier}`;
3522
3012
  }
3523
3013
  __name(signalAwareParamValue, "signalAwareParamValue");
3524
- function emitUrlExpression(path3, pathParams, argumentNames, paramValue = plainParamValue) {
3525
- const declared = new Set(pathParams.map((param) => param.name));
3526
- const unresolved = (path3.match(/{([^{}]*)}/g) ?? []).map((placeholder) => placeholder.slice(1, -1)).filter((name) => !declared.has(name));
3527
- if (unresolved.length > 0) {
3528
- throw new UnresolvedPathTemplateError(`Path "${path3}" declares no parameter for ${unresolved.map((name) => `{${name}}`).join(", ")}. Declare each placeholder as a path parameter, or remove it from the path.`, path3, unresolved);
3529
- }
3530
- let urlExpression = "`${this.basePath}" + escapeTemplateLiteral(path3) + "`";
3014
+ function emitUrlExpression(path3, pathParams, paramValue = plainParamValue) {
3015
+ let urlExpression = `\`\${this.basePath}${path3}\``;
3531
3016
  pathParams.forEach((param) => {
3532
- const replacement = "${" + paramValue(argumentNames.of(param.name)) + "}";
3533
- urlExpression = urlExpression.split(`{${escapeTemplateLiteral(param.name)}}`).join(replacement);
3017
+ urlExpression = urlExpression.replace(`{${param.name}}`, `\${${paramValue(camelCase(param.name))}}`);
3534
3018
  });
3535
3019
  return urlExpression;
3536
3020
  }
3537
3021
  __name(emitUrlExpression, "emitUrlExpression");
3538
3022
 
3539
3023
  // ../../shared/src/emit/query-params.emit.ts
3540
- function emitSignalAwareQueryParams(queryParams, argumentNames) {
3024
+ function emitSignalAwareQueryParams(queryParams) {
3541
3025
  if (queryParams.length === 0) {
3542
3026
  return "";
3543
3027
  }
3544
- const paramMappings = queryParams.map((param) => {
3545
- const identifier = argumentNames.of(param.name);
3546
- const local = deriveLocalName(`${identifier}Value`, argumentNames.all);
3547
- return `const ${local} = ${signalAwareParamValue(identifier)};
3548
- if (${local} != null) {
3549
- params = HttpParamsBuilder.addToHttpParams(params, ${local}, ${quoteLiteral(param.name)});
3550
- }`;
3551
- }).join("\n");
3028
+ const paramMappings = queryParams.map((param) => `const ${camelCase(param.name)}Value = ${signalAwareParamValue(camelCase(param.name))};
3029
+ if (${camelCase(param.name)}Value != null) {
3030
+ params = HttpParamsBuilder.addToHttpParams(params, ${camelCase(param.name)}Value, '${param.name}');
3031
+ }`).join("\n");
3552
3032
  return `
3553
3033
  let params = new HttpParams();
3554
3034
  ${paramMappings}`;
@@ -3595,149 +3075,22 @@ function listGeneratedFileNames(project, directoryPath, suffix) {
3595
3075
  __name(listGeneratedFileNames, "listGeneratedFileNames");
3596
3076
 
3597
3077
  // ../../shared/src/utils/functions/token-names.ts
3598
- function effectiveClientName(clientName) {
3599
- return clientName ? clientName : "default";
3600
- }
3601
- __name(effectiveClientName, "effectiveClientName");
3602
- function tokenSuffix(clientName) {
3603
- return effectiveClientName(clientName).toUpperCase().replace(/[^A-Z0-9]/g, "_");
3604
- }
3605
- __name(tokenSuffix, "tokenSuffix");
3606
- function getClientContextTokenName(clientName) {
3607
- const clientSuffix = tokenSuffix(clientName);
3078
+ function getClientContextTokenName(clientName = "default") {
3079
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
3608
3080
  return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
3609
3081
  }
3610
3082
  __name(getClientContextTokenName, "getClientContextTokenName");
3611
- function getBasePathTokenName(clientName) {
3612
- const clientSuffix = tokenSuffix(clientName);
3083
+ function getBasePathTokenName(clientName = "default") {
3084
+ const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
3613
3085
  return `BASE_PATH_${clientSuffix}`;
3614
3086
  }
3615
3087
  __name(getBasePathTokenName, "getBasePathTokenName");
3616
3088
 
3617
- // ../../shared/src/utils/functions/controller-groups.ts
3618
- function groupOperationsByController(operations, onWarning) {
3619
- const groups = {};
3620
- const controllerByFold = /* @__PURE__ */ new Map();
3621
- const tagSpellings = /* @__PURE__ */ new Map();
3622
- const namelessTags = /* @__PURE__ */ new Set();
3623
- operations.forEach((operation) => {
3624
- const tag = operation.tags?.[0];
3625
- let rawName = "Default";
3626
- if (tag !== void 0) {
3627
- rawName = tag;
3628
- } else {
3629
- const pathParts = operation.path.split("/").filter((part) => part && !part.startsWith("{"));
3630
- if (pathParts.length > 1) {
3631
- rawName = pathParts[1];
3632
- }
3633
- }
3634
- const sanitized = pascalCase(rawName);
3635
- const isNameless = !/\p{L}/u.test(sanitized);
3636
- const candidate = isNameless ? "Default" : sanitized;
3637
- const fold = candidate.toLowerCase();
3638
- const controllerName = controllerByFold.get(fold) ?? candidate;
3639
- controllerByFold.set(fold, controllerName);
3640
- if (tag !== void 0 && isNameless) {
3641
- namelessTags.add(tag);
3642
- } else if (tag !== void 0) {
3643
- const spellings = tagSpellings.get(controllerName) ?? /* @__PURE__ */ new Set();
3644
- spellings.add(tag);
3645
- tagSpellings.set(controllerName, spellings);
3646
- }
3647
- if (!groups[controllerName]) {
3648
- groups[controllerName] = [];
3649
- }
3650
- groups[controllerName].push(operation);
3651
- });
3652
- for (const tag of namelessTags) {
3653
- onWarning?.(`Tag "${tag}" contains no characters usable in a name \u2014 its operations are generated into the "Default" controller. Rename the tag to give them a file of their own.`);
3654
- }
3655
- for (const [controllerName, spellings] of tagSpellings) {
3656
- if (spellings.size > 1) {
3657
- onWarning?.(`Tags ${[
3658
- ...spellings
3659
- ].map((name) => `"${name}"`).join(" and ")} all map to the controller "${controllerName}" \u2014 their operations are generated into one file. Rename one tag to keep them apart.`);
3660
- }
3661
- }
3662
- return groups;
3663
- }
3664
- __name(groupOperationsByController, "groupOperationsByController");
3665
-
3666
- // ../../shared/src/utils/functions/method-names.ts
3667
- var RESERVED_MEMBER_NAMES = Object.freeze([
3668
- "constructor",
3669
- "httpClient",
3670
- "basePath",
3671
- "clientContextToken",
3672
- "createContextWithClientId"
3673
- ]);
3674
- var RESERVED_MEMBER_SET = new Set(RESERVED_MEMBER_NAMES);
3675
- function reservedMemberCollision(operation, config) {
3676
- if (config.options.customizeMethodName || !operation.operationId) {
3677
- return void 0;
3678
- }
3679
- const natural = camelCase(operation.operationId);
3680
- return RESERVED_MEMBER_SET.has(natural) ? {
3681
- from: natural,
3682
- to: `_${natural}`
3683
- } : void 0;
3089
+ // ../../shared/src/utils/functions/duplicate-function-name.ts
3090
+ function hasDuplicateFunctionNames(arr) {
3091
+ return new Set(arr.map((fn) => fn.getName())).size !== arr.length;
3684
3092
  }
3685
- __name(reservedMemberCollision, "reservedMemberCollision");
3686
- function getOperationMethodName(operation, config) {
3687
- const customize = config.options.customizeMethodName;
3688
- if (!customize) {
3689
- return defaultOperationMethodName(operation);
3690
- }
3691
- if (operation.operationId == null) {
3692
- throw new InvalidIdentifierError(`customizeMethodName needs an operationId, and ${describeOperation(operation)} has none. Add one to the spec, or drop customizeMethodName to use the derived name.`, operation);
3693
- }
3694
- const customName = customize(operation.operationId);
3695
- if (!isValidIdentifier(customName) || RESERVED_MEMBER_SET.has(customName)) {
3696
- throw new InvalidIdentifierError(`customizeMethodName returned "${customName}" for ${describeOperation(operation)}, which is not a usable TypeScript method name. Return an identifier \u2014 letters, digits, "_" and "$", not starting with a digit \u2014 and not one of ${RESERVED_MEMBER_NAMES.map((name) => `"${name}"`).join(", ")}.`, operation, customName);
3697
- }
3698
- return customName;
3699
- }
3700
- __name(getOperationMethodName, "getOperationMethodName");
3701
- function defaultOperationMethodName(operation) {
3702
- if (operation.operationId) {
3703
- const name = camelCase(operation.operationId);
3704
- return RESERVED_MEMBER_SET.has(name) ? `_${name}` : name;
3705
- }
3706
- const method = pascalCase(operation.method.toLowerCase());
3707
- const pathParts = operation.path.split("/").filter((segment) => segment !== "").map((segment) => pascalCase(segment));
3708
- const resource = pathParts.join("") || "resource";
3709
- return `${camelCase(resource)}${method}`;
3710
- }
3711
- __name(defaultOperationMethodName, "defaultOperationMethodName");
3712
-
3713
- // ../../shared/src/utils/functions/distinct-member-names.ts
3714
- function assertDistinctMemberNames(serviceClass, className, operations, methodNameOf) {
3715
- const methodNames = serviceClass.getMethods().map((method) => method.getName());
3716
- const propertyNames = new Set(serviceClass.getProperties().map((property) => property.getName()));
3717
- const duplicates = [
3718
- ...new Set(methodNames.filter((name, index) => methodNames.indexOf(name) !== index || propertyNames.has(name)))
3719
- ];
3720
- if (duplicates.length === 0) {
3721
- return;
3722
- }
3723
- const byName = new Map(duplicates.map((name) => [
3724
- name,
3725
- []
3726
- ]));
3727
- for (const operation of operations) {
3728
- byName.get(methodNameOf(operation))?.push(operation);
3729
- }
3730
- const detail = [
3731
- ...byName
3732
- ].map(([name, ops]) => {
3733
- const from = ops.map(describeOperation).join(" and ");
3734
- return propertyNames.has(name) ? `"${name}" from ${from} (a property of ${className})` : `"${name}" from ${from}`;
3735
- }).join("; ");
3736
- throw new DuplicateGeneratedNameError(`Operations map to the same member name in ${className}: ${detail}. Ensure each operationId maps to a unique name.`, duplicates, [
3737
- ...byName.values()
3738
- ].flat());
3739
- }
3740
- __name(assertDistinctMemberNames, "assertDistinctMemberNames");
3093
+ __name(hasDuplicateFunctionNames, "hasDuplicateFunctionNames");
3741
3094
 
3742
3095
  // ../../shared/src/config/constants.ts
3743
3096
  var disableLinting = `// @ts-nocheck
@@ -3790,14 +3143,6 @@ var HttpResourceMethodBodyGenerator = class {
3790
3143
  constructor(config) {
3791
3144
  this.config = config;
3792
3145
  }
3793
- /**
3794
- * The plugin reserves its own bindings (`resourceOptions`/`requestOptions`),
3795
- * not the core service's — resolving against the wrong set would let a
3796
- * `requestOptions` query parameter capture the plugin's own parameter.
3797
- */
3798
- argumentNames(operation) {
3799
- return resolveArgumentNames(operation, this.config, RESOURCE_ARGUMENT_PROFILE);
3800
- }
3801
3146
  generateMethodBody(operation) {
3802
3147
  const bodyParts = [
3803
3148
  this.generateDefaultHeaders(operation),
@@ -3829,7 +3174,7 @@ var HttpResourceMethodBodyGenerator = class {
3829
3174
  }
3830
3175
  generateRequestOptions(operation) {
3831
3176
  const entries = [];
3832
- const url = emitUrlExpression(operation.path, operation.pathParams, this.argumentNames(operation), signalAwareParamValue);
3177
+ const url = emitUrlExpression(operation.path, operation.pathParams, signalAwareParamValue);
3833
3178
  entries.push(`url: ${url}`);
3834
3179
  entries.push(`method: "GET"`);
3835
3180
  entries.push("...requestOptions");
@@ -3847,7 +3192,7 @@ var HttpResourceMethodBodyGenerator = class {
3847
3192
  }
3848
3193
  generateHttpResource(operation) {
3849
3194
  const resourceOptions = this.generateRequestOptions(operation);
3850
- const queryParams = emitSignalAwareQueryParams(operation.queryParams, this.argumentNames(operation));
3195
+ const queryParams = emitSignalAwareQueryParams(operation.queryParams);
3851
3196
  let httpResource = "httpResource";
3852
3197
  switch (operation.responseType) {
3853
3198
  case "blob":
@@ -3895,14 +3240,13 @@ var HttpResourceMethodParamsGenerator = class {
3895
3240
  }
3896
3241
  generateApiParameters(operation) {
3897
3242
  const params = [];
3898
- const argumentNames = resolveArgumentNames(operation, this.config, RESOURCE_ARGUMENT_PROFILE);
3899
3243
  operation.pathParams.forEach((param) => {
3900
3244
  const paramType = getTypeScriptType(param.schema || {
3901
3245
  ...param
3902
3246
  }, this.config);
3903
3247
  const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
3904
3248
  params.push({
3905
- name: argumentNames.of(param.name),
3249
+ name: camelCase(param.name),
3906
3250
  type: `${signalParamType} | ${paramType}`,
3907
3251
  hasQuestionToken: !param.required
3908
3252
  });
@@ -3913,7 +3257,7 @@ var HttpResourceMethodParamsGenerator = class {
3913
3257
  }, this.config);
3914
3258
  const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
3915
3259
  params.push({
3916
- name: argumentNames.of(param.name),
3260
+ name: camelCase(param.name),
3917
3261
  type: `${signalParamType} | ${paramType}`,
3918
3262
  hasQuestionToken: !param.required
3919
3263
  });
@@ -3984,11 +3328,31 @@ var HttpResourceMethodGenerator = class {
3984
3328
  returnType,
3985
3329
  statements: methodBody,
3986
3330
  overloads,
3987
- docs: emitDocs(operation.description)
3331
+ docs: operation.description ? [
3332
+ operation.description
3333
+ ] : void 0
3988
3334
  });
3989
3335
  }
3990
3336
  generateMethodName(operation) {
3991
- return getOperationMethodName(operation, this.config);
3337
+ if (this.config.options.customizeMethodName) {
3338
+ if (operation.operationId == null) {
3339
+ throw new Error(`Operation ID is required for method name customization of operation: (${operation.method}) ${operation.path}`);
3340
+ }
3341
+ return this.config.options.customizeMethodName(operation.operationId);
3342
+ } else {
3343
+ return this.defaultNameGenerator(operation);
3344
+ }
3345
+ }
3346
+ defaultNameGenerator(operation) {
3347
+ if (operation.operationId) {
3348
+ return camelCase(operation.operationId);
3349
+ }
3350
+ const method = pascalCase(operation.method.toLowerCase());
3351
+ const pathParts = operation.path.split("/").map((str2) => {
3352
+ return pascalCase(pascalCase(str2).replace(/[^a-zA-Z0-9]/g, ""));
3353
+ });
3354
+ const resource = pathParts.join("") || "resource";
3355
+ return `${camelCase(resource)}${method}`;
3992
3356
  }
3993
3357
  generateReturnType(operation) {
3994
3358
  const response = operation.responses?.["200"] || operation.responses?.["201"] || operation.responses?.["204"];
@@ -4063,6 +3427,7 @@ var HttpResourceIndexGenerator = class {
4063
3427
  });
4064
3428
  });
4065
3429
  sourceFile.formatText();
3430
+ sourceFile.saveSync();
4066
3431
  }
4067
3432
  };
4068
3433
 
@@ -4092,15 +3457,32 @@ var HttpResourceGenerator = class {
4092
3457
  this.onWarning?.("No API paths found in the specification");
4093
3458
  return;
4094
3459
  }
4095
- const controllerGroups = groupOperationsByController(paths, this.onWarning);
4096
- await Promise.all(
4097
- // Must return the promise: without it Promise.all awaits [undefined],
4098
- // and a generateServiceFile rejection escapes as an unhandled
4099
- // rejection while generation reports success.
4100
- Object.entries(controllerGroups).map(([controllerName, operations]) => this.generateServiceFile(controllerName, operations, outputDir))
4101
- );
3460
+ const controllerGroups = this.groupPathsByController(paths);
3461
+ await Promise.all(Object.entries(controllerGroups).map(([controllerName, operations]) => {
3462
+ this.generateServiceFile(controllerName, operations, outputDir);
3463
+ }));
4102
3464
  this.indexGenerator.generateIndex(outputRoot);
4103
3465
  }
3466
+ groupPathsByController(paths) {
3467
+ const groups = {};
3468
+ paths.forEach((path3) => {
3469
+ let controllerName = "Default";
3470
+ if (path3.tags && path3.tags.length > 0) {
3471
+ controllerName = path3.tags[0];
3472
+ } else {
3473
+ const pathParts = path3.path.split("/").filter((p) => p && !p.startsWith("{"));
3474
+ if (pathParts.length > 1) {
3475
+ controllerName = pascalCase(pathParts[1]);
3476
+ }
3477
+ }
3478
+ controllerName = pascalCase(controllerName);
3479
+ if (!groups[controllerName]) {
3480
+ groups[controllerName] = [];
3481
+ }
3482
+ groups[controllerName].push(path3);
3483
+ });
3484
+ return groups;
3485
+ }
4104
3486
  async generateServiceFile(controllerName, operations, outputDir) {
4105
3487
  const fileName = `${camelCase(controllerName)}.resource.ts`;
4106
3488
  const filePath = path2.join(outputDir, fileName);
@@ -4110,6 +3492,7 @@ var HttpResourceGenerator = class {
4110
3492
  this.addServiceClass(sourceFile, controllerName, operations);
4111
3493
  sourceFile.fixMissingImports().formatText();
4112
3494
  sourceFile.insertText(0, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT(getResourceClassName(controllerName, this.config.options.naming?.resources)));
3495
+ sourceFile.saveSync();
4113
3496
  }
4114
3497
  addServiceClass(sourceFile, controllerName, operations) {
4115
3498
  const className = getResourceClassName(controllerName, this.config.options.naming?.resources);
@@ -4185,23 +3568,14 @@ var HttpResourceGenerator = class {
4185
3568
  ],
4186
3569
  returnType: "HttpContext",
4187
3570
  statements: `const context = existingContext || new HttpContext();
4188
- return context.set(this.clientContextToken, ${quoteLiteral(effectiveClientName(this.config.clientName))});`
3571
+ return context.set(this.clientContextToken, '${this.config.clientName || "default"}');`
4189
3572
  });
4190
3573
  operations.forEach((operation) => {
4191
- const { renamed: renamed2, merged } = resolveArgumentNames(operation, this.config, RESOURCE_ARGUMENT_PROFILE);
4192
- for (const { source, identifier } of renamed2) {
4193
- this.onWarning?.(`Parameter "${source}" of ${describeOperation(operation)} is exposed as "${identifier}" \u2014 its natural name is already taken by another parameter or by the resource method itself.`);
4194
- }
4195
- for (const wireName of merged) {
4196
- this.onWarning?.(`Parameter "${wireName}" of ${describeOperation(operation)} is declared in more than one location; they collapse into one argument, so the first declaration's type wins and the same value is sent for both.`);
4197
- }
4198
- const collision = reservedMemberCollision(operation, this.config);
4199
- if (collision) {
4200
- this.onWarning?.(`Operation ${describeOperation(operation)} would be named "${collision.from}", which the generated class already binds \u2014 it is emitted as "${collision.to}". Rename the operationId to choose the name.`);
4201
- }
4202
3574
  this.methodGenerator.addResourceMethod(serviceClass, operation);
4203
3575
  });
4204
- assertDistinctMemberNames(serviceClass, className, operations, (op) => this.methodGenerator.generateMethodName(op));
3576
+ if (hasDuplicateFunctionNames(serviceClass.getMethods())) {
3577
+ throw new Error(`Duplicate method names found in service class ${className}. Please ensure unique method names for each operation.`);
3578
+ }
4205
3579
  }
4206
3580
  };
4207
3581
  // Annotate the CommonJS export names for ESM import in node: