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