@bagelink/sdk 1.4.18 → 1.4.20
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/index.cjs +21 -6
- package/dist/index.mjs +21 -6
- package/package.json +1 -1
- package/src/openAPITools/openApiTypes.ts +2 -0
- package/src/openAPITools/utils.ts +32 -23
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,21 @@ function resolveReference(ref) {
|
|
|
21
21
|
if (!t) return "any";
|
|
22
22
|
return formatType(t);
|
|
23
23
|
}
|
|
24
|
+
function handleArrayItems(schema) {
|
|
25
|
+
const itemType = schemaToType(schema.items);
|
|
26
|
+
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
27
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
28
|
+
if (itemType.includes("string | string")) {
|
|
29
|
+
res = res.replace("string | string", "string");
|
|
30
|
+
}
|
|
31
|
+
if (itemType.includes("string |")) {
|
|
32
|
+
return res.replace("string |", "(string & {}) |");
|
|
33
|
+
}
|
|
34
|
+
if (itemType.includes("| string")) {
|
|
35
|
+
return res.replace("| string", "| (string & {})");
|
|
36
|
+
}
|
|
37
|
+
return res;
|
|
38
|
+
}
|
|
24
39
|
function schemaToType(schema) {
|
|
25
40
|
if (!schema) return "any";
|
|
26
41
|
if (schema.anyOf) {
|
|
@@ -36,6 +51,9 @@ function schemaToType(schema) {
|
|
|
36
51
|
case "object":
|
|
37
52
|
return "{ [key: string]: any }";
|
|
38
53
|
case "string":
|
|
54
|
+
if (schema.const) {
|
|
55
|
+
return `'${schema.const}'`;
|
|
56
|
+
}
|
|
39
57
|
return "string";
|
|
40
58
|
case "integer":
|
|
41
59
|
return "number";
|
|
@@ -43,11 +61,8 @@ function schemaToType(schema) {
|
|
|
43
61
|
return "number";
|
|
44
62
|
case "boolean":
|
|
45
63
|
return "boolean";
|
|
46
|
-
case "array":
|
|
47
|
-
|
|
48
|
-
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
49
|
-
return needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
50
|
-
}
|
|
64
|
+
case "array":
|
|
65
|
+
return handleArrayItems(schema);
|
|
51
66
|
case "undefined":
|
|
52
67
|
return "undefined";
|
|
53
68
|
case "null":
|
|
@@ -56,7 +71,7 @@ function schemaToType(schema) {
|
|
|
56
71
|
return "any";
|
|
57
72
|
default:
|
|
58
73
|
console.log("Unknown type", schema.type);
|
|
59
|
-
return "
|
|
74
|
+
return "unknown";
|
|
60
75
|
}
|
|
61
76
|
}
|
|
62
77
|
function isOptional(schema) {
|
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,21 @@ function resolveReference(ref) {
|
|
|
15
15
|
if (!t) return "any";
|
|
16
16
|
return formatType(t);
|
|
17
17
|
}
|
|
18
|
+
function handleArrayItems(schema) {
|
|
19
|
+
const itemType = schemaToType(schema.items);
|
|
20
|
+
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
21
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
22
|
+
if (itemType.includes("string | string")) {
|
|
23
|
+
res = res.replace("string | string", "string");
|
|
24
|
+
}
|
|
25
|
+
if (itemType.includes("string |")) {
|
|
26
|
+
return res.replace("string |", "(string & {}) |");
|
|
27
|
+
}
|
|
28
|
+
if (itemType.includes("| string")) {
|
|
29
|
+
return res.replace("| string", "| (string & {})");
|
|
30
|
+
}
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
18
33
|
function schemaToType(schema) {
|
|
19
34
|
if (!schema) return "any";
|
|
20
35
|
if (schema.anyOf) {
|
|
@@ -30,6 +45,9 @@ function schemaToType(schema) {
|
|
|
30
45
|
case "object":
|
|
31
46
|
return "{ [key: string]: any }";
|
|
32
47
|
case "string":
|
|
48
|
+
if (schema.const) {
|
|
49
|
+
return `'${schema.const}'`;
|
|
50
|
+
}
|
|
33
51
|
return "string";
|
|
34
52
|
case "integer":
|
|
35
53
|
return "number";
|
|
@@ -37,11 +55,8 @@ function schemaToType(schema) {
|
|
|
37
55
|
return "number";
|
|
38
56
|
case "boolean":
|
|
39
57
|
return "boolean";
|
|
40
|
-
case "array":
|
|
41
|
-
|
|
42
|
-
const needsParentheses = itemType.includes("|") || itemType.includes("&");
|
|
43
|
-
return needsParentheses ? `(${itemType})[]` : `${itemType}[]`;
|
|
44
|
-
}
|
|
58
|
+
case "array":
|
|
59
|
+
return handleArrayItems(schema);
|
|
45
60
|
case "undefined":
|
|
46
61
|
return "undefined";
|
|
47
62
|
case "null":
|
|
@@ -50,7 +65,7 @@ function schemaToType(schema) {
|
|
|
50
65
|
return "any";
|
|
51
66
|
default:
|
|
52
67
|
console.log("Unknown type", schema.type);
|
|
53
|
-
return "
|
|
68
|
+
return "unknown";
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
function isOptional(schema) {
|
package/package.json
CHANGED
|
@@ -41,8 +41,10 @@ export interface ResponsesObject { [statusCode: string]: ResponseObject }
|
|
|
41
41
|
|
|
42
42
|
export interface SchemaObject {
|
|
43
43
|
type?: string
|
|
44
|
+
const?: string
|
|
44
45
|
format?: string
|
|
45
46
|
properties?: { [property: string]: SchemaObject }
|
|
47
|
+
prefixItems?: SchemaObject[]
|
|
46
48
|
items?: SchemaObject
|
|
47
49
|
$ref?: string
|
|
48
50
|
enum?: string[]
|
|
@@ -29,6 +29,28 @@ function resolveReference(ref: string): string {
|
|
|
29
29
|
return formatType(t)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function handleArrayItems(schema: SchemaObject): string {
|
|
33
|
+
// Handle array items that might be union types
|
|
34
|
+
const itemType = schemaToType(schema.items)
|
|
35
|
+
|
|
36
|
+
// Add parentheses around union types to ensure correct syntax
|
|
37
|
+
const needsParentheses = itemType.includes('|') || itemType.includes('&')
|
|
38
|
+
|
|
39
|
+
let res = needsParentheses ? `(${itemType})[]` : `${itemType}[]`
|
|
40
|
+
|
|
41
|
+
if (itemType.includes('string | string')) {
|
|
42
|
+
res = res.replace('string | string', 'string')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (itemType.includes('string |')) {
|
|
46
|
+
return res.replace('string |', '(string & {}) |')
|
|
47
|
+
}
|
|
48
|
+
if (itemType.includes('| string')) {
|
|
49
|
+
return res.replace('| string', '| (string & {})')
|
|
50
|
+
}
|
|
51
|
+
return res
|
|
52
|
+
}
|
|
53
|
+
|
|
32
54
|
export function schemaToType(schema?: SchemaObject): string {
|
|
33
55
|
if (!schema) return 'any'
|
|
34
56
|
if (schema.anyOf) {
|
|
@@ -47,33 +69,20 @@ export function schemaToType(schema?: SchemaObject): string {
|
|
|
47
69
|
}
|
|
48
70
|
if (schema.$ref) return resolveReference(schema.$ref)
|
|
49
71
|
switch (schema.type) {
|
|
50
|
-
case 'object':
|
|
51
|
-
return '{ [key: string]: any }'
|
|
72
|
+
case 'object': return '{ [key: string]: any }'
|
|
52
73
|
case 'string':
|
|
74
|
+
if (schema.const) { return `'${schema.const}'` }
|
|
53
75
|
return 'string'
|
|
54
|
-
case 'integer':
|
|
55
|
-
|
|
56
|
-
case '
|
|
57
|
-
|
|
58
|
-
case '
|
|
59
|
-
|
|
60
|
-
case '
|
|
61
|
-
// Handle array items that might be union types
|
|
62
|
-
const itemType = schemaToType(schema.items)
|
|
63
|
-
|
|
64
|
-
// Add parentheses around union types to ensure correct syntax
|
|
65
|
-
const needsParentheses = itemType.includes('|') || itemType.includes('&')
|
|
66
|
-
return needsParentheses ? `(${itemType})[]` : `${itemType}[]`
|
|
67
|
-
}
|
|
68
|
-
case 'undefined':
|
|
69
|
-
return 'undefined'
|
|
70
|
-
case 'null':
|
|
71
|
-
return 'null'
|
|
72
|
-
case undefined:
|
|
73
|
-
return 'any'
|
|
76
|
+
case 'integer': return 'number'
|
|
77
|
+
case 'number': return 'number'
|
|
78
|
+
case 'boolean': return 'boolean'
|
|
79
|
+
case 'array': return handleArrayItems(schema)
|
|
80
|
+
case 'undefined': return 'undefined'
|
|
81
|
+
case 'null': return 'null'
|
|
82
|
+
case undefined: return 'any'
|
|
74
83
|
default:
|
|
75
84
|
console.log('Unknown type', schema.type)
|
|
76
|
-
return '
|
|
85
|
+
return 'unknown'
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
|