api-core-lib 12.0.53 → 12.0.54

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +18 -24
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -69,28 +69,22 @@ function parseSpecToModules(spec) {
69
69
  }
70
70
  return modules;
71
71
  }
72
- function extractTypeNameFromSchema(schema) {
73
- if (!schema) return "unknown";
74
- if (schema.title && schema.type === "object") {
75
- return schema.title;
76
- }
77
- if (schema.type === "array" && schema.items) {
78
- const itemTypeName = extractTypeNameFromSchema(schema.items);
79
- return itemTypeName !== "unknown" ? `${itemTypeName}[]` : "unknown";
80
- }
81
- if (schema.$ref) {
82
- return refToTypeName(schema.$ref);
83
- }
84
- return "unknown";
85
- }
86
72
  function getInputOutputTypes(endpoint) {
87
73
  const requestBodySchema = endpoint.requestBody?.content?.["application/json"]?.schema;
88
74
  const successResponseSchema = endpoint.responses?.["200"]?.content?.["application/json"]?.schema || endpoint.responses?.["201"]?.content?.["application/json"]?.schema;
89
- let outputType = extractTypeNameFromSchema(successResponseSchema);
75
+ let outputType = "unknown";
76
+ if (successResponseSchema) {
77
+ if (successResponseSchema.$ref) {
78
+ outputType = refToTypeName(successResponseSchema.$ref);
79
+ } else if (successResponseSchema.type === "array" && successResponseSchema.items?.$ref) {
80
+ outputType = `${refToTypeName(successResponseSchema.items.$ref)}[]`;
81
+ }
82
+ }
90
83
  let inputType = "undefined";
91
84
  if (requestBodySchema) {
92
- inputType = extractTypeNameFromSchema(requestBodySchema);
93
- if (inputType === "unknown" && requestBodySchema.type === "object") {
85
+ if (requestBodySchema.$ref) {
86
+ inputType = refToTypeName(requestBodySchema.$ref);
87
+ } else if (requestBodySchema.type === "object") {
94
88
  inputType = "any";
95
89
  }
96
90
  } else if ((endpoint.parameters || []).some((p) => p.in === "query")) {
@@ -129,7 +123,7 @@ Generating module: ${moduleName}`));
129
123
  async function generateTypesFile(moduleFolderPath, moduleName, typeNames, spec) {
130
124
  const typesCount = typeNames.size;
131
125
  if (typesCount === 0) {
132
- console.log(import_chalk.default.yellow(` - Warning: No types found for this module. types.ts will be empty.`));
126
+ console.log(import_chalk.default.yellow(` - No types found for this module. types.ts will be empty.`));
133
127
  } else {
134
128
  console.log(import_chalk.default.gray(` - Found ${typesCount} types to generate for types.ts...`));
135
129
  }
@@ -160,7 +154,7 @@ async function generateTypesFile(moduleFolderPath, moduleName, typeNames, spec)
160
154
  console.error(import_chalk.default.red(` ${compileError.message}`));
161
155
  }
162
156
  } else {
163
- console.log(import_chalk.default.yellow(` - Warning: Schema not found for type "${typeName}", skipping.`));
157
+ console.log(import_chalk.default.yellow(` - Warning: Schema for type "${typeName}" not found in dereferenced spec, skipping.`));
164
158
  }
165
159
  }
166
160
  const typesFilePath = import_path.default.join(moduleFolderPath, "types.ts");
@@ -211,16 +205,16 @@ async function runGenerator(options) {
211
205
  try {
212
206
  console.log("\n" + import_chalk2.default.blue(`Step 2: Fetching OpenAPI spec from ${specUrl}...`));
213
207
  const response = await import_axios.default.get(specUrl, { timeout: 15e3 });
214
- let spec = response.data;
215
- if (!spec.openapi || !spec.paths) {
208
+ const originalSpec = response.data;
209
+ if (!originalSpec.openapi || !originalSpec.paths) {
216
210
  throw new Error('Invalid OpenAPI specification file. "openapi" or "paths" property is missing.');
217
211
  }
218
212
  console.log(import_chalk2.default.green("\u2713 OpenAPI spec fetched successfully."));
219
213
  console.log(import_chalk2.default.blue("Step 2.5: Dereferencing all $refs in the spec..."));
220
- spec = await import_json_schema_ref_parser.default.dereference(spec);
214
+ const dereferencedSpec = await import_json_schema_ref_parser.default.dereference(originalSpec);
221
215
  console.log(import_chalk2.default.green("\u2713 Spec dereferenced successfully."));
222
216
  console.log("\n" + import_chalk2.default.blue("Step 3: Parsing spec and generating API modules..."));
223
- const modules = parseSpecToModules(spec);
217
+ const modules = parseSpecToModules(originalSpec);
224
218
  const modulesCount = Object.keys(modules).length;
225
219
  console.log(import_chalk2.default.gray(`Found ${modulesCount} modules to generate...`));
226
220
  if (modulesCount === 0) {
@@ -229,7 +223,7 @@ async function runGenerator(options) {
229
223
  const modulesOutputPath = import_path2.default.join(options.output, "modules");
230
224
  for (const moduleName in modules) {
231
225
  const moduleData = modules[moduleName];
232
- await generateModuleFiles(moduleName, moduleData, spec, modulesOutputPath);
226
+ await generateModuleFiles(moduleName, moduleData, dereferencedSpec, modulesOutputPath);
233
227
  }
234
228
  if (modulesCount > 0) {
235
229
  console.log(import_chalk2.default.green("\u2713 All custom modules generated."));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.53",
3
+ "version": "12.0.54",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {