react-query-lightbase-codegen 3.1.2 → 3.1.4

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/utils.js CHANGED
@@ -201,23 +201,27 @@ function getTypeFromSchema(schema) {
201
201
  // Handle enums as union types
202
202
  if ("enum" in schema && schema.enum) {
203
203
  // Filter out null/undefined enum values (some specs include null for nullable enums)
204
- const hasNull = schema.enum.some((e) => e === null);
204
+ const enumValues = Object.values(schema.enum);
205
+ const hasNull = enumValues.some((e) => e === null);
205
206
  const nullSuffix = hasNull ? " | null" : "";
206
- if (Object.values(schema.enum)?.length > 0) {
207
- const values = Object.values(schema.enum)
208
- .filter((e) => e != null)
209
- .map((e) => (typeof e === "string" ? `'${e}'` : e));
210
- if (values.length === 0)
211
- return `unknown${nullable}`;
212
- return values.join(" | ") + nullSuffix + nullable;
213
- }
214
- const values = schema.enum.filter((e) => e != null).map((e) => (typeof e === "string" ? `'${e}'` : e));
207
+ const values = enumValues.filter((e) => e != null).map((e) => (typeof e === "string" ? `'${e}'` : e));
215
208
  if (values.length === 0)
216
209
  return `unknown${nullable}`;
217
210
  return values.join(" | ") + nullSuffix + nullable;
218
211
  }
219
212
  // Handle types based on the "type" property
220
213
  if ("type" in schema) {
214
+ // OpenAPI 3.1 supports type as an array, e.g. ["string", "null"]
215
+ if (Array.isArray(schema.type)) {
216
+ const types = schema.type.filter((t) => t !== "null");
217
+ const hasNull = schema.type.includes("null");
218
+ const nullSuffix = hasNull ? " | null" : "";
219
+ if (types.length === 0)
220
+ return `unknown${nullable}`;
221
+ // Resolve each type individually by recursing with a single-type schema
222
+ const resolved = types.map((t) => getTypeFromSchema({ ...schema, type: t }));
223
+ return resolved.filter(Boolean).join(" | ") + nullSuffix + nullable;
224
+ }
221
225
  switch (schema.type) {
222
226
  case "string":
223
227
  // Special case for binary format strings
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-lightbase-codegen",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "license": "MIT",
5
5
  "description": "Generate Axios API clients and React Query options from OpenAPI specifications",
6
6
  "exports": "./dist/index.js",
package/src/utils.ts CHANGED
@@ -229,22 +229,27 @@ export function getTypeFromSchema(
229
229
  // Handle enums as union types
230
230
  if ("enum" in schema && schema.enum) {
231
231
  // Filter out null/undefined enum values (some specs include null for nullable enums)
232
- const hasNull = schema.enum.some((e) => e === null);
232
+ const enumValues = Object.values(schema.enum);
233
+ const hasNull = enumValues.some((e) => e === null);
233
234
  const nullSuffix = hasNull ? " | null" : "";
234
- if (Object.values(schema.enum)?.length > 0) {
235
- const values = Object.values(schema.enum)
236
- .filter((e) => e != null)
237
- .map((e) => (typeof e === "string" ? `'${e}'` : e));
238
- if (values.length === 0) return `unknown${nullable}`;
239
- return values.join(" | ") + nullSuffix + nullable;
240
- }
241
- const values = schema.enum.filter((e) => e != null).map((e) => (typeof e === "string" ? `'${e}'` : e));
235
+ const values = enumValues.filter((e) => e != null).map((e) => (typeof e === "string" ? `'${e}'` : e));
242
236
  if (values.length === 0) return `unknown${nullable}`;
243
237
  return values.join(" | ") + nullSuffix + nullable;
244
238
  }
245
239
 
246
240
  // Handle types based on the "type" property
247
241
  if ("type" in schema) {
242
+ // OpenAPI 3.1 supports type as an array, e.g. ["string", "null"]
243
+ if (Array.isArray(schema.type)) {
244
+ const types = (schema.type as string[]).filter((t) => t !== "null");
245
+ const hasNull = (schema.type as string[]).includes("null");
246
+ const nullSuffix = hasNull ? " | null" : "";
247
+ if (types.length === 0) return `unknown${nullable}`;
248
+ // Resolve each type individually by recursing with a single-type schema
249
+ const resolved = types.map((t) => getTypeFromSchema({ ...schema, type: t } as OpenAPIV3.SchemaObject));
250
+ return resolved.filter(Boolean).join(" | ") + nullSuffix + nullable;
251
+ }
252
+
248
253
  switch (schema.type) {
249
254
  case "string":
250
255
  // Special case for binary format strings