@bagelink/sdk 0.0.464 → 0.0.471
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 +44 -40
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +44 -40
- package/package.json +2 -2
- package/src/index.ts +130 -131
- package/src/openAPITools/functionGenerator.ts +133 -123
- package/src/openAPITools/index.ts +17 -17
- package/src/openAPITools/openApiTypes.ts +38 -38
- package/src/openAPITools/typeGenerator.ts +16 -14
- package/src/openAPITools/utils.ts +46 -46
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import type { SchemaObject } from './openApiTypes'
|
|
1
|
+
import type { SchemaObject } from './openApiTypes'
|
|
2
2
|
|
|
3
|
-
export const toCamelCase = (str?: string) => str?.replace(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./,
|
|
4
|
-
export const toPascalCase = (str?: string) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./,
|
|
3
|
+
export const toCamelCase = (str?: string) => str?.replace(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, str => str.toLowerCase()) || str
|
|
4
|
+
export const toPascalCase = (str?: string) => str?.replace(/[-_\s]+(.)?/g, (_, c) => c?.toUpperCase() || '').replace(/^./, str => str.toUpperCase()) || str
|
|
5
5
|
|
|
6
6
|
export function formatType(typeName: string): string {
|
|
7
|
-
typeName = typeName.replace(/-/g, '').replace(/(post|put)$/gi, '').replace(/^body_/gi, '')
|
|
8
|
-
return toPascalCase(typeName)
|
|
7
|
+
typeName = typeName.replace(/-/g, '').replace(/(post|put)$/gi, '').replace(/^body_/gi, '')
|
|
8
|
+
return toPascalCase(typeName)!
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const t = ref.split('/').pop()
|
|
13
|
-
if (!t) return 'any'
|
|
14
|
-
return formatType(t)
|
|
15
|
-
}
|
|
11
|
+
function resolveReference(ref: string): string {
|
|
12
|
+
const t = ref.split('/').pop()
|
|
13
|
+
if (!t) return 'any'
|
|
14
|
+
return formatType(t)
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
export
|
|
18
|
-
if (!schema) return 'any'
|
|
19
|
-
if (schema.anyOf) return schema.anyOf.map(
|
|
20
|
-
if (schema.allOf) return schema.allOf.map(
|
|
21
|
-
if (schema.$ref) return resolveReference(schema.$ref)
|
|
17
|
+
export function schemaToType(schema?: SchemaObject): string {
|
|
18
|
+
if (!schema) return 'any'
|
|
19
|
+
if (schema.anyOf) return schema.anyOf.map(s => schemaToType(s)).filter(p => p !== 'any').join(' | ')
|
|
20
|
+
if (schema.allOf) return schema.allOf.map(s => schemaToType(s)).filter(p => p !== 'any').join(' & ')
|
|
21
|
+
if (schema.$ref) return resolveReference(schema.$ref)
|
|
22
22
|
switch (schema.type) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
case 'object':
|
|
24
|
+
return 'Record<string, any>'
|
|
25
|
+
case 'string':
|
|
26
|
+
return 'string'
|
|
27
|
+
case 'integer':
|
|
28
|
+
return 'number'
|
|
29
|
+
case 'number':
|
|
30
|
+
return 'number'
|
|
31
|
+
case 'boolean':
|
|
32
|
+
return 'boolean'
|
|
33
|
+
case 'array':
|
|
34
|
+
return `${schemaToType(schema.items)}[]`
|
|
35
|
+
case 'null':
|
|
36
|
+
return 'null'
|
|
37
|
+
default:
|
|
38
|
+
return 'any'
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
export
|
|
42
|
+
export function isOptional(schema: SchemaObject) {
|
|
43
43
|
/// / !schema?.required?.includes(schema.title || '')
|
|
44
|
-
const type = schemaToType(schema)
|
|
45
|
-
return type
|
|
46
|
-
}
|
|
44
|
+
const type = schemaToType(schema)
|
|
45
|
+
return type.split(/\s+\|\s+/).includes('null') || schema.default !== undefined
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
export const cleanNulls = (str: string) => str.split(' | ').filter(
|
|
48
|
+
export const cleanNulls = (str: string) => str.split(' | ').filter(t => t !== 'null').join(' | ')
|
|
49
49
|
|
|
50
50
|
export function formatVarType(varName: string, schema: any, required = false, defaultValue: any = null) {
|
|
51
|
-
let type = schemaToType(schema)
|
|
52
|
-
type = cleanNulls(type)
|
|
51
|
+
let type = schemaToType(schema)
|
|
52
|
+
type = cleanNulls(type)
|
|
53
53
|
|
|
54
|
-
let defaultStr = defaultValue ? ` = ${defaultValue}` : ''
|
|
54
|
+
let defaultStr = defaultValue ? ` = ${defaultValue}` : ''
|
|
55
55
|
|
|
56
|
-
if (defaultStr && type === 'string') defaultStr = ` = '${defaultValue}'
|
|
57
|
-
else if (defaultValue && (typeof defaultValue === 'object' || defaultValue === '{}')) defaultStr = ' = {}'
|
|
56
|
+
if (defaultStr && type === 'string') defaultStr = ` = '${defaultValue}'`
|
|
57
|
+
else if (defaultValue && (typeof defaultValue === 'object' || defaultValue === '{}')) defaultStr = ' = {}'
|
|
58
58
|
|
|
59
|
-
let optionalStr = required || isOptional(schema) ? '?' : ''
|
|
60
|
-
if (defaultStr) optionalStr = ''
|
|
59
|
+
let optionalStr = required || isOptional(schema) ? '?' : ''
|
|
60
|
+
if (defaultStr) optionalStr = ''
|
|
61
61
|
|
|
62
|
-
return `${varName}${optionalStr}: ${type}${defaultStr}
|
|
62
|
+
return `${varName}${optionalStr}: ${type}${defaultStr}`
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export function cleanPath(path: string) {
|
|
66
|
-
return path.split('/').filter(
|
|
66
|
+
return path.split('/').filter(p => p && !p.match(/\{|\}/)).join('/')
|
|
67
67
|
}
|