ng-openapi 0.2.1-pr-26-feature-zod-ee9b608.0 → 0.2.1-pr-32-feature-zod-9008b87.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/cli.cjs +67 -207
- package/index.d.ts +3 -3
- package/index.js +81 -215
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -107,7 +107,7 @@ function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, c
|
|
|
107
107
|
case "boolean":
|
|
108
108
|
return nullableType("boolean", nullable);
|
|
109
109
|
case "object":
|
|
110
|
-
return nullableType(context === "type" ? "Record<string,
|
|
110
|
+
return nullableType(context === "type" ? "Record<string, any>" : "any", nullable);
|
|
111
111
|
case "null":
|
|
112
112
|
return "null";
|
|
113
113
|
default:
|
|
@@ -124,78 +124,6 @@ function escapeString(str) {
|
|
|
124
124
|
}
|
|
125
125
|
__name(escapeString, "escapeString");
|
|
126
126
|
|
|
127
|
-
// ../shared/src/utils/functions/collect-used-types.ts
|
|
128
|
-
function collectUsedTypes(operations) {
|
|
129
|
-
const usedTypes = /* @__PURE__ */ new Set();
|
|
130
|
-
usedTypes.add("RequestOptions");
|
|
131
|
-
operations.forEach((operation) => {
|
|
132
|
-
operation.parameters?.forEach((param) => {
|
|
133
|
-
collectTypesFromSchema(param.schema || param, usedTypes);
|
|
134
|
-
});
|
|
135
|
-
if (operation.requestBody) {
|
|
136
|
-
collectTypesFromRequestBody(operation.requestBody, usedTypes);
|
|
137
|
-
}
|
|
138
|
-
if (operation.responses) {
|
|
139
|
-
Object.values(operation.responses).forEach((response) => {
|
|
140
|
-
collectTypesFromResponse(response, usedTypes);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return usedTypes;
|
|
145
|
-
}
|
|
146
|
-
__name(collectUsedTypes, "collectUsedTypes");
|
|
147
|
-
function collectTypesFromSchema(schema, usedTypes) {
|
|
148
|
-
if (!schema) return;
|
|
149
|
-
if (schema.$ref) {
|
|
150
|
-
const refName = schema.$ref.split("/").pop();
|
|
151
|
-
if (refName) {
|
|
152
|
-
usedTypes.add(pascalCase(refName));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (schema.type === "array" && schema.items) {
|
|
156
|
-
collectTypesFromSchema(schema.items, usedTypes);
|
|
157
|
-
}
|
|
158
|
-
if (schema.type === "object" && schema.properties) {
|
|
159
|
-
Object.values(schema.properties).forEach((prop) => {
|
|
160
|
-
collectTypesFromSchema(prop, usedTypes);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (schema.allOf) {
|
|
164
|
-
schema.allOf.forEach((subSchema) => {
|
|
165
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
if (schema.oneOf) {
|
|
169
|
-
schema.oneOf.forEach((subSchema) => {
|
|
170
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
if (schema.anyOf) {
|
|
174
|
-
schema.anyOf.forEach((subSchema) => {
|
|
175
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
__name(collectTypesFromSchema, "collectTypesFromSchema");
|
|
180
|
-
function collectTypesFromRequestBody(requestBody, usedTypes) {
|
|
181
|
-
const content = requestBody.content || {};
|
|
182
|
-
Object.values(content).forEach((mediaType) => {
|
|
183
|
-
if (mediaType.schema) {
|
|
184
|
-
collectTypesFromSchema(mediaType.schema, usedTypes);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
__name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
|
|
189
|
-
function collectTypesFromResponse(response, usedTypes) {
|
|
190
|
-
const content = response.content || {};
|
|
191
|
-
Object.values(content).forEach((mediaType) => {
|
|
192
|
-
if (mediaType.schema) {
|
|
193
|
-
collectTypesFromSchema(mediaType.schema, usedTypes);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
__name(collectTypesFromResponse, "collectTypesFromResponse");
|
|
198
|
-
|
|
199
127
|
// ../shared/src/utils/functions/token-names.ts
|
|
200
128
|
function getClientContextTokenName(clientName = "default") {
|
|
201
129
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
@@ -459,6 +387,10 @@ var BASE_INTERCEPTOR_HEADER_COMMENT = /* @__PURE__ */ __name((clientName) => def
|
|
|
459
387
|
* Do not edit this file manually
|
|
460
388
|
*/
|
|
461
389
|
`, "BASE_INTERCEPTOR_HEADER_COMMENT");
|
|
390
|
+
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
391
|
+
* Do not edit this file manually
|
|
392
|
+
*/
|
|
393
|
+
`;
|
|
462
394
|
|
|
463
395
|
// ../shared/src/core/swagger-parser.ts
|
|
464
396
|
var fs = __toESM(require("fs"));
|
|
@@ -1191,18 +1123,6 @@ var FileDownloadGenerator = class {
|
|
|
1191
1123
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1192
1124
|
overwrite: true
|
|
1193
1125
|
});
|
|
1194
|
-
sourceFile.addImportDeclaration({
|
|
1195
|
-
namedImports: [
|
|
1196
|
-
"Observable"
|
|
1197
|
-
],
|
|
1198
|
-
moduleSpecifier: "rxjs"
|
|
1199
|
-
});
|
|
1200
|
-
sourceFile.addImportDeclaration({
|
|
1201
|
-
namedImports: [
|
|
1202
|
-
"tap"
|
|
1203
|
-
],
|
|
1204
|
-
moduleSpecifier: "rxjs/operators"
|
|
1205
|
-
});
|
|
1206
1126
|
sourceFile.addFunction({
|
|
1207
1127
|
name: "downloadFile",
|
|
1208
1128
|
isExported: true,
|
|
@@ -1312,7 +1232,7 @@ var FileDownloadGenerator = class {
|
|
|
1312
1232
|
|
|
1313
1233
|
return fallbackFilename;`
|
|
1314
1234
|
});
|
|
1315
|
-
sourceFile.formatText();
|
|
1235
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1316
1236
|
sourceFile.saveSync();
|
|
1317
1237
|
}
|
|
1318
1238
|
};
|
|
@@ -1334,34 +1254,6 @@ var DateTransformerGenerator = class {
|
|
|
1334
1254
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1335
1255
|
overwrite: true
|
|
1336
1256
|
});
|
|
1337
|
-
sourceFile.addImportDeclaration({
|
|
1338
|
-
namedImports: [
|
|
1339
|
-
"HttpInterceptor",
|
|
1340
|
-
"HttpRequest",
|
|
1341
|
-
"HttpHandler",
|
|
1342
|
-
"HttpEvent",
|
|
1343
|
-
"HttpResponse"
|
|
1344
|
-
],
|
|
1345
|
-
moduleSpecifier: "@angular/common/http"
|
|
1346
|
-
});
|
|
1347
|
-
sourceFile.addImportDeclaration({
|
|
1348
|
-
namedImports: [
|
|
1349
|
-
"Injectable"
|
|
1350
|
-
],
|
|
1351
|
-
moduleSpecifier: "@angular/core"
|
|
1352
|
-
});
|
|
1353
|
-
sourceFile.addImportDeclaration({
|
|
1354
|
-
namedImports: [
|
|
1355
|
-
"Observable"
|
|
1356
|
-
],
|
|
1357
|
-
moduleSpecifier: "rxjs"
|
|
1358
|
-
});
|
|
1359
|
-
sourceFile.addImportDeclaration({
|
|
1360
|
-
namedImports: [
|
|
1361
|
-
"map"
|
|
1362
|
-
],
|
|
1363
|
-
moduleSpecifier: "rxjs/operators"
|
|
1364
|
-
});
|
|
1365
1257
|
sourceFile.addVariableStatement({
|
|
1366
1258
|
isExported: true,
|
|
1367
1259
|
declarationKind: import_ts_morph3.VariableDeclarationKind.Const,
|
|
@@ -1448,7 +1340,7 @@ var DateTransformerGenerator = class {
|
|
|
1448
1340
|
}
|
|
1449
1341
|
]
|
|
1450
1342
|
});
|
|
1451
|
-
sourceFile.formatText();
|
|
1343
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1452
1344
|
sourceFile.saveSync();
|
|
1453
1345
|
}
|
|
1454
1346
|
};
|
|
@@ -1733,33 +1625,9 @@ var BaseInterceptorGenerator = class {
|
|
|
1733
1625
|
sourceFile.addImportDeclarations([
|
|
1734
1626
|
{
|
|
1735
1627
|
namedImports: [
|
|
1736
|
-
"HttpEvent",
|
|
1737
|
-
"HttpHandler",
|
|
1738
|
-
"HttpInterceptor",
|
|
1739
|
-
"HttpRequest",
|
|
1740
|
-
"HttpContextToken"
|
|
1741
|
-
],
|
|
1742
|
-
moduleSpecifier: "@angular/common/http"
|
|
1743
|
-
},
|
|
1744
|
-
{
|
|
1745
|
-
namedImports: [
|
|
1746
|
-
"inject",
|
|
1747
1628
|
"Injectable"
|
|
1748
1629
|
],
|
|
1749
1630
|
moduleSpecifier: "@angular/core"
|
|
1750
|
-
},
|
|
1751
|
-
{
|
|
1752
|
-
namedImports: [
|
|
1753
|
-
"Observable"
|
|
1754
|
-
],
|
|
1755
|
-
moduleSpecifier: "rxjs"
|
|
1756
|
-
},
|
|
1757
|
-
{
|
|
1758
|
-
namedImports: [
|
|
1759
|
-
interceptorsTokenName,
|
|
1760
|
-
clientContextTokenName
|
|
1761
|
-
],
|
|
1762
|
-
moduleSpecifier: "../tokens"
|
|
1763
1631
|
}
|
|
1764
1632
|
]);
|
|
1765
1633
|
sourceFile.addClass({
|
|
@@ -1825,7 +1693,7 @@ var BaseInterceptorGenerator = class {
|
|
|
1825
1693
|
}
|
|
1826
1694
|
]
|
|
1827
1695
|
});
|
|
1828
|
-
sourceFile.formatText();
|
|
1696
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1829
1697
|
sourceFile.saveSync();
|
|
1830
1698
|
}
|
|
1831
1699
|
getInterceptorsTokenName() {
|
|
@@ -2061,8 +1929,10 @@ var ServiceMethodBodyGenerator = class {
|
|
|
2061
1929
|
__name(this, "ServiceMethodBodyGenerator");
|
|
2062
1930
|
}
|
|
2063
1931
|
config;
|
|
2064
|
-
|
|
1932
|
+
parser;
|
|
1933
|
+
constructor(config, parser) {
|
|
2065
1934
|
this.config = config;
|
|
1935
|
+
this.parser = parser;
|
|
2066
1936
|
}
|
|
2067
1937
|
generateMethodBody(operation) {
|
|
2068
1938
|
const context = this.createGenerationContext(operation);
|
|
@@ -2083,7 +1953,12 @@ var ServiceMethodBodyGenerator = class {
|
|
|
2083
1953
|
if (!this.isMultipartFormData(operation)) {
|
|
2084
1954
|
return [];
|
|
2085
1955
|
}
|
|
2086
|
-
const
|
|
1956
|
+
const schema = operation.requestBody?.content?.["multipart/form-data"].schema;
|
|
1957
|
+
let resolvedSchema = schema;
|
|
1958
|
+
if (schema?.$ref) {
|
|
1959
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
1960
|
+
}
|
|
1961
|
+
const properties = resolvedSchema?.properties || {};
|
|
2087
1962
|
return Object.keys(properties);
|
|
2088
1963
|
}
|
|
2089
1964
|
createGenerationContext(operation) {
|
|
@@ -2152,13 +2027,33 @@ if (!headers.has('Content-Type')) {
|
|
|
2152
2027
|
if (!context.isMultipart || context.formDataFields.length === 0) {
|
|
2153
2028
|
return "";
|
|
2154
2029
|
}
|
|
2030
|
+
const schema = operation.requestBody?.content?.["multipart/form-data"].schema;
|
|
2031
|
+
let resolvedSchema = schema;
|
|
2032
|
+
if (schema?.$ref) {
|
|
2033
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
2034
|
+
}
|
|
2035
|
+
const properties = resolvedSchema?.properties || {};
|
|
2155
2036
|
const formDataAppends = context.formDataFields.map((field) => {
|
|
2156
|
-
const fieldSchema =
|
|
2037
|
+
const fieldSchema = properties[field];
|
|
2157
2038
|
const isFile = fieldSchema?.type === "string" && fieldSchema?.format === "binary";
|
|
2158
|
-
const
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2039
|
+
const isArray = fieldSchema?.type === "array";
|
|
2040
|
+
if (isArray) {
|
|
2041
|
+
const itemSchema = Array.isArray(fieldSchema.items) ? fieldSchema.items[0] : fieldSchema.items;
|
|
2042
|
+
const isFileArray = itemSchema?.type === "string" && itemSchema?.format === "binary";
|
|
2043
|
+
const valueExpression = isFileArray ? "item" : "String(item)";
|
|
2044
|
+
return `if (${field} !== undefined && Array.isArray(${field})) {
|
|
2045
|
+
${field}.forEach((item) => {
|
|
2046
|
+
if (item !== undefined && item !== null) {
|
|
2047
|
+
formData.append('${field}', ${valueExpression});
|
|
2048
|
+
}
|
|
2049
|
+
});
|
|
2050
|
+
}`;
|
|
2051
|
+
} else {
|
|
2052
|
+
const valueExpression = isFile ? field : `String(${field})`;
|
|
2053
|
+
return `if (${field} !== undefined) {
|
|
2054
|
+
formData.append('${field}', ${valueExpression});
|
|
2055
|
+
}`;
|
|
2056
|
+
}
|
|
2162
2057
|
}).join("\n");
|
|
2163
2058
|
return `
|
|
2164
2059
|
const formData = new FormData();
|
|
@@ -2235,8 +2130,10 @@ var ServiceMethodParamsGenerator = class {
|
|
|
2235
2130
|
__name(this, "ServiceMethodParamsGenerator");
|
|
2236
2131
|
}
|
|
2237
2132
|
config;
|
|
2238
|
-
|
|
2133
|
+
parser;
|
|
2134
|
+
constructor(config, parser) {
|
|
2239
2135
|
this.config = config;
|
|
2136
|
+
this.parser = parser;
|
|
2240
2137
|
}
|
|
2241
2138
|
generateMethodParameters(operation) {
|
|
2242
2139
|
const params = this.generateApiParameters(operation);
|
|
@@ -2266,11 +2163,16 @@ var ServiceMethodParamsGenerator = class {
|
|
|
2266
2163
|
});
|
|
2267
2164
|
});
|
|
2268
2165
|
if (operation.requestBody && operation.requestBody?.content?.["multipart/form-data"]) {
|
|
2269
|
-
|
|
2166
|
+
const schema = operation.requestBody.content["multipart/form-data"].schema;
|
|
2167
|
+
let resolvedSchema = schema;
|
|
2168
|
+
if (schema?.$ref) {
|
|
2169
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
2170
|
+
}
|
|
2171
|
+
Object.entries(resolvedSchema?.properties ?? {}).forEach(([key, value]) => {
|
|
2270
2172
|
params.push({
|
|
2271
2173
|
name: key,
|
|
2272
2174
|
type: getTypeScriptType(value, this.config, value.nullable),
|
|
2273
|
-
hasQuestionToken: !
|
|
2175
|
+
hasQuestionToken: !resolvedSchema?.required?.includes(key)
|
|
2274
2176
|
});
|
|
2275
2177
|
});
|
|
2276
2178
|
}
|
|
@@ -2336,9 +2238,9 @@ var ServiceMethodOverloadsGenerator = class {
|
|
|
2336
2238
|
config;
|
|
2337
2239
|
paramsGenerator;
|
|
2338
2240
|
responseDataType = "any";
|
|
2339
|
-
constructor(config) {
|
|
2241
|
+
constructor(config, parser) {
|
|
2340
2242
|
this.config = config;
|
|
2341
|
-
this.paramsGenerator = new ServiceMethodParamsGenerator(config);
|
|
2243
|
+
this.paramsGenerator = new ServiceMethodParamsGenerator(config, parser);
|
|
2342
2244
|
}
|
|
2343
2245
|
generateMethodOverloads(operation) {
|
|
2344
2246
|
const observeTypes = [
|
|
@@ -2452,11 +2354,11 @@ var ServiceMethodGenerator = class {
|
|
|
2452
2354
|
bodyGenerator;
|
|
2453
2355
|
overloadsGenerator;
|
|
2454
2356
|
paramsGenerator;
|
|
2455
|
-
constructor(config) {
|
|
2357
|
+
constructor(config, parser) {
|
|
2456
2358
|
this.config = config;
|
|
2457
|
-
this.bodyGenerator = new ServiceMethodBodyGenerator(config);
|
|
2458
|
-
this.overloadsGenerator = new ServiceMethodOverloadsGenerator(config);
|
|
2459
|
-
this.paramsGenerator = new ServiceMethodParamsGenerator(config);
|
|
2359
|
+
this.bodyGenerator = new ServiceMethodBodyGenerator(config, parser);
|
|
2360
|
+
this.overloadsGenerator = new ServiceMethodOverloadsGenerator(config, parser);
|
|
2361
|
+
this.paramsGenerator = new ServiceMethodParamsGenerator(config, parser);
|
|
2460
2362
|
}
|
|
2461
2363
|
addServiceMethod(serviceClass, operation) {
|
|
2462
2364
|
const methodName = this.generateMethodName(operation);
|
|
@@ -2520,7 +2422,7 @@ var ServiceGenerator = class {
|
|
|
2520
2422
|
const versionInfo = this.parser.getSpecVersion();
|
|
2521
2423
|
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"}`);
|
|
2522
2424
|
}
|
|
2523
|
-
this.methodGenerator = new ServiceMethodGenerator(config);
|
|
2425
|
+
this.methodGenerator = new ServiceMethodGenerator(config, parser);
|
|
2524
2426
|
}
|
|
2525
2427
|
async generate(outputRoot) {
|
|
2526
2428
|
const outputDir = path9.join(outputRoot, "services");
|
|
@@ -2558,62 +2460,20 @@ var ServiceGenerator = class {
|
|
|
2558
2460
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
2559
2461
|
overwrite: true
|
|
2560
2462
|
});
|
|
2561
|
-
|
|
2562
|
-
this.addImports(sourceFile, usedTypes);
|
|
2463
|
+
this.addImports(sourceFile);
|
|
2563
2464
|
this.addServiceClass(sourceFile, controllerName, operations);
|
|
2564
|
-
sourceFile.formatText();
|
|
2465
|
+
sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
|
|
2565
2466
|
sourceFile.saveSync();
|
|
2566
2467
|
}
|
|
2567
|
-
addImports(sourceFile
|
|
2568
|
-
const basePathTokenName = getBasePathTokenName(this.config.clientName);
|
|
2569
|
-
const clientContextTokenName = getClientContextTokenName(this.config.clientName);
|
|
2468
|
+
addImports(sourceFile) {
|
|
2570
2469
|
sourceFile.addImportDeclarations([
|
|
2571
2470
|
{
|
|
2572
2471
|
namedImports: [
|
|
2573
|
-
"Injectable"
|
|
2574
|
-
"inject"
|
|
2472
|
+
"Injectable"
|
|
2575
2473
|
],
|
|
2576
2474
|
moduleSpecifier: "@angular/core"
|
|
2577
|
-
},
|
|
2578
|
-
{
|
|
2579
|
-
namedImports: [
|
|
2580
|
-
"HttpClient",
|
|
2581
|
-
"HttpParams",
|
|
2582
|
-
"HttpHeaders",
|
|
2583
|
-
"HttpContext",
|
|
2584
|
-
"HttpResponse",
|
|
2585
|
-
"HttpEvent",
|
|
2586
|
-
"HttpContextToken"
|
|
2587
|
-
],
|
|
2588
|
-
moduleSpecifier: "@angular/common/http"
|
|
2589
|
-
},
|
|
2590
|
-
{
|
|
2591
|
-
namedImports: [
|
|
2592
|
-
"Observable",
|
|
2593
|
-
"map"
|
|
2594
|
-
],
|
|
2595
|
-
moduleSpecifier: "rxjs"
|
|
2596
|
-
},
|
|
2597
|
-
{
|
|
2598
|
-
namedImports: [
|
|
2599
|
-
basePathTokenName,
|
|
2600
|
-
clientContextTokenName
|
|
2601
|
-
],
|
|
2602
|
-
moduleSpecifier: "../tokens"
|
|
2603
|
-
},
|
|
2604
|
-
{
|
|
2605
|
-
namedImports: [
|
|
2606
|
-
"HttpParamsBuilder"
|
|
2607
|
-
],
|
|
2608
|
-
moduleSpecifier: "../index"
|
|
2609
2475
|
}
|
|
2610
2476
|
]);
|
|
2611
|
-
if (usedTypes.size > 0) {
|
|
2612
|
-
sourceFile.addImportDeclaration({
|
|
2613
|
-
namedImports: Array.from(usedTypes).sort(),
|
|
2614
|
-
moduleSpecifier: "../models"
|
|
2615
|
-
});
|
|
2616
|
-
}
|
|
2617
2477
|
}
|
|
2618
2478
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2619
2479
|
const className = `${controllerName}Service`;
|
|
@@ -2765,15 +2625,15 @@ async function generateFromConfig(config) {
|
|
|
2765
2625
|
fileDownloadHelper.generate(outputPath);
|
|
2766
2626
|
const httpParamsBuilderGenerator = new HttpParamsBuilderGenerator(project);
|
|
2767
2627
|
httpParamsBuilderGenerator.generate(outputPath);
|
|
2628
|
+
const providerGenerator = new ProviderGenerator(project, config);
|
|
2629
|
+
providerGenerator.generate(outputPath);
|
|
2630
|
+
const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
|
|
2631
|
+
baseInterceptorGenerator.generate(outputPath);
|
|
2768
2632
|
const serviceGenerator = new ServiceGenerator(swaggerParser, project, config);
|
|
2769
2633
|
await serviceGenerator.generate(outputPath);
|
|
2770
2634
|
const indexGenerator = new ServiceIndexGenerator(project);
|
|
2771
2635
|
indexGenerator.generateIndex(outputPath);
|
|
2772
2636
|
console.log(`\u2705 Angular services generated`);
|
|
2773
|
-
const providerGenerator = new ProviderGenerator(project, config);
|
|
2774
|
-
providerGenerator.generate(outputPath);
|
|
2775
|
-
const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
|
|
2776
|
-
baseInterceptorGenerator.generate(outputPath);
|
|
2777
2637
|
}
|
|
2778
2638
|
if (config.plugins?.length) {
|
|
2779
2639
|
for (const plugin of config.plugins) {
|
package/index.d.ts
CHANGED
|
@@ -237,8 +237,6 @@ declare function escapeString(str: string): string;
|
|
|
237
237
|
|
|
238
238
|
type placeHolder = {};
|
|
239
239
|
|
|
240
|
-
declare function collectUsedTypes(operations: PathInfo[]): Set<string>;
|
|
241
|
-
|
|
242
240
|
declare function getClientContextTokenName(clientName?: string): string;
|
|
243
241
|
declare function getBasePathTokenName(clientName?: string): string;
|
|
244
242
|
|
|
@@ -268,6 +266,8 @@ declare const MAIN_INDEX_GENERATOR_HEADER_COMMENT: string;
|
|
|
268
266
|
declare const PROVIDER_GENERATOR_HEADER_COMMENT: string;
|
|
269
267
|
declare const BASE_INTERCEPTOR_HEADER_COMMENT: (clientName: string) => string;
|
|
270
268
|
declare const HTTP_RESOURCE_GENERATOR_HEADER_COMMENT: (resourceName: string) => string;
|
|
269
|
+
declare const ZOD_PLUGIN_GENERATOR_HEADER_COMMENT: (validatorName: string) => string;
|
|
270
|
+
declare const ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT: string;
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
273
|
* Validates input (file or URL)
|
|
@@ -278,4 +278,4 @@ declare function validateInput(inputPath: string): void;
|
|
|
278
278
|
*/
|
|
279
279
|
declare function generateFromConfig(config: GeneratorConfig): Promise<void>;
|
|
280
280
|
|
|
281
|
-
export { BASE_INTERCEPTOR_HEADER_COMMENT, type EnumValueObject, type GeneratorConfig, type GetMethodGenerationContext, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT, type IPluginGenerator, type IPluginGeneratorClass, MAIN_INDEX_GENERATOR_HEADER_COMMENT, type MethodGenerationContext, type NgOpenapiClientConfig, PROVIDER_GENERATOR_HEADER_COMMENT, type Parameter, type PathInfo, type RequestBody, SERVICE_GENERATOR_HEADER_COMMENT, SERVICE_INDEX_GENERATOR_HEADER_COMMENT, type SwaggerDefinition, SwaggerParser, type SwaggerResponse, type SwaggerSpec, TYPE_GENERATOR_HEADER_COMMENT, type TypeSchema,
|
|
281
|
+
export { BASE_INTERCEPTOR_HEADER_COMMENT, type EnumValueObject, type GeneratorConfig, type GetMethodGenerationContext, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT, type IPluginGenerator, type IPluginGeneratorClass, MAIN_INDEX_GENERATOR_HEADER_COMMENT, type MethodGenerationContext, type NgOpenapiClientConfig, PROVIDER_GENERATOR_HEADER_COMMENT, type Parameter, type PathInfo, type RequestBody, SERVICE_GENERATOR_HEADER_COMMENT, SERVICE_INDEX_GENERATOR_HEADER_COMMENT, type SwaggerDefinition, SwaggerParser, type SwaggerResponse, type SwaggerSpec, TYPE_GENERATOR_HEADER_COMMENT, type TypeSchema, ZOD_PLUGIN_GENERATOR_HEADER_COMMENT, ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT, camelCase, escapeString, extractPaths, generateFromConfig, generateParseRequestTypeParams, getBasePathTokenName, getClientContextTokenName, getRequestBodyType, getResponseType, getResponseTypeFromResponse, getTypeScriptType, hasDuplicateFunctionNames, inferResponseTypeFromContentType, isDataTypeInterface, isPrimitiveType, kebabCase, nullableType, pascalCase, type placeHolder, screamingSnakeCase, validateInput };
|
package/index.js
CHANGED
|
@@ -81,8 +81,9 @@ __export(index_exports, {
|
|
|
81
81
|
SERVICE_INDEX_GENERATOR_HEADER_COMMENT: () => SERVICE_INDEX_GENERATOR_HEADER_COMMENT,
|
|
82
82
|
SwaggerParser: () => SwaggerParser,
|
|
83
83
|
TYPE_GENERATOR_HEADER_COMMENT: () => TYPE_GENERATOR_HEADER_COMMENT,
|
|
84
|
+
ZOD_PLUGIN_GENERATOR_HEADER_COMMENT: () => ZOD_PLUGIN_GENERATOR_HEADER_COMMENT,
|
|
85
|
+
ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT: () => ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT,
|
|
84
86
|
camelCase: () => camelCase,
|
|
85
|
-
collectUsedTypes: () => collectUsedTypes,
|
|
86
87
|
escapeString: () => escapeString,
|
|
87
88
|
extractPaths: () => extractPaths,
|
|
88
89
|
generateFromConfig: () => generateFromConfig,
|
|
@@ -174,7 +175,7 @@ function getTypeScriptType(schemaOrType, config, formatOrNullable, isNullable, c
|
|
|
174
175
|
case "boolean":
|
|
175
176
|
return nullableType("boolean", nullable);
|
|
176
177
|
case "object":
|
|
177
|
-
return nullableType(context === "type" ? "Record<string,
|
|
178
|
+
return nullableType(context === "type" ? "Record<string, any>" : "any", nullable);
|
|
178
179
|
case "null":
|
|
179
180
|
return "null";
|
|
180
181
|
default:
|
|
@@ -191,79 +192,6 @@ function escapeString(str) {
|
|
|
191
192
|
}
|
|
192
193
|
__name(escapeString, "escapeString");
|
|
193
194
|
|
|
194
|
-
// ../shared/src/utils/functions/collect-used-types.ts
|
|
195
|
-
function collectUsedTypes(operations) {
|
|
196
|
-
const usedTypes = /* @__PURE__ */ new Set();
|
|
197
|
-
usedTypes.add("RequestOptions");
|
|
198
|
-
operations.forEach((operation) => {
|
|
199
|
-
var _a;
|
|
200
|
-
(_a = operation.parameters) == null ? void 0 : _a.forEach((param) => {
|
|
201
|
-
collectTypesFromSchema(param.schema || param, usedTypes);
|
|
202
|
-
});
|
|
203
|
-
if (operation.requestBody) {
|
|
204
|
-
collectTypesFromRequestBody(operation.requestBody, usedTypes);
|
|
205
|
-
}
|
|
206
|
-
if (operation.responses) {
|
|
207
|
-
Object.values(operation.responses).forEach((response) => {
|
|
208
|
-
collectTypesFromResponse(response, usedTypes);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
return usedTypes;
|
|
213
|
-
}
|
|
214
|
-
__name(collectUsedTypes, "collectUsedTypes");
|
|
215
|
-
function collectTypesFromSchema(schema, usedTypes) {
|
|
216
|
-
if (!schema) return;
|
|
217
|
-
if (schema.$ref) {
|
|
218
|
-
const refName = schema.$ref.split("/").pop();
|
|
219
|
-
if (refName) {
|
|
220
|
-
usedTypes.add(pascalCase(refName));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (schema.type === "array" && schema.items) {
|
|
224
|
-
collectTypesFromSchema(schema.items, usedTypes);
|
|
225
|
-
}
|
|
226
|
-
if (schema.type === "object" && schema.properties) {
|
|
227
|
-
Object.values(schema.properties).forEach((prop) => {
|
|
228
|
-
collectTypesFromSchema(prop, usedTypes);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (schema.allOf) {
|
|
232
|
-
schema.allOf.forEach((subSchema) => {
|
|
233
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
if (schema.oneOf) {
|
|
237
|
-
schema.oneOf.forEach((subSchema) => {
|
|
238
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
if (schema.anyOf) {
|
|
242
|
-
schema.anyOf.forEach((subSchema) => {
|
|
243
|
-
collectTypesFromSchema(subSchema, usedTypes);
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
__name(collectTypesFromSchema, "collectTypesFromSchema");
|
|
248
|
-
function collectTypesFromRequestBody(requestBody, usedTypes) {
|
|
249
|
-
const content = requestBody.content || {};
|
|
250
|
-
Object.values(content).forEach((mediaType) => {
|
|
251
|
-
if (mediaType.schema) {
|
|
252
|
-
collectTypesFromSchema(mediaType.schema, usedTypes);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
__name(collectTypesFromRequestBody, "collectTypesFromRequestBody");
|
|
257
|
-
function collectTypesFromResponse(response, usedTypes) {
|
|
258
|
-
const content = response.content || {};
|
|
259
|
-
Object.values(content).forEach((mediaType) => {
|
|
260
|
-
if (mediaType.schema) {
|
|
261
|
-
collectTypesFromSchema(mediaType.schema, usedTypes);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
__name(collectTypesFromResponse, "collectTypesFromResponse");
|
|
266
|
-
|
|
267
195
|
// ../shared/src/utils/functions/token-names.ts
|
|
268
196
|
function getClientContextTokenName(clientName = "default") {
|
|
269
197
|
const clientSuffix = clientName.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
@@ -546,6 +474,14 @@ var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceNam
|
|
|
546
474
|
* Do not edit this file manually
|
|
547
475
|
*/
|
|
548
476
|
`, "HTTP_RESOURCE_GENERATOR_HEADER_COMMENT");
|
|
477
|
+
var ZOD_PLUGIN_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((validatorName) => defaultHeaderComment + `* Generated Zod Schemas for ${validatorName}
|
|
478
|
+
* Do not edit this file manually
|
|
479
|
+
*/
|
|
480
|
+
`, "ZOD_PLUGIN_GENERATOR_HEADER_COMMENT");
|
|
481
|
+
var ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT = defaultHeaderComment + `* Generated Zod Schemas exports
|
|
482
|
+
* Do not edit this file manually
|
|
483
|
+
*/
|
|
484
|
+
`;
|
|
549
485
|
|
|
550
486
|
// ../shared/src/core/swagger-parser.ts
|
|
551
487
|
var fs = __toESM(require("fs"));
|
|
@@ -1308,18 +1244,6 @@ var _FileDownloadGenerator = class _FileDownloadGenerator {
|
|
|
1308
1244
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1309
1245
|
overwrite: true
|
|
1310
1246
|
});
|
|
1311
|
-
sourceFile.addImportDeclaration({
|
|
1312
|
-
namedImports: [
|
|
1313
|
-
"Observable"
|
|
1314
|
-
],
|
|
1315
|
-
moduleSpecifier: "rxjs"
|
|
1316
|
-
});
|
|
1317
|
-
sourceFile.addImportDeclaration({
|
|
1318
|
-
namedImports: [
|
|
1319
|
-
"tap"
|
|
1320
|
-
],
|
|
1321
|
-
moduleSpecifier: "rxjs/operators"
|
|
1322
|
-
});
|
|
1323
1247
|
sourceFile.addFunction({
|
|
1324
1248
|
name: "downloadFile",
|
|
1325
1249
|
isExported: true,
|
|
@@ -1429,7 +1353,7 @@ var _FileDownloadGenerator = class _FileDownloadGenerator {
|
|
|
1429
1353
|
|
|
1430
1354
|
return fallbackFilename;`
|
|
1431
1355
|
});
|
|
1432
|
-
sourceFile.formatText();
|
|
1356
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1433
1357
|
sourceFile.saveSync();
|
|
1434
1358
|
}
|
|
1435
1359
|
};
|
|
@@ -1450,34 +1374,6 @@ var _DateTransformerGenerator = class _DateTransformerGenerator {
|
|
|
1450
1374
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
1451
1375
|
overwrite: true
|
|
1452
1376
|
});
|
|
1453
|
-
sourceFile.addImportDeclaration({
|
|
1454
|
-
namedImports: [
|
|
1455
|
-
"HttpInterceptor",
|
|
1456
|
-
"HttpRequest",
|
|
1457
|
-
"HttpHandler",
|
|
1458
|
-
"HttpEvent",
|
|
1459
|
-
"HttpResponse"
|
|
1460
|
-
],
|
|
1461
|
-
moduleSpecifier: "@angular/common/http"
|
|
1462
|
-
});
|
|
1463
|
-
sourceFile.addImportDeclaration({
|
|
1464
|
-
namedImports: [
|
|
1465
|
-
"Injectable"
|
|
1466
|
-
],
|
|
1467
|
-
moduleSpecifier: "@angular/core"
|
|
1468
|
-
});
|
|
1469
|
-
sourceFile.addImportDeclaration({
|
|
1470
|
-
namedImports: [
|
|
1471
|
-
"Observable"
|
|
1472
|
-
],
|
|
1473
|
-
moduleSpecifier: "rxjs"
|
|
1474
|
-
});
|
|
1475
|
-
sourceFile.addImportDeclaration({
|
|
1476
|
-
namedImports: [
|
|
1477
|
-
"map"
|
|
1478
|
-
],
|
|
1479
|
-
moduleSpecifier: "rxjs/operators"
|
|
1480
|
-
});
|
|
1481
1377
|
sourceFile.addVariableStatement({
|
|
1482
1378
|
isExported: true,
|
|
1483
1379
|
declarationKind: import_ts_morph3.VariableDeclarationKind.Const,
|
|
@@ -1564,7 +1460,7 @@ var _DateTransformerGenerator = class _DateTransformerGenerator {
|
|
|
1564
1460
|
}
|
|
1565
1461
|
]
|
|
1566
1462
|
});
|
|
1567
|
-
sourceFile.formatText();
|
|
1463
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1568
1464
|
sourceFile.saveSync();
|
|
1569
1465
|
}
|
|
1570
1466
|
};
|
|
@@ -1847,33 +1743,9 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1847
1743
|
sourceFile.addImportDeclarations([
|
|
1848
1744
|
{
|
|
1849
1745
|
namedImports: [
|
|
1850
|
-
"HttpEvent",
|
|
1851
|
-
"HttpHandler",
|
|
1852
|
-
"HttpInterceptor",
|
|
1853
|
-
"HttpRequest",
|
|
1854
|
-
"HttpContextToken"
|
|
1855
|
-
],
|
|
1856
|
-
moduleSpecifier: "@angular/common/http"
|
|
1857
|
-
},
|
|
1858
|
-
{
|
|
1859
|
-
namedImports: [
|
|
1860
|
-
"inject",
|
|
1861
1746
|
"Injectable"
|
|
1862
1747
|
],
|
|
1863
1748
|
moduleSpecifier: "@angular/core"
|
|
1864
|
-
},
|
|
1865
|
-
{
|
|
1866
|
-
namedImports: [
|
|
1867
|
-
"Observable"
|
|
1868
|
-
],
|
|
1869
|
-
moduleSpecifier: "rxjs"
|
|
1870
|
-
},
|
|
1871
|
-
{
|
|
1872
|
-
namedImports: [
|
|
1873
|
-
interceptorsTokenName,
|
|
1874
|
-
clientContextTokenName
|
|
1875
|
-
],
|
|
1876
|
-
moduleSpecifier: "../tokens"
|
|
1877
1749
|
}
|
|
1878
1750
|
]);
|
|
1879
1751
|
sourceFile.addClass({
|
|
@@ -1939,7 +1811,7 @@ var _BaseInterceptorGenerator = class _BaseInterceptorGenerator {
|
|
|
1939
1811
|
}
|
|
1940
1812
|
]
|
|
1941
1813
|
});
|
|
1942
|
-
sourceFile.formatText();
|
|
1814
|
+
sourceFile.fixMissingImports().organizeImports().formatText();
|
|
1943
1815
|
sourceFile.saveSync();
|
|
1944
1816
|
}
|
|
1945
1817
|
getInterceptorsTokenName() {
|
|
@@ -2174,9 +2046,11 @@ var path9 = __toESM(require("path"));
|
|
|
2174
2046
|
|
|
2175
2047
|
// src/lib/generators/service/service-method/service-method-body.generator.ts
|
|
2176
2048
|
var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
|
|
2177
|
-
constructor(config) {
|
|
2049
|
+
constructor(config, parser) {
|
|
2178
2050
|
__publicField(this, "config");
|
|
2051
|
+
__publicField(this, "parser");
|
|
2179
2052
|
this.config = config;
|
|
2053
|
+
this.parser = parser;
|
|
2180
2054
|
}
|
|
2181
2055
|
generateMethodBody(operation) {
|
|
2182
2056
|
const context = this.createGenerationContext(operation);
|
|
@@ -2195,11 +2069,16 @@ var _ServiceMethodBodyGenerator = class _ServiceMethodBodyGenerator {
|
|
|
2195
2069
|
return !!((_b = (_a = operation.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b["multipart/form-data"]);
|
|
2196
2070
|
}
|
|
2197
2071
|
getFormDataFields(operation) {
|
|
2198
|
-
var _a, _b
|
|
2072
|
+
var _a, _b;
|
|
2199
2073
|
if (!this.isMultipartFormData(operation)) {
|
|
2200
2074
|
return [];
|
|
2201
2075
|
}
|
|
2202
|
-
const
|
|
2076
|
+
const schema = (_b = (_a = operation.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b["multipart/form-data"].schema;
|
|
2077
|
+
let resolvedSchema = schema;
|
|
2078
|
+
if (schema == null ? void 0 : schema.$ref) {
|
|
2079
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
2080
|
+
}
|
|
2081
|
+
const properties = (resolvedSchema == null ? void 0 : resolvedSchema.properties) || {};
|
|
2203
2082
|
return Object.keys(properties);
|
|
2204
2083
|
}
|
|
2205
2084
|
createGenerationContext(operation) {
|
|
@@ -2266,17 +2145,37 @@ if (!headers.has('Content-Type')) {
|
|
|
2266
2145
|
return headerCode;
|
|
2267
2146
|
}
|
|
2268
2147
|
generateMultipartFormData(operation, context) {
|
|
2148
|
+
var _a, _b;
|
|
2269
2149
|
if (!context.isMultipart || context.formDataFields.length === 0) {
|
|
2270
2150
|
return "";
|
|
2271
2151
|
}
|
|
2152
|
+
const schema = (_b = (_a = operation.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b["multipart/form-data"].schema;
|
|
2153
|
+
let resolvedSchema = schema;
|
|
2154
|
+
if (schema == null ? void 0 : schema.$ref) {
|
|
2155
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
2156
|
+
}
|
|
2157
|
+
const properties = (resolvedSchema == null ? void 0 : resolvedSchema.properties) || {};
|
|
2272
2158
|
const formDataAppends = context.formDataFields.map((field) => {
|
|
2273
|
-
|
|
2274
|
-
const fieldSchema = (_e = (_d = (_c = (_b = (_a = operation.requestBody) == null ? void 0 : _a.content) == null ? void 0 : _b["multipart/form-data"]) == null ? void 0 : _c.schema) == null ? void 0 : _d.properties) == null ? void 0 : _e[field];
|
|
2159
|
+
const fieldSchema = properties[field];
|
|
2275
2160
|
const isFile = (fieldSchema == null ? void 0 : fieldSchema.type) === "string" && (fieldSchema == null ? void 0 : fieldSchema.format) === "binary";
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2161
|
+
const isArray = (fieldSchema == null ? void 0 : fieldSchema.type) === "array";
|
|
2162
|
+
if (isArray) {
|
|
2163
|
+
const itemSchema = Array.isArray(fieldSchema.items) ? fieldSchema.items[0] : fieldSchema.items;
|
|
2164
|
+
const isFileArray = (itemSchema == null ? void 0 : itemSchema.type) === "string" && (itemSchema == null ? void 0 : itemSchema.format) === "binary";
|
|
2165
|
+
const valueExpression = isFileArray ? "item" : "String(item)";
|
|
2166
|
+
return `if (${field} !== undefined && Array.isArray(${field})) {
|
|
2167
|
+
${field}.forEach((item) => {
|
|
2168
|
+
if (item !== undefined && item !== null) {
|
|
2169
|
+
formData.append('${field}', ${valueExpression});
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
}`;
|
|
2173
|
+
} else {
|
|
2174
|
+
const valueExpression = isFile ? field : `String(${field})`;
|
|
2175
|
+
return `if (${field} !== undefined) {
|
|
2176
|
+
formData.append('${field}', ${valueExpression});
|
|
2177
|
+
}`;
|
|
2178
|
+
}
|
|
2280
2179
|
}).join("\n");
|
|
2281
2180
|
return `
|
|
2282
2181
|
const formData = new FormData();
|
|
@@ -2353,9 +2252,11 @@ var ServiceMethodBodyGenerator = _ServiceMethodBodyGenerator;
|
|
|
2353
2252
|
|
|
2354
2253
|
// src/lib/generators/service/service-method/service-method-params.generator.ts
|
|
2355
2254
|
var _ServiceMethodParamsGenerator = class _ServiceMethodParamsGenerator {
|
|
2356
|
-
constructor(config) {
|
|
2255
|
+
constructor(config, parser) {
|
|
2357
2256
|
__publicField(this, "config");
|
|
2257
|
+
__publicField(this, "parser");
|
|
2358
2258
|
this.config = config;
|
|
2259
|
+
this.parser = parser;
|
|
2359
2260
|
}
|
|
2360
2261
|
generateMethodParameters(operation) {
|
|
2361
2262
|
const params = this.generateApiParameters(operation);
|
|
@@ -2375,7 +2276,7 @@ var _ServiceMethodParamsGenerator = class _ServiceMethodParamsGenerator {
|
|
|
2375
2276
|
return uniqueParams;
|
|
2376
2277
|
}
|
|
2377
2278
|
generateApiParameters(operation) {
|
|
2378
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
2279
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2379
2280
|
const params = [];
|
|
2380
2281
|
const pathParams = ((_a = operation.parameters) == null ? void 0 : _a.filter((p) => p.in === "path")) || [];
|
|
2381
2282
|
pathParams.forEach((param) => {
|
|
@@ -2386,15 +2287,21 @@ var _ServiceMethodParamsGenerator = class _ServiceMethodParamsGenerator {
|
|
|
2386
2287
|
});
|
|
2387
2288
|
});
|
|
2388
2289
|
if (operation.requestBody && ((_c = (_b = operation.requestBody) == null ? void 0 : _b.content) == null ? void 0 : _c["multipart/form-data"])) {
|
|
2389
|
-
|
|
2290
|
+
const schema = operation.requestBody.content["multipart/form-data"].schema;
|
|
2291
|
+
let resolvedSchema = schema;
|
|
2292
|
+
if (schema == null ? void 0 : schema.$ref) {
|
|
2293
|
+
resolvedSchema = this.parser.resolveReference(schema.$ref);
|
|
2294
|
+
}
|
|
2295
|
+
Object.entries((_d = resolvedSchema == null ? void 0 : resolvedSchema.properties) != null ? _d : {}).forEach(([key, value]) => {
|
|
2296
|
+
var _a2;
|
|
2390
2297
|
params.push({
|
|
2391
2298
|
name: key,
|
|
2392
2299
|
type: getTypeScriptType(value, this.config, value.nullable),
|
|
2393
|
-
hasQuestionToken: !
|
|
2300
|
+
hasQuestionToken: !((_a2 = resolvedSchema == null ? void 0 : resolvedSchema.required) == null ? void 0 : _a2.includes(key))
|
|
2394
2301
|
});
|
|
2395
2302
|
});
|
|
2396
2303
|
}
|
|
2397
|
-
if (operation.requestBody && ((
|
|
2304
|
+
if (operation.requestBody && ((_f = (_e = operation.requestBody) == null ? void 0 : _e.content) == null ? void 0 : _f["application/json"])) {
|
|
2398
2305
|
const bodyType = this.getRequestBodyType(operation.requestBody);
|
|
2399
2306
|
const isInterface = isDataTypeInterface(bodyType);
|
|
2400
2307
|
params.push({
|
|
@@ -2403,7 +2310,7 @@ var _ServiceMethodParamsGenerator = class _ServiceMethodParamsGenerator {
|
|
|
2403
2310
|
hasQuestionToken: !operation.requestBody.required
|
|
2404
2311
|
});
|
|
2405
2312
|
}
|
|
2406
|
-
const queryParams = ((
|
|
2313
|
+
const queryParams = ((_g = operation.parameters) == null ? void 0 : _g.filter((p) => p.in === "query")) || [];
|
|
2407
2314
|
queryParams.forEach((param) => {
|
|
2408
2315
|
params.push({
|
|
2409
2316
|
name: param.name,
|
|
@@ -2453,12 +2360,12 @@ var ServiceMethodParamsGenerator = _ServiceMethodParamsGenerator;
|
|
|
2453
2360
|
|
|
2454
2361
|
// src/lib/generators/service/service-method/service-method-overloads.generator.ts
|
|
2455
2362
|
var _ServiceMethodOverloadsGenerator = class _ServiceMethodOverloadsGenerator {
|
|
2456
|
-
constructor(config) {
|
|
2363
|
+
constructor(config, parser) {
|
|
2457
2364
|
__publicField(this, "config");
|
|
2458
2365
|
__publicField(this, "paramsGenerator");
|
|
2459
2366
|
__publicField(this, "responseDataType", "any");
|
|
2460
2367
|
this.config = config;
|
|
2461
|
-
this.paramsGenerator = new ServiceMethodParamsGenerator(config);
|
|
2368
|
+
this.paramsGenerator = new ServiceMethodParamsGenerator(config, parser);
|
|
2462
2369
|
}
|
|
2463
2370
|
generateMethodOverloads(operation) {
|
|
2464
2371
|
const observeTypes = [
|
|
@@ -2570,15 +2477,15 @@ var ServiceMethodOverloadsGenerator = _ServiceMethodOverloadsGenerator;
|
|
|
2570
2477
|
|
|
2571
2478
|
// src/lib/generators/service/service-method.generator.ts
|
|
2572
2479
|
var _ServiceMethodGenerator = class _ServiceMethodGenerator {
|
|
2573
|
-
constructor(config) {
|
|
2480
|
+
constructor(config, parser) {
|
|
2574
2481
|
__publicField(this, "config");
|
|
2575
2482
|
__publicField(this, "bodyGenerator");
|
|
2576
2483
|
__publicField(this, "overloadsGenerator");
|
|
2577
2484
|
__publicField(this, "paramsGenerator");
|
|
2578
2485
|
this.config = config;
|
|
2579
|
-
this.bodyGenerator = new ServiceMethodBodyGenerator(config);
|
|
2580
|
-
this.overloadsGenerator = new ServiceMethodOverloadsGenerator(config);
|
|
2581
|
-
this.paramsGenerator = new ServiceMethodParamsGenerator(config);
|
|
2486
|
+
this.bodyGenerator = new ServiceMethodBodyGenerator(config, parser);
|
|
2487
|
+
this.overloadsGenerator = new ServiceMethodOverloadsGenerator(config, parser);
|
|
2488
|
+
this.paramsGenerator = new ServiceMethodParamsGenerator(config, parser);
|
|
2582
2489
|
}
|
|
2583
2490
|
addServiceMethod(serviceClass, operation) {
|
|
2584
2491
|
const methodName = this.generateMethodName(operation);
|
|
@@ -2641,7 +2548,7 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2641
2548
|
const versionInfo = this.parser.getSpecVersion();
|
|
2642
2549
|
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"}`);
|
|
2643
2550
|
}
|
|
2644
|
-
this.methodGenerator = new ServiceMethodGenerator(config);
|
|
2551
|
+
this.methodGenerator = new ServiceMethodGenerator(config, parser);
|
|
2645
2552
|
}
|
|
2646
2553
|
generate(outputRoot) {
|
|
2647
2554
|
return __async(this, null, function* () {
|
|
@@ -2682,63 +2589,21 @@ var _ServiceGenerator = class _ServiceGenerator {
|
|
|
2682
2589
|
const sourceFile = this.project.createSourceFile(filePath, "", {
|
|
2683
2590
|
overwrite: true
|
|
2684
2591
|
});
|
|
2685
|
-
|
|
2686
|
-
this.addImports(sourceFile, usedTypes);
|
|
2592
|
+
this.addImports(sourceFile);
|
|
2687
2593
|
this.addServiceClass(sourceFile, controllerName, operations);
|
|
2688
|
-
sourceFile.formatText();
|
|
2594
|
+
sourceFile.fixMissingImports().organizeImports().fixUnusedIdentifiers().formatText();
|
|
2689
2595
|
sourceFile.saveSync();
|
|
2690
2596
|
});
|
|
2691
2597
|
}
|
|
2692
|
-
addImports(sourceFile
|
|
2693
|
-
const basePathTokenName = getBasePathTokenName(this.config.clientName);
|
|
2694
|
-
const clientContextTokenName = getClientContextTokenName(this.config.clientName);
|
|
2598
|
+
addImports(sourceFile) {
|
|
2695
2599
|
sourceFile.addImportDeclarations([
|
|
2696
2600
|
{
|
|
2697
2601
|
namedImports: [
|
|
2698
|
-
"Injectable"
|
|
2699
|
-
"inject"
|
|
2602
|
+
"Injectable"
|
|
2700
2603
|
],
|
|
2701
2604
|
moduleSpecifier: "@angular/core"
|
|
2702
|
-
},
|
|
2703
|
-
{
|
|
2704
|
-
namedImports: [
|
|
2705
|
-
"HttpClient",
|
|
2706
|
-
"HttpParams",
|
|
2707
|
-
"HttpHeaders",
|
|
2708
|
-
"HttpContext",
|
|
2709
|
-
"HttpResponse",
|
|
2710
|
-
"HttpEvent",
|
|
2711
|
-
"HttpContextToken"
|
|
2712
|
-
],
|
|
2713
|
-
moduleSpecifier: "@angular/common/http"
|
|
2714
|
-
},
|
|
2715
|
-
{
|
|
2716
|
-
namedImports: [
|
|
2717
|
-
"Observable",
|
|
2718
|
-
"map"
|
|
2719
|
-
],
|
|
2720
|
-
moduleSpecifier: "rxjs"
|
|
2721
|
-
},
|
|
2722
|
-
{
|
|
2723
|
-
namedImports: [
|
|
2724
|
-
basePathTokenName,
|
|
2725
|
-
clientContextTokenName
|
|
2726
|
-
],
|
|
2727
|
-
moduleSpecifier: "../tokens"
|
|
2728
|
-
},
|
|
2729
|
-
{
|
|
2730
|
-
namedImports: [
|
|
2731
|
-
"HttpParamsBuilder"
|
|
2732
|
-
],
|
|
2733
|
-
moduleSpecifier: "../index"
|
|
2734
2605
|
}
|
|
2735
2606
|
]);
|
|
2736
|
-
if (usedTypes.size > 0) {
|
|
2737
|
-
sourceFile.addImportDeclaration({
|
|
2738
|
-
namedImports: Array.from(usedTypes).sort(),
|
|
2739
|
-
moduleSpecifier: "../models"
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
2607
|
}
|
|
2743
2608
|
addServiceClass(sourceFile, controllerName, operations) {
|
|
2744
2609
|
const className = `${controllerName}Service`;
|
|
@@ -2892,15 +2757,15 @@ function generateFromConfig(config) {
|
|
|
2892
2757
|
fileDownloadHelper.generate(outputPath);
|
|
2893
2758
|
const httpParamsBuilderGenerator = new HttpParamsBuilderGenerator(project);
|
|
2894
2759
|
httpParamsBuilderGenerator.generate(outputPath);
|
|
2760
|
+
const providerGenerator = new ProviderGenerator(project, config);
|
|
2761
|
+
providerGenerator.generate(outputPath);
|
|
2762
|
+
const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
|
|
2763
|
+
baseInterceptorGenerator.generate(outputPath);
|
|
2895
2764
|
const serviceGenerator = new ServiceGenerator(swaggerParser, project, config);
|
|
2896
2765
|
yield serviceGenerator.generate(outputPath);
|
|
2897
2766
|
const indexGenerator = new ServiceIndexGenerator(project);
|
|
2898
2767
|
indexGenerator.generateIndex(outputPath);
|
|
2899
2768
|
console.log(`\u2705 Angular services generated`);
|
|
2900
|
-
const providerGenerator = new ProviderGenerator(project, config);
|
|
2901
|
-
providerGenerator.generate(outputPath);
|
|
2902
|
-
const baseInterceptorGenerator = new BaseInterceptorGenerator(project, config.clientName);
|
|
2903
|
-
baseInterceptorGenerator.generate(outputPath);
|
|
2904
2769
|
}
|
|
2905
2770
|
if ((_b = config.plugins) == null ? void 0 : _b.length) {
|
|
2906
2771
|
for (const plugin of config.plugins) {
|
|
@@ -2943,8 +2808,9 @@ __name(generateFromConfig, "generateFromConfig");
|
|
|
2943
2808
|
SERVICE_INDEX_GENERATOR_HEADER_COMMENT,
|
|
2944
2809
|
SwaggerParser,
|
|
2945
2810
|
TYPE_GENERATOR_HEADER_COMMENT,
|
|
2811
|
+
ZOD_PLUGIN_GENERATOR_HEADER_COMMENT,
|
|
2812
|
+
ZOD_PLUGIN_INDEX_GENERATOR_HEADER_COMMENT,
|
|
2946
2813
|
camelCase,
|
|
2947
|
-
collectUsedTypes,
|
|
2948
2814
|
escapeString,
|
|
2949
2815
|
extractPaths,
|
|
2950
2816
|
generateFromConfig,
|
package/package.json
CHANGED