@ng-openapi/http-resource 0.0.34-pr-85-testing-25e3627.0 → 0.0.34-pr-103-refactored-d262edf.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.
- package/index.cjs +440 -486
- package/index.d.ts +157 -29
- package/index.js +440 -486
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -38,330 +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/utils/string.utils.ts
|
|
42
|
-
function camelCase(str2) {
|
|
43
|
-
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
44
|
-
}
|
|
45
|
-
__name(camelCase, "camelCase");
|
|
46
|
-
function pascalCase(str2) {
|
|
47
|
-
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
48
|
-
}
|
|
49
|
-
__name(pascalCase, "pascalCase");
|
|
50
|
-
function pascalCaseForEnums(str2) {
|
|
51
|
-
return str2.replace(/[^a-zA-Z0-9]/g, "_").replace(/(?:^|_)([a-z])/g, (_, char) => char.toUpperCase()).replace(/^([0-9])/, "_$1");
|
|
52
|
-
}
|
|
53
|
-
__name(pascalCaseForEnums, "pascalCaseForEnums");
|
|
54
|
-
|
|
55
|
-
// ../../shared/src/utils/type.utils.ts
|
|
56
|
-
function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, context = "type") {
|
|
57
|
-
let schema2;
|
|
58
|
-
let nullable;
|
|
59
|
-
if (typeof schemaOrType === "string" || schemaOrType === void 0) {
|
|
60
|
-
schema2 = {
|
|
61
|
-
type: schemaOrType,
|
|
62
|
-
format: typeof formatOrNullable === "string" ? formatOrNullable : void 0
|
|
63
|
-
};
|
|
64
|
-
nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : isNullable;
|
|
65
|
-
} else {
|
|
66
|
-
schema2 = schemaOrType;
|
|
67
|
-
nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : schema2.nullable;
|
|
68
|
-
}
|
|
69
|
-
if (!schema2) {
|
|
70
|
-
return "any";
|
|
71
|
-
}
|
|
72
|
-
if (schema2.$ref) {
|
|
73
|
-
const refName = schema2.$ref.split("/").pop();
|
|
74
|
-
return nullableType(pascalCaseForEnums(refName), nullable);
|
|
75
|
-
}
|
|
76
|
-
if (schema2.type === "array") {
|
|
77
|
-
const itemType = schema2.items ? getTypeScriptType(schema2.items, config, void 0, void 0, context) : "unknown";
|
|
78
|
-
return nullable ? `(Array<${itemType}> | null)` : `Array<${itemType}>`;
|
|
79
|
-
}
|
|
80
|
-
switch (schema2.type) {
|
|
81
|
-
case "string":
|
|
82
|
-
if (schema2.enum) {
|
|
83
|
-
return schema2.enum.map((value) => typeof value === "string" ? `'${escapeString(value)}'` : String(value)).join(" | ");
|
|
84
|
-
}
|
|
85
|
-
if (schema2.format === "date" || schema2.format === "date-time") {
|
|
86
|
-
const dateType = config.options.dateType === "Date" ? "Date" : "string";
|
|
87
|
-
return nullableType(dateType, nullable);
|
|
88
|
-
}
|
|
89
|
-
if (schema2.format === "binary") {
|
|
90
|
-
const binaryType = context === "type" ? "Blob" : "File";
|
|
91
|
-
return nullableType(binaryType, nullable);
|
|
92
|
-
}
|
|
93
|
-
if (schema2.format === "uuid" || schema2.format === "email" || schema2.format === "uri" || schema2.format === "hostname" || schema2.format === "ipv4" || schema2.format === "ipv6") {
|
|
94
|
-
return nullableType("string", nullable);
|
|
95
|
-
}
|
|
96
|
-
return nullableType("string", nullable);
|
|
97
|
-
case "number":
|
|
98
|
-
case "integer":
|
|
99
|
-
return nullableType("number", nullable);
|
|
100
|
-
case "boolean":
|
|
101
|
-
return nullableType("boolean", nullable);
|
|
102
|
-
case "object":
|
|
103
|
-
return nullableType(context === "type" ? "Record<string, any>" : "any", nullable);
|
|
104
|
-
case "null":
|
|
105
|
-
return "null";
|
|
106
|
-
default:
|
|
107
|
-
if (Array.isArray(schema2.type)) {
|
|
108
|
-
const types = schema2.type.map((t) => getTypeScriptType(t, config, void 0, void 0, context));
|
|
109
|
-
return nullableType(types.join(" | "), nullable);
|
|
110
|
-
}
|
|
111
|
-
return nullableType("any", nullable);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
__name(getTypeScriptType, "getTypeScriptType");
|
|
115
|
-
function nullableType(type2, isNullable) {
|
|
116
|
-
return type2 + (isNullable ? " | null" : "");
|
|
117
|
-
}
|
|
118
|
-
__name(nullableType, "nullableType");
|
|
119
|
-
function escapeString(str2) {
|
|
120
|
-
return str2.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
121
|
-
}
|
|
122
|
-
__name(escapeString, "escapeString");
|
|
123
|
-
|
|
124
|
-
// ../../shared/src/utils/functions/token-names.ts
|
|
125
|
-
function getClientContextTokenName(clientName = "default") {
|
|
126
|
-
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
127
|
-
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
128
|
-
}
|
|
129
|
-
__name(getClientContextTokenName, "getClientContextTokenName");
|
|
130
|
-
function getBasePathTokenName(clientName = "default") {
|
|
131
|
-
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
132
|
-
return `BASE_PATH_${clientSuffix}`;
|
|
133
|
-
}
|
|
134
|
-
__name(getBasePathTokenName, "getBasePathTokenName");
|
|
135
|
-
|
|
136
|
-
// ../../shared/src/utils/functions/duplicate-function-name.ts
|
|
137
|
-
function hasDuplicateFunctionNames(arr) {
|
|
138
|
-
return new Set(arr.map((fn) => fn.getName())).size !== arr.length;
|
|
139
|
-
}
|
|
140
|
-
__name(hasDuplicateFunctionNames, "hasDuplicateFunctionNames");
|
|
141
|
-
|
|
142
|
-
// ../../shared/src/utils/functions/extract-paths.ts
|
|
143
|
-
function extractPaths(swaggerPaths = {}, methods = [
|
|
144
|
-
"get",
|
|
145
|
-
"post",
|
|
146
|
-
"put",
|
|
147
|
-
"patch",
|
|
148
|
-
"delete",
|
|
149
|
-
"options",
|
|
150
|
-
"head"
|
|
151
|
-
]) {
|
|
152
|
-
const paths = [];
|
|
153
|
-
Object.entries(swaggerPaths).forEach(([path3, pathItem]) => {
|
|
154
|
-
methods.forEach((method) => {
|
|
155
|
-
if (pathItem[method]) {
|
|
156
|
-
const operation = pathItem[method];
|
|
157
|
-
paths.push({
|
|
158
|
-
path: path3,
|
|
159
|
-
method: method.toUpperCase(),
|
|
160
|
-
operationId: operation.operationId,
|
|
161
|
-
summary: operation.summary,
|
|
162
|
-
description: operation.description,
|
|
163
|
-
tags: operation.tags || [],
|
|
164
|
-
parameters: parseParameters(operation.parameters || [], pathItem.parameters || []),
|
|
165
|
-
requestBody: operation.requestBody,
|
|
166
|
-
responses: operation.responses || {}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
return paths;
|
|
172
|
-
}
|
|
173
|
-
__name(extractPaths, "extractPaths");
|
|
174
|
-
function parseParameters(operationParams, pathParams) {
|
|
175
|
-
const allParams = [
|
|
176
|
-
...pathParams,
|
|
177
|
-
...operationParams
|
|
178
|
-
];
|
|
179
|
-
return allParams.map((param) => ({
|
|
180
|
-
name: param.name,
|
|
181
|
-
in: param.in,
|
|
182
|
-
required: param.required || param.in === "path",
|
|
183
|
-
schema: param.schema,
|
|
184
|
-
type: param.type,
|
|
185
|
-
format: param.format,
|
|
186
|
-
description: param.description
|
|
187
|
-
}));
|
|
188
|
-
}
|
|
189
|
-
__name(parseParameters, "parseParameters");
|
|
190
|
-
|
|
191
|
-
// ../../shared/src/utils/functions/extract-swagger-response-type.ts
|
|
192
|
-
function getResponseTypeFromResponse(response, responseTypeMapping) {
|
|
193
|
-
const content = response.content || {};
|
|
194
|
-
if (Object.keys(content).length === 0) {
|
|
195
|
-
return "json";
|
|
196
|
-
}
|
|
197
|
-
const responseTypes = [];
|
|
198
|
-
for (const [contentType, mediaType] of Object.entries(content)) {
|
|
199
|
-
const schema2 = mediaType?.schema;
|
|
200
|
-
const mapping = responseTypeMapping || {};
|
|
201
|
-
if (mapping[contentType]) {
|
|
202
|
-
responseTypes.push({
|
|
203
|
-
type: mapping[contentType],
|
|
204
|
-
priority: 1,
|
|
205
|
-
contentType
|
|
206
|
-
});
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (schema2?.format === "binary" || schema2?.format === "byte") {
|
|
210
|
-
responseTypes.push({
|
|
211
|
-
type: "blob",
|
|
212
|
-
priority: 2,
|
|
213
|
-
contentType
|
|
214
|
-
});
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (schema2?.type === "string" && (schema2?.format === "binary" || schema2?.format === "byte")) {
|
|
218
|
-
responseTypes.push({
|
|
219
|
-
type: "blob",
|
|
220
|
-
priority: 2,
|
|
221
|
-
contentType
|
|
222
|
-
});
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
const isPrimitive = isPrimitiveType(schema2);
|
|
226
|
-
const inferredType = inferResponseTypeFromContentType(contentType);
|
|
227
|
-
let priority = 3;
|
|
228
|
-
let finalType = inferredType;
|
|
229
|
-
if (inferredType === "json" && isPrimitive) {
|
|
230
|
-
finalType = "text";
|
|
231
|
-
priority = 2;
|
|
232
|
-
} else if (inferredType === "json") {
|
|
233
|
-
priority = 2;
|
|
234
|
-
}
|
|
235
|
-
responseTypes.push({
|
|
236
|
-
type: finalType,
|
|
237
|
-
priority,
|
|
238
|
-
contentType,
|
|
239
|
-
isPrimitive
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
243
|
-
return responseTypes[0]?.type || "json";
|
|
244
|
-
}
|
|
245
|
-
__name(getResponseTypeFromResponse, "getResponseTypeFromResponse");
|
|
246
|
-
function isPrimitiveType(schema2) {
|
|
247
|
-
if (!schema2) return false;
|
|
248
|
-
const primitiveTypes = [
|
|
249
|
-
"string",
|
|
250
|
-
"number",
|
|
251
|
-
"integer",
|
|
252
|
-
"boolean"
|
|
253
|
-
];
|
|
254
|
-
if (primitiveTypes.includes(schema2.type)) {
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
if (schema2.type === "array") {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
if (schema2.type === "object" || schema2.properties) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
if (schema2.$ref) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
if (schema2.allOf || schema2.oneOf || schema2.anyOf) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
__name(isPrimitiveType, "isPrimitiveType");
|
|
272
|
-
function inferResponseTypeFromContentType(contentType) {
|
|
273
|
-
const normalizedType = contentType.split(";")[0].trim().toLowerCase();
|
|
274
|
-
if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
|
|
275
|
-
return "json";
|
|
276
|
-
}
|
|
277
|
-
if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
|
|
278
|
-
return "text";
|
|
279
|
-
}
|
|
280
|
-
if (normalizedType.startsWith("text/")) {
|
|
281
|
-
const binaryTextTypes = [
|
|
282
|
-
"text/rtf",
|
|
283
|
-
"text/cache-manifest",
|
|
284
|
-
"text/vcard",
|
|
285
|
-
"text/calendar"
|
|
286
|
-
];
|
|
287
|
-
if (binaryTextTypes.includes(normalizedType)) {
|
|
288
|
-
return "blob";
|
|
289
|
-
}
|
|
290
|
-
return "text";
|
|
291
|
-
}
|
|
292
|
-
if (normalizedType === "CONTENT_TYPES.FORM_URLENCODED" || normalizedType === "multipart/form-data") {
|
|
293
|
-
return "text";
|
|
294
|
-
}
|
|
295
|
-
if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
|
|
296
|
-
return "text";
|
|
297
|
-
}
|
|
298
|
-
if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
|
|
299
|
-
return "arraybuffer";
|
|
300
|
-
}
|
|
301
|
-
return "blob";
|
|
302
|
-
}
|
|
303
|
-
__name(inferResponseTypeFromContentType, "inferResponseTypeFromContentType");
|
|
304
|
-
function getResponseType(response, config) {
|
|
305
|
-
const responseType = getResponseTypeFromResponse(response);
|
|
306
|
-
const content = response.content || {};
|
|
307
|
-
for (const [contentType, mediaType] of Object.entries(content)) {
|
|
308
|
-
if (mediaType?.schema) {
|
|
309
|
-
return getTypeScriptType(mediaType.schema, config, mediaType.schema.nullable);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
switch (responseType) {
|
|
313
|
-
case "blob":
|
|
314
|
-
return "Blob";
|
|
315
|
-
case "arraybuffer":
|
|
316
|
-
return "ArrayBuffer";
|
|
317
|
-
case "text":
|
|
318
|
-
return "string";
|
|
319
|
-
default:
|
|
320
|
-
return "any";
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
__name(getResponseType, "getResponseType");
|
|
324
|
-
|
|
325
|
-
// ../../shared/src/config/constants.ts
|
|
326
|
-
var disableLinting = `/* @ts-nocheck */
|
|
327
|
-
/* eslint-disable */
|
|
328
|
-
/* @noformat */
|
|
329
|
-
/* @formatter:off */
|
|
330
|
-
`;
|
|
331
|
-
var authorComment = `/**
|
|
332
|
-
* Generated by ng-openapi
|
|
333
|
-
`;
|
|
334
|
-
var defaultHeaderComment = disableLinting + authorComment;
|
|
335
|
-
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
336
|
-
* Do not edit this file manually
|
|
337
|
-
*/
|
|
338
|
-
`;
|
|
339
|
-
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
340
|
-
* Do not edit this file manually
|
|
341
|
-
*/
|
|
342
|
-
`;
|
|
343
|
-
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
344
|
-
* Do not edit this file manually
|
|
345
|
-
*/
|
|
346
|
-
`;
|
|
347
|
-
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
348
|
-
* Do not edit this file manually
|
|
349
|
-
*/
|
|
350
|
-
`;
|
|
351
|
-
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
352
|
-
* Do not edit this file manually
|
|
353
|
-
*/
|
|
354
|
-
`;
|
|
355
|
-
var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceName) => defaultHeaderComment + `* \`httpResource\` is still an experimental feature - NOT PRODUCTION READY
|
|
356
|
-
* Generated Angular service for ${resourceName}
|
|
357
|
-
* Do not edit this file manually
|
|
358
|
-
*/
|
|
359
|
-
`, "HTTP_RESOURCE_GENERATOR_HEADER_COMMENT");
|
|
360
|
-
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
361
|
-
* Do not edit this file manually
|
|
362
|
-
*/
|
|
363
|
-
`;
|
|
364
|
-
|
|
365
41
|
// ../../../node_modules/js-yaml/dist/js-yaml.mjs
|
|
366
42
|
function isNothing(subject) {
|
|
367
43
|
return typeof subject === "undefined" || subject === null;
|
|
@@ -2695,7 +2371,7 @@ function writeScalar(state, string, level, iskey, inblock) {
|
|
|
2695
2371
|
case STYLE_FOLDED:
|
|
2696
2372
|
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2697
2373
|
case STYLE_DOUBLE:
|
|
2698
|
-
return '"' +
|
|
2374
|
+
return '"' + escapeString(string) + '"';
|
|
2699
2375
|
default:
|
|
2700
2376
|
throw new exception("impossible error: invalid scalar style");
|
|
2701
2377
|
}
|
|
@@ -2758,7 +2434,7 @@ function foldLine(line, width) {
|
|
|
2758
2434
|
return result.slice(1);
|
|
2759
2435
|
}
|
|
2760
2436
|
__name(foldLine, "foldLine");
|
|
2761
|
-
function
|
|
2437
|
+
function escapeString(string) {
|
|
2762
2438
|
var result = "";
|
|
2763
2439
|
var char = 0;
|
|
2764
2440
|
var escapeSeq;
|
|
@@ -2774,7 +2450,7 @@ function escapeString2(string) {
|
|
|
2774
2450
|
}
|
|
2775
2451
|
return result;
|
|
2776
2452
|
}
|
|
2777
|
-
__name(
|
|
2453
|
+
__name(escapeString, "escapeString");
|
|
2778
2454
|
function writeFlowSequence(state, level, object) {
|
|
2779
2455
|
var _result = "", _tag = state.tag, index, length, value;
|
|
2780
2456
|
for (index = 0, length = object.length; index < length; index += 1) {
|
|
@@ -2999,70 +2675,404 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2999
2675
|
state.dump = tagStr + " " + state.dump;
|
|
3000
2676
|
}
|
|
3001
2677
|
}
|
|
3002
|
-
return true;
|
|
2678
|
+
return true;
|
|
2679
|
+
}
|
|
2680
|
+
__name(writeNode, "writeNode");
|
|
2681
|
+
function getDuplicateReferences(object, state) {
|
|
2682
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
2683
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
2684
|
+
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
2685
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
2686
|
+
}
|
|
2687
|
+
state.usedDuplicates = new Array(length);
|
|
2688
|
+
}
|
|
2689
|
+
__name(getDuplicateReferences, "getDuplicateReferences");
|
|
2690
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2691
|
+
var objectKeyList, index, length;
|
|
2692
|
+
if (object !== null && typeof object === "object") {
|
|
2693
|
+
index = objects.indexOf(object);
|
|
2694
|
+
if (index !== -1) {
|
|
2695
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
2696
|
+
duplicatesIndexes.push(index);
|
|
2697
|
+
}
|
|
2698
|
+
} else {
|
|
2699
|
+
objects.push(object);
|
|
2700
|
+
if (Array.isArray(object)) {
|
|
2701
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2702
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
2703
|
+
}
|
|
2704
|
+
} else {
|
|
2705
|
+
objectKeyList = Object.keys(object);
|
|
2706
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2707
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
__name(inspectNode, "inspectNode");
|
|
2714
|
+
function dump$1(input, options) {
|
|
2715
|
+
options = options || {};
|
|
2716
|
+
var state = new State(options);
|
|
2717
|
+
if (!state.noRefs) getDuplicateReferences(input, state);
|
|
2718
|
+
var value = input;
|
|
2719
|
+
if (state.replacer) {
|
|
2720
|
+
value = state.replacer.call({ "": value }, "", value);
|
|
2721
|
+
}
|
|
2722
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2723
|
+
return "";
|
|
2724
|
+
}
|
|
2725
|
+
__name(dump$1, "dump$1");
|
|
2726
|
+
var dump_1 = dump$1;
|
|
2727
|
+
var dumper = {
|
|
2728
|
+
dump: dump_1
|
|
2729
|
+
};
|
|
2730
|
+
function renamed(from, to) {
|
|
2731
|
+
return function() {
|
|
2732
|
+
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
__name(renamed, "renamed");
|
|
2736
|
+
var load = loader.load;
|
|
2737
|
+
var loadAll = loader.loadAll;
|
|
2738
|
+
var dump = dumper.dump;
|
|
2739
|
+
var safeLoad = renamed("safeLoad", "load");
|
|
2740
|
+
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2741
|
+
var safeDump = renamed("safeDump", "dump");
|
|
2742
|
+
|
|
2743
|
+
// ../../shared/src/utils/string.utils.ts
|
|
2744
|
+
function camelCase(str2) {
|
|
2745
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toLowerCase());
|
|
2746
|
+
}
|
|
2747
|
+
__name(camelCase, "camelCase");
|
|
2748
|
+
function pascalCase(str2) {
|
|
2749
|
+
return str2.replace(/[-_.\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^./, (char) => char.toUpperCase());
|
|
2750
|
+
}
|
|
2751
|
+
__name(pascalCase, "pascalCase");
|
|
2752
|
+
function pascalCaseForEnums(str2) {
|
|
2753
|
+
return str2.replace(/[^a-zA-Z0-9]/g, "_").replace(/(?:^|_)([a-z])/g, (_, char) => char.toUpperCase()).replace(/^([0-9])/, "_$1");
|
|
2754
|
+
}
|
|
2755
|
+
__name(pascalCaseForEnums, "pascalCaseForEnums");
|
|
2756
|
+
|
|
2757
|
+
// ../../shared/src/utils/type.utils.ts
|
|
2758
|
+
function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, context = "type") {
|
|
2759
|
+
let schema2;
|
|
2760
|
+
let nullable;
|
|
2761
|
+
if (typeof schemaOrType === "string" || schemaOrType === void 0) {
|
|
2762
|
+
schema2 = {
|
|
2763
|
+
type: schemaOrType,
|
|
2764
|
+
format: typeof formatOrNullable === "string" ? formatOrNullable : void 0
|
|
2765
|
+
};
|
|
2766
|
+
nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : isNullable;
|
|
2767
|
+
} else {
|
|
2768
|
+
schema2 = schemaOrType;
|
|
2769
|
+
nullable = typeof formatOrNullable === "boolean" ? formatOrNullable : schema2.nullable;
|
|
2770
|
+
}
|
|
2771
|
+
if (!schema2) {
|
|
2772
|
+
return "any";
|
|
2773
|
+
}
|
|
2774
|
+
if (schema2.$ref) {
|
|
2775
|
+
const refName = schema2.$ref.split("/").pop();
|
|
2776
|
+
return nullableType(pascalCaseForEnums(refName), nullable);
|
|
2777
|
+
}
|
|
2778
|
+
if (schema2.type === "array") {
|
|
2779
|
+
const itemType = schema2.items ? Array.isArray(schema2.items) ? "any" : getTypeScriptType(schema2.items, config, void 0, void 0, context) : "unknown";
|
|
2780
|
+
return nullable ? `(Array<${itemType}> | null)` : `Array<${itemType}>`;
|
|
2781
|
+
}
|
|
2782
|
+
switch (schema2.type) {
|
|
2783
|
+
case "string":
|
|
2784
|
+
if (schema2.enum) {
|
|
2785
|
+
return schema2.enum.map((value) => typeof value === "string" ? `'${escapeString2(value)}'` : String(value)).join(" | ");
|
|
2786
|
+
}
|
|
2787
|
+
if (schema2.format === "date" || schema2.format === "date-time") {
|
|
2788
|
+
const dateType = config.options.dateType === "Date" ? "Date" : "string";
|
|
2789
|
+
return nullableType(dateType, nullable);
|
|
2790
|
+
}
|
|
2791
|
+
if (schema2.format === "binary") {
|
|
2792
|
+
const binaryType = context === "type" ? "Blob" : "File";
|
|
2793
|
+
return nullableType(binaryType, nullable);
|
|
2794
|
+
}
|
|
2795
|
+
if (schema2.format === "uuid" || schema2.format === "email" || schema2.format === "uri" || schema2.format === "hostname" || schema2.format === "ipv4" || schema2.format === "ipv6") {
|
|
2796
|
+
return nullableType("string", nullable);
|
|
2797
|
+
}
|
|
2798
|
+
return nullableType("string", nullable);
|
|
2799
|
+
case "number":
|
|
2800
|
+
case "integer":
|
|
2801
|
+
return nullableType("number", nullable);
|
|
2802
|
+
case "boolean":
|
|
2803
|
+
return nullableType("boolean", nullable);
|
|
2804
|
+
case "object":
|
|
2805
|
+
return nullableType(context === "type" ? "Record<string, any>" : "any", nullable);
|
|
2806
|
+
case "null":
|
|
2807
|
+
return "null";
|
|
2808
|
+
default:
|
|
2809
|
+
if (Array.isArray(schema2.type)) {
|
|
2810
|
+
const types = schema2.type.map((t) => getTypeScriptType(t, config, void 0, void 0, context));
|
|
2811
|
+
return nullableType(types.join(" | "), nullable);
|
|
2812
|
+
}
|
|
2813
|
+
return nullableType("any", nullable);
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
__name(getTypeScriptType, "getTypeScriptType");
|
|
2817
|
+
function nullableType(type2, isNullable) {
|
|
2818
|
+
return type2 + (isNullable ? " | null" : "");
|
|
2819
|
+
}
|
|
2820
|
+
__name(nullableType, "nullableType");
|
|
2821
|
+
function escapeString2(str2) {
|
|
2822
|
+
return str2.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
2823
|
+
}
|
|
2824
|
+
__name(escapeString2, "escapeString");
|
|
2825
|
+
|
|
2826
|
+
// ../../shared/src/utils/functions/extract-swagger-response-type.ts
|
|
2827
|
+
function getResponseTypeFromResponse(response, responseTypeMapping) {
|
|
2828
|
+
const content = response.content || {};
|
|
2829
|
+
if (Object.keys(content).length === 0) {
|
|
2830
|
+
return "json";
|
|
2831
|
+
}
|
|
2832
|
+
const responseTypes = [];
|
|
2833
|
+
for (const [contentType, mediaType] of Object.entries(content)) {
|
|
2834
|
+
const schema2 = mediaType?.schema;
|
|
2835
|
+
const mapping = responseTypeMapping || {};
|
|
2836
|
+
if (mapping[contentType]) {
|
|
2837
|
+
responseTypes.push({
|
|
2838
|
+
type: mapping[contentType],
|
|
2839
|
+
priority: 1,
|
|
2840
|
+
contentType
|
|
2841
|
+
});
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
if (schema2?.format === "binary" || schema2?.format === "byte") {
|
|
2845
|
+
responseTypes.push({
|
|
2846
|
+
type: "blob",
|
|
2847
|
+
priority: 2,
|
|
2848
|
+
contentType
|
|
2849
|
+
});
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
if (schema2?.type === "string" && (schema2?.format === "binary" || schema2?.format === "byte")) {
|
|
2853
|
+
responseTypes.push({
|
|
2854
|
+
type: "blob",
|
|
2855
|
+
priority: 2,
|
|
2856
|
+
contentType
|
|
2857
|
+
});
|
|
2858
|
+
continue;
|
|
2859
|
+
}
|
|
2860
|
+
const isPrimitive = isPrimitiveType(schema2);
|
|
2861
|
+
const inferredType = inferResponseTypeFromContentType(contentType);
|
|
2862
|
+
let priority = 3;
|
|
2863
|
+
let finalType = inferredType;
|
|
2864
|
+
if (inferredType === "json" && isPrimitive) {
|
|
2865
|
+
finalType = "text";
|
|
2866
|
+
priority = 2;
|
|
2867
|
+
} else if (inferredType === "json") {
|
|
2868
|
+
priority = 2;
|
|
2869
|
+
}
|
|
2870
|
+
responseTypes.push({
|
|
2871
|
+
type: finalType,
|
|
2872
|
+
priority,
|
|
2873
|
+
contentType,
|
|
2874
|
+
isPrimitive
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
responseTypes.sort((a, b) => a.priority - b.priority);
|
|
2878
|
+
return responseTypes[0]?.type || "json";
|
|
3003
2879
|
}
|
|
3004
|
-
__name(
|
|
3005
|
-
function
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
2880
|
+
__name(getResponseTypeFromResponse, "getResponseTypeFromResponse");
|
|
2881
|
+
function isPrimitiveType(schema2) {
|
|
2882
|
+
if (!schema2) return false;
|
|
2883
|
+
const primitiveTypes = [
|
|
2884
|
+
"string",
|
|
2885
|
+
"number",
|
|
2886
|
+
"integer",
|
|
2887
|
+
"boolean"
|
|
2888
|
+
];
|
|
2889
|
+
if (schema2.type && primitiveTypes.includes(schema2.type)) {
|
|
2890
|
+
return true;
|
|
3010
2891
|
}
|
|
3011
|
-
|
|
2892
|
+
if (schema2.type === "array") {
|
|
2893
|
+
return false;
|
|
2894
|
+
}
|
|
2895
|
+
if (schema2.type === "object" || schema2.properties) {
|
|
2896
|
+
return false;
|
|
2897
|
+
}
|
|
2898
|
+
if (schema2.$ref) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (schema2.allOf || schema2.oneOf || schema2.anyOf) {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
return false;
|
|
3012
2905
|
}
|
|
3013
|
-
__name(
|
|
3014
|
-
function
|
|
3015
|
-
|
|
3016
|
-
if (
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
2906
|
+
__name(isPrimitiveType, "isPrimitiveType");
|
|
2907
|
+
function inferResponseTypeFromContentType(contentType) {
|
|
2908
|
+
const normalizedType = contentType.split(";")[0].trim().toLowerCase();
|
|
2909
|
+
if (normalizedType.includes("json") || normalizedType === "application/ld+json" || normalizedType === "application/hal+json" || normalizedType === "application/vnd.api+json") {
|
|
2910
|
+
return "json";
|
|
2911
|
+
}
|
|
2912
|
+
if (normalizedType.includes("xml") || normalizedType === "application/soap+xml" || normalizedType === "application/atom+xml" || normalizedType === "application/rss+xml") {
|
|
2913
|
+
return "text";
|
|
2914
|
+
}
|
|
2915
|
+
if (normalizedType.startsWith("text/")) {
|
|
2916
|
+
const binaryTextTypes = [
|
|
2917
|
+
"text/rtf",
|
|
2918
|
+
"text/cache-manifest",
|
|
2919
|
+
"text/vcard",
|
|
2920
|
+
"text/calendar"
|
|
2921
|
+
];
|
|
2922
|
+
if (binaryTextTypes.includes(normalizedType)) {
|
|
2923
|
+
return "blob";
|
|
3034
2924
|
}
|
|
2925
|
+
return "text";
|
|
2926
|
+
}
|
|
2927
|
+
if (normalizedType === "CONTENT_TYPES.FORM_URLENCODED" || normalizedType === "multipart/form-data") {
|
|
2928
|
+
return "text";
|
|
2929
|
+
}
|
|
2930
|
+
if (normalizedType === "application/javascript" || normalizedType === "application/typescript" || normalizedType === "application/css" || normalizedType === "application/yaml" || normalizedType === "application/x-yaml" || normalizedType === "application/toml") {
|
|
2931
|
+
return "text";
|
|
2932
|
+
}
|
|
2933
|
+
if (normalizedType.startsWith("image/") || normalizedType.startsWith("audio/") || normalizedType.startsWith("video/") || normalizedType === "application/pdf" || normalizedType === "application/zip" || normalizedType.includes("octet-stream")) {
|
|
2934
|
+
return "arraybuffer";
|
|
3035
2935
|
}
|
|
2936
|
+
return "blob";
|
|
3036
2937
|
}
|
|
3037
|
-
__name(
|
|
3038
|
-
function
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
2938
|
+
__name(inferResponseTypeFromContentType, "inferResponseTypeFromContentType");
|
|
2939
|
+
function getResponseType(response, config) {
|
|
2940
|
+
const responseType = getResponseTypeFromResponse(response);
|
|
2941
|
+
const content = response.content || {};
|
|
2942
|
+
for (const [contentType, mediaType] of Object.entries(content)) {
|
|
2943
|
+
if (mediaType?.schema) {
|
|
2944
|
+
return getTypeScriptType(mediaType.schema, config, mediaType.schema.nullable);
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
switch (responseType) {
|
|
2948
|
+
case "blob":
|
|
2949
|
+
return "Blob";
|
|
2950
|
+
case "arraybuffer":
|
|
2951
|
+
return "ArrayBuffer";
|
|
2952
|
+
case "text":
|
|
2953
|
+
return "string";
|
|
2954
|
+
default:
|
|
2955
|
+
return "any";
|
|
3045
2956
|
}
|
|
3046
|
-
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
3047
|
-
return "";
|
|
3048
2957
|
}
|
|
3049
|
-
__name(
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
};
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
2958
|
+
__name(getResponseType, "getResponseType");
|
|
2959
|
+
|
|
2960
|
+
// ../../shared/src/emit/headers.emit.ts
|
|
2961
|
+
function emitDefaultHeadersMerge(optionsExpression, customHeaders) {
|
|
2962
|
+
const defaultsLiteral = Object.entries(customHeaders).map(([key, value]) => `'${key}': '${value}'`).join(", ");
|
|
2963
|
+
return `
|
|
2964
|
+
// Add default headers if not already present
|
|
2965
|
+
let headers = ${optionsExpression}?.headers;
|
|
2966
|
+
if (headers instanceof HttpHeaders) {
|
|
2967
|
+
${emitDefaultHeaderGuards(customHeaders)}
|
|
2968
|
+
} else {
|
|
2969
|
+
headers = { ${defaultsLiteral}, ...headers };
|
|
2970
|
+
}`;
|
|
3058
2971
|
}
|
|
3059
|
-
__name(
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
2972
|
+
__name(emitDefaultHeadersMerge, "emitDefaultHeadersMerge");
|
|
2973
|
+
function emitDefaultHeaderGuards(customHeaders) {
|
|
2974
|
+
return Object.entries(customHeaders).map(([key, value]) => `if (!headers.has('${key}')) {
|
|
2975
|
+
headers = headers.set('${key}', '${value}');
|
|
2976
|
+
}`).join("\n");
|
|
2977
|
+
}
|
|
2978
|
+
__name(emitDefaultHeaderGuards, "emitDefaultHeaderGuards");
|
|
2979
|
+
|
|
2980
|
+
// ../../shared/src/emit/url.emit.ts
|
|
2981
|
+
function plainParamValue(identifier) {
|
|
2982
|
+
return identifier;
|
|
2983
|
+
}
|
|
2984
|
+
__name(plainParamValue, "plainParamValue");
|
|
2985
|
+
function signalAwareParamValue(identifier) {
|
|
2986
|
+
return `typeof ${identifier} === 'function' ? ${identifier}() : ${identifier}`;
|
|
2987
|
+
}
|
|
2988
|
+
__name(signalAwareParamValue, "signalAwareParamValue");
|
|
2989
|
+
function emitUrlExpression(path3, pathParams, paramValue = plainParamValue) {
|
|
2990
|
+
let urlExpression = `\`\${this.basePath}${path3}\``;
|
|
2991
|
+
pathParams.forEach((param) => {
|
|
2992
|
+
urlExpression = urlExpression.replace(`{${param.name}}`, `\${${paramValue(camelCase(param.name))}}`);
|
|
2993
|
+
});
|
|
2994
|
+
return urlExpression;
|
|
2995
|
+
}
|
|
2996
|
+
__name(emitUrlExpression, "emitUrlExpression");
|
|
2997
|
+
|
|
2998
|
+
// ../../shared/src/emit/query-params.emit.ts
|
|
2999
|
+
function emitSignalAwareQueryParams(queryParams) {
|
|
3000
|
+
if (queryParams.length === 0) {
|
|
3001
|
+
return "";
|
|
3002
|
+
}
|
|
3003
|
+
const paramMappings = queryParams.map((param) => `const ${camelCase(param.name)}Value = ${signalAwareParamValue(camelCase(param.name))};
|
|
3004
|
+
if (${camelCase(param.name)}Value != null) {
|
|
3005
|
+
params = HttpParamsBuilder.addToHttpParams(params, ${camelCase(param.name)}Value, '${param.name}');
|
|
3006
|
+
}`).join("\n");
|
|
3007
|
+
return `
|
|
3008
|
+
let params = new HttpParams();
|
|
3009
|
+
${paramMappings}`;
|
|
3010
|
+
}
|
|
3011
|
+
__name(emitSignalAwareQueryParams, "emitSignalAwareQueryParams");
|
|
3012
|
+
|
|
3013
|
+
// ../../shared/src/emit/response-type.emit.ts
|
|
3014
|
+
function joinRequestOptionEntries(entries) {
|
|
3015
|
+
return entries.filter((entry) => entry && !entry.includes("undefined")).join(",\n ");
|
|
3016
|
+
}
|
|
3017
|
+
__name(joinRequestOptionEntries, "joinRequestOptionEntries");
|
|
3018
|
+
|
|
3019
|
+
// ../../shared/src/utils/functions/token-names.ts
|
|
3020
|
+
function getClientContextTokenName(clientName = "default") {
|
|
3021
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
3022
|
+
return `CLIENT_CONTEXT_TOKEN_${clientSuffix}`;
|
|
3023
|
+
}
|
|
3024
|
+
__name(getClientContextTokenName, "getClientContextTokenName");
|
|
3025
|
+
function getBasePathTokenName(clientName = "default") {
|
|
3026
|
+
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
3027
|
+
return `BASE_PATH_${clientSuffix}`;
|
|
3028
|
+
}
|
|
3029
|
+
__name(getBasePathTokenName, "getBasePathTokenName");
|
|
3030
|
+
|
|
3031
|
+
// ../../shared/src/utils/functions/duplicate-function-name.ts
|
|
3032
|
+
function hasDuplicateFunctionNames(arr) {
|
|
3033
|
+
return new Set(arr.map((fn) => fn.getName())).size !== arr.length;
|
|
3034
|
+
}
|
|
3035
|
+
__name(hasDuplicateFunctionNames, "hasDuplicateFunctionNames");
|
|
3036
|
+
|
|
3037
|
+
// ../../shared/src/config/constants.ts
|
|
3038
|
+
var disableLinting = `/* @ts-nocheck */
|
|
3039
|
+
/* eslint-disable */
|
|
3040
|
+
/* @noformat */
|
|
3041
|
+
/* @formatter:off */
|
|
3042
|
+
`;
|
|
3043
|
+
var authorComment = `/**
|
|
3044
|
+
* Generated by ng-openapi
|
|
3045
|
+
`;
|
|
3046
|
+
var defaultHeaderComment = disableLinting + authorComment;
|
|
3047
|
+
var TYPE_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated TypeScript interfaces from Swagger specification
|
|
3048
|
+
* Do not edit this file manually
|
|
3049
|
+
*/
|
|
3050
|
+
`;
|
|
3051
|
+
var SERVICE_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated service exports
|
|
3052
|
+
* Do not edit this file manually
|
|
3053
|
+
*/
|
|
3054
|
+
`;
|
|
3055
|
+
var REQUEST_PARAMS_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated request parameter interfaces
|
|
3056
|
+
* Do not edit this file manually
|
|
3057
|
+
*/
|
|
3058
|
+
`;
|
|
3059
|
+
var MAIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Entrypoint for the client
|
|
3060
|
+
* Do not edit this file manually
|
|
3061
|
+
*/
|
|
3062
|
+
`;
|
|
3063
|
+
var PROVIDER_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated provider functions for easy setup
|
|
3064
|
+
* Do not edit this file manually
|
|
3065
|
+
*/
|
|
3066
|
+
`;
|
|
3067
|
+
var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceName) => defaultHeaderComment + `* \`httpResource\` is still an experimental feature - NOT PRODUCTION READY
|
|
3068
|
+
* Generated Angular service for ${resourceName}
|
|
3069
|
+
* Do not edit this file manually
|
|
3070
|
+
*/
|
|
3071
|
+
`, "HTTP_RESOURCE_GENERATOR_HEADER_COMMENT");
|
|
3072
|
+
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
3073
|
+
* Do not edit this file manually
|
|
3074
|
+
*/
|
|
3075
|
+
`;
|
|
3066
3076
|
|
|
3067
3077
|
// src/lib/http-resource.generator.ts
|
|
3068
3078
|
var path2 = __toESM(require("path"), 1);
|
|
@@ -3077,83 +3087,46 @@ var HttpResourceMethodBodyGenerator = class {
|
|
|
3077
3087
|
this.config = config;
|
|
3078
3088
|
}
|
|
3079
3089
|
generateMethodBody(operation) {
|
|
3080
|
-
const context = this.createGenerationContext(operation);
|
|
3081
3090
|
const bodyParts = [
|
|
3082
|
-
this.
|
|
3083
|
-
this.generateHttpResource(operation
|
|
3091
|
+
this.generateDefaultHeaders(),
|
|
3092
|
+
this.generateHttpResource(operation)
|
|
3084
3093
|
];
|
|
3085
3094
|
return bodyParts.filter(Boolean).join("\n");
|
|
3086
3095
|
}
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
generateUrl(operation, context) {
|
|
3095
|
-
let urlExpression = `\`\${this.basePath}${operation.path}\``;
|
|
3096
|
-
if (context.pathParams.length > 0) {
|
|
3097
|
-
context.pathParams.forEach((param) => {
|
|
3098
|
-
urlExpression = urlExpression.replace(`{${param.name}}`, `\${typeof ${camelCase(param.name)} === 'function' ? ${camelCase(param.name)}() : ${camelCase(param.name)}}`);
|
|
3099
|
-
});
|
|
3100
|
-
}
|
|
3101
|
-
return urlExpression;
|
|
3102
|
-
}
|
|
3103
|
-
generateQueryParams(context) {
|
|
3104
|
-
if (context.queryParams.length === 0) {
|
|
3096
|
+
/**
|
|
3097
|
+
* Caller headers flow through `...requestOptions` untouched; a headers
|
|
3098
|
+
* merge is only needed when the config declares default headers.
|
|
3099
|
+
*/
|
|
3100
|
+
generateDefaultHeaders() {
|
|
3101
|
+
const customHeaders = this.config.options.customHeaders;
|
|
3102
|
+
if (!customHeaders || Object.keys(customHeaders).length === 0) {
|
|
3105
3103
|
return "";
|
|
3106
3104
|
}
|
|
3107
|
-
|
|
3108
|
-
if (${camelCase(param.name)}Value != null) {
|
|
3109
|
-
params = HttpParamsBuilder.addToHttpParams(params, ${camelCase(param.name)}Value, '${param.name}');
|
|
3110
|
-
}`).join("\n");
|
|
3111
|
-
return `
|
|
3112
|
-
let params = new HttpParams();
|
|
3113
|
-
${paramMappings}`;
|
|
3114
|
-
}
|
|
3115
|
-
generateHeaders(context) {
|
|
3116
|
-
const hasCustomHeaders = this.config.options.customHeaders;
|
|
3117
|
-
let headerCode = `
|
|
3118
|
-
let headers: HttpHeaders;
|
|
3119
|
-
if (requestOptions?.headers instanceof HttpHeaders) {
|
|
3120
|
-
headers = requestOptions.headers;
|
|
3121
|
-
} else {
|
|
3122
|
-
headers = new HttpHeaders(requestOptions?.headers as Record<string, string>);
|
|
3123
|
-
}`;
|
|
3124
|
-
if (hasCustomHeaders) {
|
|
3125
|
-
headerCode += `
|
|
3126
|
-
// Add default headers if not already present
|
|
3127
|
-
${Object.entries(this.config.options.customHeaders || {}).map(([key, value]) => `if (!headers.has('${key}')) {
|
|
3128
|
-
headers = headers.set('${key}', '${value}');
|
|
3129
|
-
}`).join("\n")}`;
|
|
3130
|
-
}
|
|
3131
|
-
return headerCode;
|
|
3105
|
+
return emitDefaultHeadersMerge("requestOptions", customHeaders);
|
|
3132
3106
|
}
|
|
3133
|
-
generateRequestOptions(operation
|
|
3134
|
-
const
|
|
3135
|
-
const url =
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3107
|
+
generateRequestOptions(operation) {
|
|
3108
|
+
const entries = [];
|
|
3109
|
+
const url = emitUrlExpression(operation.path, operation.pathParams, signalAwareParamValue);
|
|
3110
|
+
entries.push(`url: ${url}`);
|
|
3111
|
+
entries.push(`method: "GET"`);
|
|
3112
|
+
entries.push("...requestOptions");
|
|
3113
|
+
if (operation.queryParams.length > 0) {
|
|
3114
|
+
entries.push("params");
|
|
3140
3115
|
}
|
|
3141
|
-
options.
|
|
3142
|
-
|
|
3143
|
-
options.push(`responseType: '${context.responseType}' as '${context.responseType}'`);
|
|
3116
|
+
if (this.config.options.customHeaders && Object.keys(this.config.options.customHeaders).length > 0) {
|
|
3117
|
+
entries.push("headers");
|
|
3144
3118
|
}
|
|
3145
|
-
|
|
3146
|
-
const formattedOptions =
|
|
3119
|
+
entries.push("context: this.createContextWithClientId(requestOptions?.context)");
|
|
3120
|
+
const formattedOptions = joinRequestOptionEntries(entries);
|
|
3147
3121
|
return `return {
|
|
3148
|
-
${formattedOptions}
|
|
3149
|
-
...requestOptions
|
|
3122
|
+
${formattedOptions}
|
|
3150
3123
|
}`;
|
|
3151
3124
|
}
|
|
3152
|
-
generateHttpResource(operation
|
|
3153
|
-
const resourceOptions = this.generateRequestOptions(operation
|
|
3154
|
-
const queryParams =
|
|
3125
|
+
generateHttpResource(operation) {
|
|
3126
|
+
const resourceOptions = this.generateRequestOptions(operation);
|
|
3127
|
+
const queryParams = emitSignalAwareQueryParams(operation.queryParams);
|
|
3155
3128
|
let httpResource = "httpResource";
|
|
3156
|
-
switch (
|
|
3129
|
+
switch (operation.responseType) {
|
|
3157
3130
|
case "blob":
|
|
3158
3131
|
httpResource += ".blob";
|
|
3159
3132
|
break;
|
|
@@ -3164,24 +3137,9 @@ ${Object.entries(this.config.options.customHeaders || {}).map(([key, value]) =>
|
|
|
3164
3137
|
httpResource += ".text";
|
|
3165
3138
|
break;
|
|
3166
3139
|
}
|
|
3167
|
-
return `
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
}
|
|
3171
|
-
determineResponseType(operation) {
|
|
3172
|
-
const successResponses = [
|
|
3173
|
-
"200",
|
|
3174
|
-
"201",
|
|
3175
|
-
"202",
|
|
3176
|
-
"204",
|
|
3177
|
-
"206"
|
|
3178
|
-
];
|
|
3179
|
-
for (const statusCode of successResponses) {
|
|
3180
|
-
const response = operation.responses?.[statusCode];
|
|
3181
|
-
if (!response) continue;
|
|
3182
|
-
return getResponseTypeFromResponse(response);
|
|
3183
|
-
}
|
|
3184
|
-
return "json";
|
|
3140
|
+
return `return ${httpResource}(() => {${queryParams}
|
|
3141
|
+
${resourceOptions}
|
|
3142
|
+
}, resourceOptions);`;
|
|
3185
3143
|
}
|
|
3186
3144
|
};
|
|
3187
3145
|
|
|
@@ -3214,9 +3172,10 @@ var HttpResourceMethodParamsGenerator = class {
|
|
|
3214
3172
|
}
|
|
3215
3173
|
generateApiParameters(operation) {
|
|
3216
3174
|
const params = [];
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3175
|
+
operation.pathParams.forEach((param) => {
|
|
3176
|
+
const paramType = getTypeScriptType(param.schema || {
|
|
3177
|
+
...param
|
|
3178
|
+
}, this.config);
|
|
3220
3179
|
const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
|
|
3221
3180
|
params.push({
|
|
3222
3181
|
name: camelCase(param.name),
|
|
@@ -3224,9 +3183,10 @@ var HttpResourceMethodParamsGenerator = class {
|
|
|
3224
3183
|
hasQuestionToken: !param.required
|
|
3225
3184
|
});
|
|
3226
3185
|
});
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3186
|
+
operation.queryParams.forEach((param) => {
|
|
3187
|
+
const paramType = getTypeScriptType(param.schema || {
|
|
3188
|
+
...param
|
|
3189
|
+
}, this.config);
|
|
3230
3190
|
const signalParamType = param.required ? `Signal<${paramType}>` : `Signal<${paramType} | undefined>`;
|
|
3231
3191
|
params.push({
|
|
3232
3192
|
name: camelCase(param.name),
|
|
@@ -3405,30 +3365,24 @@ var HttpResourceGenerator = class {
|
|
|
3405
3365
|
__name(this, "HttpResourceGenerator");
|
|
3406
3366
|
}
|
|
3407
3367
|
project;
|
|
3408
|
-
parser;
|
|
3409
3368
|
spec;
|
|
3410
3369
|
config;
|
|
3411
3370
|
methodGenerator;
|
|
3412
3371
|
indexGenerator;
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
this.
|
|
3416
|
-
this.
|
|
3417
|
-
this.spec =
|
|
3418
|
-
this.
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
throw new Error(`Invalid or unsupported specification format. Expected OpenAPI 3.x or Swagger 2.x. ${versionInfo ? `Found: ${versionInfo.type} ${versionInfo.version}` : "No version info found"}`);
|
|
3422
|
-
}
|
|
3423
|
-
this.methodGenerator = new HttpResourceMethodGenerator(config);
|
|
3372
|
+
onWarning;
|
|
3373
|
+
constructor(context) {
|
|
3374
|
+
this.config = context.config;
|
|
3375
|
+
this.project = context.project;
|
|
3376
|
+
this.spec = context.spec;
|
|
3377
|
+
this.onWarning = context.onWarning;
|
|
3378
|
+
this.indexGenerator = new HttpResourceIndexGenerator(context.project);
|
|
3379
|
+
this.methodGenerator = new HttpResourceMethodGenerator(context.config);
|
|
3424
3380
|
}
|
|
3425
3381
|
async generate(outputRoot) {
|
|
3426
3382
|
const outputDir = path2.join(outputRoot, "resources");
|
|
3427
|
-
const paths =
|
|
3428
|
-
"get"
|
|
3429
|
-
]);
|
|
3383
|
+
const paths = this.spec.operations.filter((operation) => operation.method === "GET");
|
|
3430
3384
|
if (paths.length === 0) {
|
|
3431
|
-
|
|
3385
|
+
this.onWarning?.("No API paths found in the specification");
|
|
3432
3386
|
return;
|
|
3433
3387
|
}
|
|
3434
3388
|
const controllerGroups = this.groupPathsByController(paths);
|