api-core-lib 12.0.80 → 12.0.82
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 +34 -8
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -212,20 +212,43 @@ function parseSpecToModules(spec) {
|
|
|
212
212
|
const allSchemas = /* @__PURE__ */ new Map();
|
|
213
213
|
const allEnums = /* @__PURE__ */ new Map();
|
|
214
214
|
const modulePaths = /* @__PURE__ */ new Map();
|
|
215
|
+
const BUILT_IN_TYPES = /* @__PURE__ */ new Set([
|
|
216
|
+
"string",
|
|
217
|
+
"number",
|
|
218
|
+
"boolean",
|
|
219
|
+
"void",
|
|
220
|
+
"undefined",
|
|
221
|
+
"unknown",
|
|
222
|
+
"any",
|
|
223
|
+
"Date",
|
|
224
|
+
"Promise",
|
|
225
|
+
"QueryOptions",
|
|
226
|
+
"Record<string, any>",
|
|
227
|
+
"Record<string, unknown>"
|
|
228
|
+
// <-- Add our fallback type here
|
|
229
|
+
]);
|
|
215
230
|
const registerSchema = (schema, baseName) => {
|
|
216
|
-
if (!schema) return "
|
|
231
|
+
if (!schema) return "Record<string, any>";
|
|
217
232
|
if (schema.type === "array" && schema.items) {
|
|
218
233
|
const itemSchema = schema.items;
|
|
219
234
|
const itemBaseName = `${baseName}Item`;
|
|
220
|
-
if (itemSchema.properties || itemSchema.type === "object")
|
|
221
|
-
|
|
235
|
+
if (itemSchema.properties || itemSchema.type === "object") {
|
|
236
|
+
return `${registerSchema(itemSchema, itemBaseName)}[]`;
|
|
237
|
+
}
|
|
238
|
+
const primitiveType = itemSchema.type === "integer" ? "number" : itemSchema.type || "any";
|
|
239
|
+
return `${primitiveType}[]`;
|
|
222
240
|
}
|
|
223
241
|
if (schema.type === "object" || schema.properties || schema.allOf || !schema.type) {
|
|
242
|
+
if (!schema.properties && !schema.allOf) {
|
|
243
|
+
return "Record<string, any>";
|
|
244
|
+
}
|
|
224
245
|
const typeName = toPascalCase(baseName.replace(/_v\d+(Request|Response)$/, "$1"));
|
|
225
|
-
if (!allSchemas.has(typeName))
|
|
246
|
+
if (!allSchemas.has(typeName)) {
|
|
247
|
+
allSchemas.set(typeName, parseSchema(typeName, schema, allEnums));
|
|
248
|
+
}
|
|
226
249
|
return typeName;
|
|
227
250
|
}
|
|
228
|
-
return schema.type === "integer" ? "number" : schema.type || "
|
|
251
|
+
return schema.type === "integer" ? "number" : schema.type || "any";
|
|
229
252
|
};
|
|
230
253
|
for (const apiPath in spec.paths) {
|
|
231
254
|
const pathItem = spec.paths[apiPath];
|
|
@@ -247,11 +270,14 @@ function parseSpecToModules(spec) {
|
|
|
247
270
|
const outputType = successKey === "204" ? "void" : registerSchema(successRes?.content?.["application/json"]?.schema, `${endpoint.operationId}Response`);
|
|
248
271
|
const reqBody = endpoint.requestBody;
|
|
249
272
|
let inputType = "undefined";
|
|
250
|
-
if (reqBody?.content?.["application/json"]?.schema)
|
|
251
|
-
|
|
273
|
+
if (reqBody?.content?.["application/json"]?.schema) {
|
|
274
|
+
inputType = registerSchema(reqBody.content["application/json"].schema, `${endpoint.operationId}Request`);
|
|
275
|
+
} else if ((endpoint.parameters || []).some((p) => p.in === "query")) {
|
|
276
|
+
inputType = "QueryOptions";
|
|
277
|
+
}
|
|
252
278
|
[inputType, outputType].forEach((t) => {
|
|
253
279
|
const cleanType = t.replace("[]", "");
|
|
254
|
-
if (cleanType && !
|
|
280
|
+
if (cleanType && !BUILT_IN_TYPES.has(cleanType)) {
|
|
255
281
|
currentModule.schemas.add(cleanType);
|
|
256
282
|
const schemaDef = allSchemas.get(cleanType);
|
|
257
283
|
if (schemaDef) Object.keys(schemaDef.enums).forEach((propName) => currentModule.enums.add(`${toPascalCase(cleanType)}${toPascalCase(propName)}Enum`));
|