@bagelink/sdk 0.0.1123 → 0.0.1125
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 +12 -6
- package/dist/index.mjs +12 -6
- package/package.json +1 -1
- package/src/openAPITools/functionGenerator.ts +10 -10
- package/src/openAPITools/utils.ts +18 -17
package/dist/index.cjs
CHANGED
|
@@ -6,10 +6,14 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios$1);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function toCamelCase(str) {
|
|
10
|
+
return str?.replaceAll(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str || "";
|
|
11
|
+
}
|
|
12
|
+
function toPascalCase(str) {
|
|
13
|
+
return str?.replaceAll(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str || "";
|
|
14
|
+
}
|
|
11
15
|
function formatType(typeName) {
|
|
12
|
-
typeName = typeName.replaceAll("-", "").replaceAll(/
|
|
16
|
+
typeName = typeName.replaceAll("-", "").replaceAll(/post|put$/gi, "").replaceAll(/^body_/gi, "");
|
|
13
17
|
return toPascalCase(typeName);
|
|
14
18
|
}
|
|
15
19
|
function resolveReference(ref) {
|
|
@@ -24,8 +28,9 @@ function schemaToType(schema) {
|
|
|
24
28
|
if (_t === "" || _t === "null") _t = "any";
|
|
25
29
|
return _t;
|
|
26
30
|
}
|
|
27
|
-
if (schema.allOf)
|
|
31
|
+
if (schema.allOf) {
|
|
28
32
|
return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
|
|
33
|
+
}
|
|
29
34
|
if (schema.$ref) return resolveReference(schema.$ref);
|
|
30
35
|
switch (schema.type) {
|
|
31
36
|
case "object":
|
|
@@ -58,14 +63,15 @@ function isOptional(schema) {
|
|
|
58
63
|
const includesUndefined = splitType.includes("undefined");
|
|
59
64
|
return includesNull || includesUndefined || schema.default !== undefined;
|
|
60
65
|
}
|
|
61
|
-
|
|
66
|
+
function cleanOptionals(str) {
|
|
67
|
+
return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
|
|
68
|
+
}
|
|
62
69
|
function formatVarType({
|
|
63
70
|
varName,
|
|
64
71
|
schema,
|
|
65
72
|
required = false,
|
|
66
73
|
defaultValue
|
|
67
74
|
}) {
|
|
68
|
-
if (varName === "personId") console.log({ varName, schema, required, defaultValue });
|
|
69
75
|
let type = schemaToType(schema);
|
|
70
76
|
type = cleanOptionals(type);
|
|
71
77
|
let defaultStr = "";
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import axios$1 from 'axios';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function toCamelCase(str) {
|
|
4
|
+
return str?.replaceAll(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str || "";
|
|
5
|
+
}
|
|
6
|
+
function toPascalCase(str) {
|
|
7
|
+
return str?.replaceAll(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toUpperCase()) || str || "";
|
|
8
|
+
}
|
|
5
9
|
function formatType(typeName) {
|
|
6
|
-
typeName = typeName.replaceAll("-", "").replaceAll(/
|
|
10
|
+
typeName = typeName.replaceAll("-", "").replaceAll(/post|put$/gi, "").replaceAll(/^body_/gi, "");
|
|
7
11
|
return toPascalCase(typeName);
|
|
8
12
|
}
|
|
9
13
|
function resolveReference(ref) {
|
|
@@ -18,8 +22,9 @@ function schemaToType(schema) {
|
|
|
18
22
|
if (_t === "" || _t === "null") _t = "any";
|
|
19
23
|
return _t;
|
|
20
24
|
}
|
|
21
|
-
if (schema.allOf)
|
|
25
|
+
if (schema.allOf) {
|
|
22
26
|
return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
|
|
27
|
+
}
|
|
23
28
|
if (schema.$ref) return resolveReference(schema.$ref);
|
|
24
29
|
switch (schema.type) {
|
|
25
30
|
case "object":
|
|
@@ -52,14 +57,15 @@ function isOptional(schema) {
|
|
|
52
57
|
const includesUndefined = splitType.includes("undefined");
|
|
53
58
|
return includesNull || includesUndefined || schema.default !== undefined;
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
function cleanOptionals(str) {
|
|
61
|
+
return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
|
|
62
|
+
}
|
|
56
63
|
function formatVarType({
|
|
57
64
|
varName,
|
|
58
65
|
schema,
|
|
59
66
|
required = false,
|
|
60
67
|
defaultValue
|
|
61
68
|
}) {
|
|
62
|
-
if (varName === "personId") console.log({ varName, schema, required, defaultValue });
|
|
63
69
|
let type = schemaToType(schema);
|
|
64
70
|
type = cleanOptionals(type);
|
|
65
71
|
let defaultStr = "";
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ const primitiveTypes = [
|
|
|
33
33
|
function collectTypeForImportStatement(typeName: string) {
|
|
34
34
|
typeName = typeName.trim().replace('[]', '')
|
|
35
35
|
if (typeName.includes('|')) {
|
|
36
|
-
typeName.split('|').forEach(singleType => {
|
|
36
|
+
typeName.split('|').forEach((singleType) => {
|
|
37
37
|
collectTypeForImportStatement(singleType)
|
|
38
38
|
})
|
|
39
39
|
return
|
|
@@ -153,10 +153,10 @@ function generateRequestBody(requestBody?: RequestBodyObject): {
|
|
|
153
153
|
const bodySchema = jsonContent.schema
|
|
154
154
|
const requestBodyType = schemaToType(bodySchema)
|
|
155
155
|
collectTypeForImportStatement(requestBodyType)
|
|
156
|
-
const requestBodyPayload
|
|
157
|
-
toCamelCase(bodySchema.title)
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
const requestBodyPayload
|
|
157
|
+
= toCamelCase(bodySchema.title)
|
|
158
|
+
|| toCamelCase(requestBodyType)
|
|
159
|
+
|| 'requestBody'
|
|
160
160
|
|
|
161
161
|
const requestBodyParam = formatVarType({
|
|
162
162
|
varName: requestBodyPayload,
|
|
@@ -246,8 +246,8 @@ function generateFunctionForOperation(
|
|
|
246
246
|
if (!operation) return ''
|
|
247
247
|
|
|
248
248
|
// Check if this is a file upload operation by looking at the schema reference
|
|
249
|
-
const isFileUpload
|
|
250
|
-
operation.requestBody?.content[
|
|
249
|
+
const isFileUpload
|
|
250
|
+
= operation.requestBody?.content[
|
|
251
251
|
'multipart/form-data'
|
|
252
252
|
]?.schema?.$ref?.includes('Body_upload_files')
|
|
253
253
|
const parameters = generateFunctionParameters(
|
|
@@ -369,9 +369,9 @@ export function generateFunctions(paths: PathsObject, baseUrl: string) {
|
|
|
369
369
|
if (!objFuncKey) return acc
|
|
370
370
|
const methods = Object.keys(operation)
|
|
371
371
|
if (
|
|
372
|
-
index === array.length - 1
|
|
373
|
-
methods.length === 1
|
|
374
|
-
allPathsClean.filter(p => p === cleanPath(path)).length === 1
|
|
372
|
+
index === array.length - 1
|
|
373
|
+
&& methods.length === 1
|
|
374
|
+
&& allPathsClean.filter(p => p === cleanPath(path)).length === 1
|
|
375
375
|
) {
|
|
376
376
|
const method: string = methods[0]
|
|
377
377
|
const opp: any = { ...operation }[method]
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type { SchemaObject } from './openApiTypes'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
str
|
|
3
|
+
export function toCamelCase(str?: string) {
|
|
4
|
+
return str
|
|
5
5
|
?.replaceAll(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || '')
|
|
6
|
-
.replace(/^./, str => str.toLowerCase())
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
.replace(/^./, str => str.toLowerCase())
|
|
7
|
+
|| str
|
|
8
|
+
|| ''
|
|
9
|
+
}
|
|
10
|
+
export function toPascalCase(str?: string) {
|
|
11
|
+
return str
|
|
11
12
|
?.replaceAll(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '')
|
|
12
|
-
.replace(/^./, str => str.toUpperCase())
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
.replace(/^./, str => str.toUpperCase())
|
|
14
|
+
|| str
|
|
15
|
+
|| ''
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
export function formatType(typeName: string): string {
|
|
17
|
-
// eslint-disable-next-line regexp/no-unused-capturing-group
|
|
18
19
|
typeName = typeName
|
|
19
20
|
.replaceAll('-', '')
|
|
20
|
-
.replaceAll(/
|
|
21
|
+
.replaceAll(/post|put$/gi, '')
|
|
21
22
|
.replaceAll(/^body_/gi, '')
|
|
22
23
|
return toPascalCase(typeName)!
|
|
23
24
|
}
|
|
@@ -38,11 +39,12 @@ export function schemaToType(schema?: SchemaObject): string {
|
|
|
38
39
|
if (_t === '' || _t === 'null') _t = 'any'
|
|
39
40
|
return _t
|
|
40
41
|
}
|
|
41
|
-
if (schema.allOf)
|
|
42
|
+
if (schema.allOf) {
|
|
42
43
|
return schema.allOf
|
|
43
44
|
.map(s => schemaToType(s))
|
|
44
45
|
.filter(p => p !== 'any')
|
|
45
46
|
.join(' & ')
|
|
47
|
+
}
|
|
46
48
|
if (schema.$ref) return resolveReference(schema.$ref)
|
|
47
49
|
switch (schema.type) {
|
|
48
50
|
case 'object':
|
|
@@ -79,11 +81,12 @@ export function isOptional(schema: SchemaObject) {
|
|
|
79
81
|
return includesNull || includesUndefined || schema.default !== undefined
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
export
|
|
83
|
-
str
|
|
84
|
+
export function cleanOptionals(str: string) {
|
|
85
|
+
return str
|
|
84
86
|
.split(' | ')
|
|
85
87
|
.filter(t => t !== 'null' && t !== 'undefined')
|
|
86
88
|
.join(' | ')
|
|
89
|
+
}
|
|
87
90
|
|
|
88
91
|
export function formatVarType({
|
|
89
92
|
varName,
|
|
@@ -96,8 +99,6 @@ export function formatVarType({
|
|
|
96
99
|
required?: boolean
|
|
97
100
|
defaultValue?: unknown
|
|
98
101
|
}) {
|
|
99
|
-
if (varName === 'personId') console.log({ varName, schema, required, defaultValue });
|
|
100
|
-
|
|
101
102
|
let type = schemaToType(schema)
|
|
102
103
|
type = cleanOptionals(type)
|
|
103
104
|
|