api-core-lib 12.0.69 → 12.0.72
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/dist/cli.cjs +142 -95
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -76,7 +76,7 @@ var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"), 1);
|
|
|
76
76
|
var import_openapi_types = __toESM(require_dist(), 1);
|
|
77
77
|
var DEBUG_MODE = process.env.DEBUG === "true";
|
|
78
78
|
var debugLog = (title, data) => DEBUG_MODE && console.log(import_chalk.default.yellow(`
|
|
79
|
-
[DEBUG: ${title}]`), import_util.default.inspect(data, { depth, colors: true }));
|
|
79
|
+
[DEBUG: ${title}]`), import_util.default.inspect(data, { depth: 4, colors: true }));
|
|
80
80
|
var toPascalCase = (str) => str.replace(/[^a-zA-Z0-9_]/g, " ").replace(/(?:^\w|[A-Z]|\b\w)/g, (w) => w.toUpperCase()).replace(/\s+/g, "");
|
|
81
81
|
var toCamelCase = (str) => {
|
|
82
82
|
const s = toPascalCase(str);
|
|
@@ -94,20 +94,14 @@ var findCommonPath = (paths) => {
|
|
|
94
94
|
const prefix = first.substring(0, i);
|
|
95
95
|
return prefix.substring(0, prefix.lastIndexOf("/") + 1) || "/";
|
|
96
96
|
};
|
|
97
|
-
|
|
98
|
-
const friendlyName = fieldName.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase());
|
|
99
|
-
return `${friendlyName} is required.`;
|
|
100
|
-
};
|
|
101
|
-
function parseSchema(name, schema, allEnums) {
|
|
97
|
+
function parseSchema(name, schema) {
|
|
102
98
|
const properties = [];
|
|
103
|
-
const enums = {};
|
|
104
99
|
if (schema.properties) {
|
|
105
100
|
for (const propName in schema.properties) {
|
|
106
101
|
const propSchema = schema.properties[propName];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!allEnums.has(enumName)) allEnums.set(enumName, { name: enumName, values: propSchema.enum });
|
|
102
|
+
let items = void 0;
|
|
103
|
+
if (propSchema.type === "array" && propSchema.items) {
|
|
104
|
+
items = parseSchema("item", propSchema.items).properties[0];
|
|
111
105
|
}
|
|
112
106
|
properties.push({
|
|
113
107
|
name: propName,
|
|
@@ -118,24 +112,24 @@ function parseSchema(name, schema, allEnums) {
|
|
|
118
112
|
example: propSchema.example,
|
|
119
113
|
enum: propSchema.enum,
|
|
120
114
|
format: propSchema.format,
|
|
121
|
-
items
|
|
122
|
-
|
|
115
|
+
items,
|
|
116
|
+
// نستخدم المتغير الذي تم حسابه بأمان
|
|
117
|
+
properties: propSchema.properties ? parseSchema("sub-object", propSchema).properties : void 0
|
|
123
118
|
});
|
|
124
119
|
}
|
|
125
120
|
}
|
|
126
|
-
return { name, description: schema.description, properties
|
|
121
|
+
return { name, description: schema.description, properties };
|
|
127
122
|
}
|
|
128
123
|
function parseSpecToModules(spec) {
|
|
129
124
|
const modules = /* @__PURE__ */ new Map();
|
|
130
125
|
const allSchemas = /* @__PURE__ */ new Map();
|
|
131
|
-
const allEnums = /* @__PURE__ */ new Map();
|
|
132
126
|
const modulePaths = /* @__PURE__ */ new Map();
|
|
133
127
|
const registerSchema = (schema, baseName) => {
|
|
134
128
|
if (!schema) return "unknown";
|
|
135
129
|
if (schema.type === "array" && schema.items) return `${registerSchema(schema.items, `${baseName}Item`)}[]`;
|
|
136
130
|
if (schema.type === "object" || schema.properties || schema.allOf || !schema.type) {
|
|
137
131
|
const typeName = toPascalCase(baseName.replace(/_v\d+(Request|Response)$/, "$1"));
|
|
138
|
-
if (!allSchemas.has(typeName)) allSchemas.set(typeName, parseSchema(typeName, schema
|
|
132
|
+
if (!allSchemas.has(typeName)) allSchemas.set(typeName, parseSchema(typeName, schema));
|
|
139
133
|
return typeName;
|
|
140
134
|
}
|
|
141
135
|
return schema.type === "integer" ? "number" : schema.type || "unknown";
|
|
@@ -149,7 +143,7 @@ function parseSpecToModules(spec) {
|
|
|
149
143
|
if (!endpoint.operationId) continue;
|
|
150
144
|
const moduleName = getModuleName(endpoint.operationId);
|
|
151
145
|
if (!modules.has(moduleName)) {
|
|
152
|
-
modules.set(moduleName, { moduleName, baseEndpoint: "", actions: {}, schemas: /* @__PURE__ */ new Set()
|
|
146
|
+
modules.set(moduleName, { moduleName, baseEndpoint: "", actions: {}, schemas: /* @__PURE__ */ new Set() });
|
|
153
147
|
modulePaths.set(moduleName, []);
|
|
154
148
|
}
|
|
155
149
|
const currentModule = modules.get(moduleName);
|
|
@@ -165,33 +159,35 @@ function parseSpecToModules(spec) {
|
|
|
165
159
|
const cleanType = t.replace("[]", "");
|
|
166
160
|
if (cleanType && !["unknown", "undefined", "void", "any", "QueryOptions", "Promise"].includes(cleanType)) {
|
|
167
161
|
currentModule.schemas.add(cleanType);
|
|
168
|
-
const schemaDef = allSchemas.get(cleanType);
|
|
169
|
-
if (schemaDef) Object.keys(schemaDef.enums).forEach((propName) => currentModule.enums.add(`${toPascalCase(cleanType)}${toPascalCase(propName)}Enum`));
|
|
170
162
|
}
|
|
171
163
|
});
|
|
172
|
-
|
|
164
|
+
const actionName = getActionName(endpoint.operationId);
|
|
165
|
+
currentModule.actions[actionName] = { name: actionName, method: method.toUpperCase(), path: apiPath, description: endpoint.summary || "", hasQuery: (endpoint.parameters || []).some((p) => p.in === "query"), autoFetch: method.toUpperCase() === "GET" && !apiPath.includes("{"), requiresAuth: !!endpoint.security && endpoint.security.length > 0, inputType, outputType };
|
|
173
166
|
}
|
|
174
167
|
}
|
|
175
168
|
modules.forEach((mod, name) => {
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
const basePath = findCommonPath(modulePaths.get(name));
|
|
170
|
+
mod.baseEndpoint = basePath;
|
|
171
|
+
Object.values(mod.actions).forEach((action) => {
|
|
172
|
+
const relativePath = action.path.replace(basePath, "").replace(/^\//, "");
|
|
173
|
+
action.path = relativePath === "" ? "/" : relativePath;
|
|
174
|
+
});
|
|
178
175
|
});
|
|
179
176
|
debugLog("Final Parsed Modules", Object.fromEntries(modules));
|
|
180
|
-
return { modules, allSchemas
|
|
177
|
+
return { modules, allSchemas };
|
|
181
178
|
}
|
|
182
|
-
async function generateModuleFiles(module2, allSchemas,
|
|
179
|
+
async function generateModuleFiles(module2, allSchemas, outputDir) {
|
|
183
180
|
const moduleOutputPath = import_path.default.join(outputDir, module2.moduleName);
|
|
184
181
|
if (!import_fs.default.existsSync(moduleOutputPath)) import_fs.default.mkdirSync(moduleOutputPath, { recursive: true });
|
|
185
182
|
console.log(import_chalk.default.cyan(`
|
|
186
183
|
Generating module: ${import_chalk.default.bold(module2.moduleName)}`));
|
|
187
|
-
const
|
|
188
|
-
const enumsToImport = [...module2.enums].sort();
|
|
184
|
+
const typesToImport = [...module2.schemas].sort();
|
|
189
185
|
let configContent = `/* eslint-disable */
|
|
190
186
|
// This file is auto-generated.
|
|
191
187
|
|
|
192
188
|
import type { ApiModuleConfig, ActionConfigModule, QueryOptions } from 'api-core-lib';
|
|
193
189
|
`;
|
|
194
|
-
if (
|
|
190
|
+
if (typesToImport.length > 0) configContent += `import type { ${typesToImport.join(", ")} } from './types';
|
|
195
191
|
`;
|
|
196
192
|
const actionsType = Object.values(module2.actions).map((a) => ` ${a.name}: ActionConfigModule<${a.inputType}, ${a.outputType}>;`).join("\n");
|
|
197
193
|
const actionsValue = Object.values(module2.actions).map((a) => {
|
|
@@ -213,32 +209,11 @@ ${actionsValue}
|
|
|
213
209
|
const indexContent = [`// This file is auto-generated.
|
|
214
210
|
|
|
215
211
|
export * from './config';`];
|
|
216
|
-
if (
|
|
217
|
-
if (enumsToImport.length > 0) {
|
|
218
|
-
let enumsContent = `// This file is auto-generated.
|
|
219
|
-
|
|
220
|
-
`;
|
|
221
|
-
for (const enumName of enumsToImport) {
|
|
222
|
-
const enumDef = allEnums.get(enumName);
|
|
223
|
-
if (enumDef) {
|
|
224
|
-
enumsContent += `export const ${enumName} = ${JSON.stringify(enumDef.values)} as const;
|
|
225
|
-
`;
|
|
226
|
-
enumsContent += `export type ${enumName} = typeof ${enumName}[number];
|
|
227
|
-
|
|
228
|
-
`;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, "enums.ts"), enumsContent);
|
|
232
|
-
console.log(import_chalk.default.gray(` \u2713 enums.ts`));
|
|
233
|
-
indexContent.push(`export * from './enums';`);
|
|
234
|
-
}
|
|
212
|
+
if (typesToImport.length > 0) {
|
|
235
213
|
let typesContent = `// This file is auto-generated.
|
|
236
214
|
|
|
237
215
|
`;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
`;
|
|
241
|
-
for (const typeName of schemasToImport) {
|
|
216
|
+
for (const typeName of typesToImport) {
|
|
242
217
|
const parsedSchema = allSchemas.get(typeName);
|
|
243
218
|
if (parsedSchema) {
|
|
244
219
|
if (parsedSchema.description) typesContent += `/**
|
|
@@ -253,10 +228,7 @@ export * from './config';`];
|
|
|
253
228
|
${prop.example ? ` * @example ${JSON.stringify(prop.example)}
|
|
254
229
|
` : ""} */
|
|
255
230
|
`;
|
|
256
|
-
|
|
257
|
-
if (prop.enum) propType = `${toPascalCase(typeName)}${toPascalCase(prop.name)}Enum`;
|
|
258
|
-
else if (prop.items) propType = prop.items.properties ? `${toPascalCase(`${typeName}${toPascalCase(prop.name)}Item`)}[]` : `${prop.items.type}[]`;
|
|
259
|
-
else if (prop.properties) propType = `Record<string, unknown>`;
|
|
231
|
+
const propType = prop.enum ? prop.enum.map((e) => typeof e === "string" ? `'${e}'` : e).join(" | ") : prop.items ? `${toPascalCase(prop.items.name)}[]` : prop.type;
|
|
260
232
|
typesContent += ` ${prop.name}${prop.isRequired ? "" : "?"}: ${propType};
|
|
261
233
|
`;
|
|
262
234
|
}
|
|
@@ -270,14 +242,12 @@ ${prop.example ? ` * @example ${JSON.stringify(prop.example)}
|
|
|
270
242
|
indexContent.push(`export * from './types';`);
|
|
271
243
|
let validationContent = `// This file is auto-generated.
|
|
272
244
|
import { z } from 'zod';
|
|
273
|
-
`;
|
|
274
|
-
if (enumsToImport.length > 0) validationContent += `import { ${enumsToImport.join(", ")} } from './enums';
|
|
275
245
|
|
|
276
246
|
`;
|
|
277
|
-
for (const typeName of
|
|
247
|
+
for (const typeName of typesToImport) {
|
|
278
248
|
const parsedSchema = allSchemas.get(typeName);
|
|
279
249
|
if (parsedSchema) {
|
|
280
|
-
let zodShape = parsedSchema.properties.map((p) => ` ${p.name}: ${_propToZod(p
|
|
250
|
+
let zodShape = parsedSchema.properties.map((p) => ` ${p.name}: ${_propToZod(p)}`).join(",\n");
|
|
281
251
|
validationContent += `export const ${typeName}Schema = z.object({
|
|
282
252
|
${zodShape}
|
|
283
253
|
});
|
|
@@ -289,12 +259,10 @@ ${zodShape}
|
|
|
289
259
|
console.log(import_chalk.default.gray(` \u2713 validation.ts`));
|
|
290
260
|
indexContent.push(`export * from './validation';`);
|
|
291
261
|
let mocksContent = `// This file is auto-generated.
|
|
292
|
-
import type { ${
|
|
293
|
-
`;
|
|
294
|
-
if (enumsToImport.length > 0) mocksContent += `import { ${enumsToImport.map((e) => e.replace(/Enum$/, "")).join(", ")} } from './enums';
|
|
262
|
+
import type { ${typesToImport.join(", ")} } from './types';
|
|
295
263
|
|
|
296
264
|
`;
|
|
297
|
-
for (const typeName of
|
|
265
|
+
for (const typeName of typesToImport) {
|
|
298
266
|
const parsedSchema = allSchemas.get(typeName);
|
|
299
267
|
if (parsedSchema) {
|
|
300
268
|
let mockObject = {};
|
|
@@ -313,66 +281,144 @@ import type { ${schemasToImport.join(", ")} } from './types';
|
|
|
313
281
|
import_fs.default.writeFileSync(import_path.default.join(moduleOutputPath, "index.ts"), indexContent.join("\n"));
|
|
314
282
|
console.log(import_chalk.default.gray(` \u2713 index.ts`));
|
|
315
283
|
}
|
|
316
|
-
function _propToZod(prop
|
|
317
|
-
let
|
|
318
|
-
const
|
|
284
|
+
function _propToZod(prop) {
|
|
285
|
+
let chain;
|
|
286
|
+
const requiredErrorMessage = { required_error: `${prop.name} is required.` };
|
|
319
287
|
switch (prop.type) {
|
|
320
288
|
case "string":
|
|
321
|
-
|
|
322
|
-
if (prop.format === "email")
|
|
323
|
-
if (prop.format === "uuid")
|
|
324
|
-
if (prop.
|
|
289
|
+
chain = `z.string({ ...requiredErrorMessage, invalid_type_error: "Expected a string for ${prop.name}" })`;
|
|
290
|
+
if (prop.format === "email") chain += `.email({ message: "Invalid email address for ${prop.name}" })`;
|
|
291
|
+
if (prop.format === "uuid") chain += `.uuid({ message: "Invalid UUID for ${prop.name}" })`;
|
|
292
|
+
if (prop.format === "url") chain += `.url({ message: "Invalid URL for ${prop.name}" })`;
|
|
293
|
+
if (prop.format === "datetime") chain += `.datetime({ message: "Invalid datetime format for ${prop.name}" })`;
|
|
294
|
+
if (prop.minLength !== void 0) chain += `.min(${prop.minLength}, { message: "${prop.name} must be at least ${prop.minLength} characters long" })`;
|
|
295
|
+
if (prop.maxLength !== void 0) chain += `.max(${prop.maxLength}, { message: "${prop.name} must be at most ${prop.maxLength} characters long" })`;
|
|
296
|
+
if (prop.pattern) chain += `.regex(/${prop.pattern}/, { message: "Invalid format for ${prop.name}" })`;
|
|
297
|
+
if (prop.enum) {
|
|
298
|
+
if (prop.enum.length > 0) {
|
|
299
|
+
chain = `z.enum(${JSON.stringify(prop.enum)})`;
|
|
300
|
+
} else {
|
|
301
|
+
chain = `z.string().refine(() => false, { message: "Enum for ${prop.name} is empty" })`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
325
304
|
break;
|
|
326
305
|
case "integer":
|
|
306
|
+
chain = `z.number({ ...requiredErrorMessage, invalid_type_error: "Expected a number for ${prop.name}" }).int({ message: "${prop.name} must be an integer" })`;
|
|
307
|
+
if (prop.minimum !== void 0) chain += `.min(${prop.minimum}, { message: "${prop.name} must be at least ${prop.minimum}" })`;
|
|
308
|
+
if (prop.maximum !== void 0) chain += `.max(${prop.maximum}, { message: "${prop.name} must be at most ${prop.maximum}" })`;
|
|
309
|
+
break;
|
|
327
310
|
case "number":
|
|
328
|
-
|
|
311
|
+
chain = `z.number({ ...requiredErrorMessage, invalid_type_error: "Expected a number for ${prop.name}" })`;
|
|
312
|
+
if (prop.minimum !== void 0) chain += `.min(${prop.minimum}, { message: "${prop.name} must be at least ${prop.minimum}" })`;
|
|
313
|
+
if (prop.maximum !== void 0) chain += `.max(${prop.maximum}, { message: "${prop.name} must be at most ${prop.maximum}" })`;
|
|
329
314
|
break;
|
|
330
315
|
case "boolean":
|
|
331
|
-
|
|
316
|
+
chain = `z.boolean({ ...requiredErrorMessage, invalid_type_error: "Expected a boolean for ${prop.name}" })`;
|
|
332
317
|
break;
|
|
333
318
|
case "array":
|
|
334
|
-
|
|
319
|
+
const itemSchema = prop.items ? _propToZod(prop.items) : "z.any()";
|
|
320
|
+
chain = `z.array(${itemSchema})`;
|
|
321
|
+
if (prop.minItems !== void 0) chain += `.min(${prop.minItems}, { message: "${prop.name} must contain at least ${prop.minItems} item(s)" })`;
|
|
322
|
+
if (prop.maxItems !== void 0) chain += `.max(${prop.maxItems}, { message: "${prop.name} must contain at most ${prop.maxItems} item(s)" })`;
|
|
335
323
|
break;
|
|
336
324
|
case "object":
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
325
|
+
if (prop.properties && prop.properties.length > 0) {
|
|
326
|
+
const shape = prop.properties.map((p) => ` ${p.name}: ${_propToZod(p)}`).join(",\n");
|
|
327
|
+
chain = `z.object({
|
|
328
|
+
${shape}
|
|
329
|
+
})`;
|
|
330
|
+
} else {
|
|
331
|
+
chain = "z.record(z.unknown())";
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
chain = "z.any()";
|
|
342
336
|
break;
|
|
343
337
|
}
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
|
|
338
|
+
if (prop.description) {
|
|
339
|
+
chain += `.describe(${JSON.stringify(prop.description)})`;
|
|
340
|
+
}
|
|
341
|
+
if (!prop.isRequired) {
|
|
342
|
+
chain += ".optional()";
|
|
343
|
+
}
|
|
344
|
+
if (prop.isNullable) {
|
|
345
|
+
chain += ".nullable()";
|
|
346
|
+
}
|
|
347
|
+
return chain;
|
|
348
|
+
}
|
|
349
|
+
function _generateUUID() {
|
|
350
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
351
|
+
const r = Math.random() * 16 | 0;
|
|
352
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
353
|
+
return v.toString(16);
|
|
354
|
+
});
|
|
347
355
|
}
|
|
356
|
+
function _getRandomInt(min, max) {
|
|
357
|
+
min = Math.ceil(min);
|
|
358
|
+
max = Math.floor(max);
|
|
359
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
360
|
+
}
|
|
361
|
+
var _firstNames = ["Ahmed", "Fatima", "Mohammed", "Zainab", "Ali", "Nour"];
|
|
362
|
+
var _lastNames = ["Al-Masri", "Khan", "Hassan", "Abbas", "Said"];
|
|
348
363
|
function _propToMock(prop) {
|
|
349
|
-
if (prop.example)
|
|
350
|
-
|
|
351
|
-
|
|
364
|
+
if (prop.example !== void 0) {
|
|
365
|
+
return prop.example;
|
|
366
|
+
}
|
|
367
|
+
if (prop.enum && prop.enum.length > 0) {
|
|
368
|
+
return prop.enum[_getRandomInt(0, prop.enum.length - 1)];
|
|
369
|
+
}
|
|
352
370
|
switch (prop.type) {
|
|
353
371
|
case "string":
|
|
354
|
-
if (prop.format === "email") return
|
|
355
|
-
if (prop.format === "uuid") return
|
|
356
|
-
|
|
372
|
+
if (prop.format === "email") return `user${_getRandomInt(1, 1e3)}@example.com`;
|
|
373
|
+
if (prop.format === "uuid") return _generateUUID();
|
|
374
|
+
if (prop.format === "url") return "https://www.example.com";
|
|
375
|
+
if (prop.format === "datetime") return (/* @__PURE__ */ new Date()).toISOString();
|
|
376
|
+
const name = prop.name.toLowerCase();
|
|
377
|
+
if (name.includes("image") || name.includes("avatar") || name.includes("logo") || name.includes("picture")) return `https://via.placeholder.com/${_getRandomInt(150, 400)}`;
|
|
378
|
+
if (name.includes("firstname")) return _firstNames[_getRandomInt(0, _firstNames.length - 1)];
|
|
379
|
+
if (name.includes("lastname")) return _lastNames[_getRandomInt(0, _lastNames.length - 1)];
|
|
380
|
+
if (name.includes("name")) return `${_firstNames[_getRandomInt(0, _firstNames.length - 1)]} ${_lastNames[_getRandomInt(0, _lastNames.length - 1)]}`;
|
|
381
|
+
if (name.includes("city")) return "Riyadh";
|
|
382
|
+
if (name.includes("country")) return "Saudi Arabia";
|
|
383
|
+
if (name.includes("phone")) return `+1-${_getRandomInt(100, 999)}-${_getRandomInt(100, 999)}-${_getRandomInt(1e3, 9999)}`;
|
|
384
|
+
if (name.includes("description") || name.includes("comment")) return "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
385
|
+
const minLen = prop.minLength || 8;
|
|
386
|
+
const maxLen = prop.maxLength || 16;
|
|
387
|
+
return `Mock${toPascalCase(prop.name)}`.padEnd(_getRandomInt(minLen, maxLen), "x");
|
|
357
388
|
case "integer":
|
|
358
389
|
case "number":
|
|
359
|
-
|
|
390
|
+
const min = prop.minimum === void 0 ? 1 : prop.minimum;
|
|
391
|
+
const max = prop.maximum === void 0 ? 1e3 : prop.maximum;
|
|
392
|
+
const randomNum = _getRandomInt(min, max);
|
|
393
|
+
return prop.type === "integer" ? Math.floor(randomNum) : randomNum + Math.random();
|
|
360
394
|
case "boolean":
|
|
361
|
-
return
|
|
395
|
+
return Math.random() > 0.5;
|
|
362
396
|
case "array":
|
|
363
|
-
|
|
397
|
+
const minItems = prop.minItems || 1;
|
|
398
|
+
const maxItems = prop.maxItems || 3;
|
|
399
|
+
const count = _getRandomInt(minItems, maxItems);
|
|
400
|
+
if (!prop.items) return [];
|
|
401
|
+
const items = [];
|
|
402
|
+
for (let i = 0; i < count; i++) {
|
|
403
|
+
items.push(_propToMock(prop.items));
|
|
404
|
+
}
|
|
405
|
+
return items;
|
|
364
406
|
case "object":
|
|
365
407
|
const mock = {};
|
|
366
|
-
if (prop.properties)
|
|
367
|
-
|
|
368
|
-
|
|
408
|
+
if (prop.properties) {
|
|
409
|
+
prop.properties.forEach((p) => {
|
|
410
|
+
if (p.isRequired || Math.random() > 0.3) {
|
|
411
|
+
mock[p.name] = _propToMock(p);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
369
415
|
return mock;
|
|
370
416
|
default:
|
|
371
417
|
return null;
|
|
372
418
|
}
|
|
373
419
|
}
|
|
374
420
|
async function runGenerator(options) {
|
|
375
|
-
console.log(import_chalk.default.cyan.bold("\u{1F680} Starting API Development Platform Generator (
|
|
421
|
+
console.log(import_chalk.default.cyan.bold("\u{1F680} Starting API Development Platform Generator (Phoenix Edition)..."));
|
|
376
422
|
import_dotenv.default.config({ path: options.envPath });
|
|
377
423
|
const specUrl = process.env.OPENAPI_SPEC_URL || "./swagger.json";
|
|
378
424
|
try {
|
|
@@ -380,12 +426,13 @@ async function runGenerator(options) {
|
|
|
380
426
|
\u23F3 Step 1: Dereferencing spec from ${specUrl}...`));
|
|
381
427
|
const spec = await import_swagger_parser.default.dereference(specUrl);
|
|
382
428
|
console.log(import_chalk.default.green("\u2713 Spec fully dereferenced."));
|
|
429
|
+
debugLog("Dereferenced Spec", spec);
|
|
383
430
|
console.log(import_chalk.default.blue("\n\u23F3 Step 2: Parsing spec with intelligent grouping..."));
|
|
384
|
-
const { modules, allSchemas
|
|
431
|
+
const { modules, allSchemas } = parseSpecToModules(spec);
|
|
385
432
|
console.log(import_chalk.default.green(`\u2713 Found and grouped ${modules.size} logical modules.`));
|
|
386
433
|
console.log(import_chalk.default.blue("\n\u23F3 Step 3: Generating all module files..."));
|
|
387
434
|
for (const module2 of modules.values()) {
|
|
388
|
-
await generateModuleFiles(module2, allSchemas,
|
|
435
|
+
await generateModuleFiles(module2, allSchemas, options.output);
|
|
389
436
|
}
|
|
390
437
|
console.log(import_chalk.default.green("\n\u2713 All module files generated successfully."));
|
|
391
438
|
console.log(import_chalk.default.bold.green("\n\u{1F389} API generation complete! Your development platform is ready."));
|