api-core-lib 12.0.51 → 12.0.52

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 +16 -30
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -75,15 +75,19 @@ function getInputOutputTypes(endpoint) {
75
75
  const responseSchema = successResponse?.content?.["application/json"]?.schema;
76
76
  let outputType = "unknown";
77
77
  if (responseSchema) {
78
- if (responseSchema.$ref) {
78
+ if (responseSchema.title) {
79
+ outputType = responseSchema.title.replace(/\[\]/g, "") + (responseSchema.type === "array" ? "[]" : "");
80
+ } else if (responseSchema.$ref) {
79
81
  outputType = refToTypeName(responseSchema.$ref);
80
- } else if (responseSchema.type === "array" && responseSchema.items?.$ref) {
81
- outputType = `${refToTypeName(responseSchema.items.$ref)}[]`;
82
+ } else if (responseSchema.type === "array" && (responseSchema.items?.title || responseSchema.items?.$ref)) {
83
+ outputType = (responseSchema.items.title || refToTypeName(responseSchema.items.$ref)) + "[]";
82
84
  }
83
85
  }
84
86
  let inputType = "undefined";
85
87
  if (requestBody) {
86
- if (requestBody.$ref) {
88
+ if (requestBody.title) {
89
+ inputType = requestBody.title;
90
+ } else if (requestBody.$ref) {
87
91
  inputType = refToTypeName(requestBody.$ref);
88
92
  } else if (requestBody.type === "object") {
89
93
  inputType = "any";
@@ -93,24 +97,6 @@ function getInputOutputTypes(endpoint) {
93
97
  }
94
98
  return { inputType, outputType };
95
99
  }
96
- function getAllReferencedTypes(initialTypes, allSchemas) {
97
- const finalTypes = new Set(initialTypes);
98
- const queue = [...initialTypes];
99
- while (queue.length > 0) {
100
- const typeName = queue.shift();
101
- if (!typeName || !allSchemas[typeName]) continue;
102
- const schemaString = JSON.stringify(allSchemas[typeName]);
103
- const references = schemaString.match(/"\$ref":\s*"#\/components\/schemas\/([^"]+)"/g) || [];
104
- for (const ref of references) {
105
- const referencedTypeName = ref.split("/").pop()?.replace(/"/g, "") || "";
106
- if (referencedTypeName && !finalTypes.has(referencedTypeName)) {
107
- finalTypes.add(referencedTypeName);
108
- queue.push(referencedTypeName);
109
- }
110
- }
111
- }
112
- return finalTypes;
113
- }
114
100
  function sanitizeTagName(tagName) {
115
101
  return tagName.replace(/[^a-zA-Z0-9]/g, "").replace(/Central|Tenant/g, "");
116
102
  }
@@ -133,16 +119,16 @@ async function generateModuleFiles(moduleName, moduleData, spec, outputDir) {
133
119
  if (!import_fs.default.existsSync(moduleFolderPath)) {
134
120
  import_fs.default.mkdirSync(moduleFolderPath, { recursive: true });
135
121
  }
136
- const allTypeNames = getAllReferencedTypes(moduleData.types, spec.components.schemas);
137
- await generateTypesFile(moduleFolderPath, allTypeNames, spec);
138
- await generateConfigFile(moduleFolderPath, moduleName, moduleData, allTypeNames);
122
+ await generateTypesFile(moduleFolderPath, moduleData.types, spec);
123
+ await generateConfigFile(moduleFolderPath, moduleName, moduleData, moduleData.types);
139
124
  }
140
- async function generateTypesFile(moduleFolderPath, allTypeNames, spec) {
125
+ async function generateTypesFile(moduleFolderPath, typeNames, spec) {
141
126
  let typesContent = `// This file is auto-generated by the API generator. Do not edit.
142
127
 
143
128
  `;
144
- for (const typeName of allTypeNames) {
145
- const schema = spec.components?.schemas?.[typeName];
129
+ const allSchemas = spec.components?.schemas || {};
130
+ for (const typeName of typeNames) {
131
+ const schema = allSchemas[typeName];
146
132
  if (schema) {
147
133
  const tsType = await (0, import_json_schema_to_typescript.compile)(schema, typeName, {
148
134
  bannerComment: "",
@@ -163,8 +149,8 @@ async function generateTypesFile(moduleFolderPath, allTypeNames, spec) {
163
149
  const typesFilePath = import_path.default.join(moduleFolderPath, "types.ts");
164
150
  import_fs.default.writeFileSync(typesFilePath, typesContent);
165
151
  }
166
- async function generateConfigFile(moduleFolderPath, moduleName, moduleData, allTypeNames) {
167
- const typeNamesArray = [...allTypeNames];
152
+ async function generateConfigFile(moduleFolderPath, moduleName, moduleData, typeNames) {
153
+ const typeNamesArray = [...typeNames];
168
154
  const typesImportStatement = typeNamesArray.length > 0 ? `import type { ${typeNamesArray.join(", ")} } from './types';` : ``;
169
155
  const actionsTypeParts = Object.entries(moduleData.actions).map(
170
156
  ([actionName, actionData]) => ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.51",
3
+ "version": "12.0.52",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6
  "exports": {