@bagelink/sdk 1.6.39 → 1.6.43
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 +6 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +6 -5
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/openAPITools/typeGenerator.ts +9 -7
package/dist/index.cjs
CHANGED
|
@@ -662,26 +662,27 @@ function generateTypes(schemas) {
|
|
|
662
662
|
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
663
663
|
`;
|
|
664
664
|
}
|
|
665
|
-
if ("array"
|
|
665
|
+
if (schema?.type === "array" && schema.items) {
|
|
666
666
|
return `export type ${typeName} = (${schemaToType(schema.items)})[];
|
|
667
667
|
`;
|
|
668
668
|
}
|
|
669
669
|
if (!schema.properties) {
|
|
670
|
-
if (
|
|
670
|
+
if (schema.additionalProperties === true) {
|
|
671
671
|
return `export type ${typeName} = { [key: string]: any };
|
|
672
672
|
`;
|
|
673
673
|
}
|
|
674
674
|
return "";
|
|
675
675
|
}
|
|
676
|
-
if (
|
|
676
|
+
if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
|
|
677
677
|
return `export type ${typeName} = { [key: string]: any };
|
|
678
678
|
`;
|
|
679
679
|
}
|
|
680
680
|
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
681
|
-
const
|
|
681
|
+
const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`;
|
|
682
|
+
const varType = formatVarType({ varName: quotedKey, schema: value });
|
|
682
683
|
return ` ${varType}`;
|
|
683
684
|
}).join(";\n ");
|
|
684
|
-
const indexSignature =
|
|
685
|
+
const indexSignature = schema.additionalProperties === true ? "\n [key: string]: any;" : "";
|
|
685
686
|
return `export type ${typeName} = {
|
|
686
687
|
${properties};${indexSignature}
|
|
687
688
|
};
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -656,26 +656,27 @@ function generateTypes(schemas) {
|
|
|
656
656
|
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
657
657
|
`;
|
|
658
658
|
}
|
|
659
|
-
if ("array"
|
|
659
|
+
if (schema?.type === "array" && schema.items) {
|
|
660
660
|
return `export type ${typeName} = (${schemaToType(schema.items)})[];
|
|
661
661
|
`;
|
|
662
662
|
}
|
|
663
663
|
if (!schema.properties) {
|
|
664
|
-
if (
|
|
664
|
+
if (schema.additionalProperties === true) {
|
|
665
665
|
return `export type ${typeName} = { [key: string]: any };
|
|
666
666
|
`;
|
|
667
667
|
}
|
|
668
668
|
return "";
|
|
669
669
|
}
|
|
670
|
-
if (
|
|
670
|
+
if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
|
|
671
671
|
return `export type ${typeName} = { [key: string]: any };
|
|
672
672
|
`;
|
|
673
673
|
}
|
|
674
674
|
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
675
|
-
const
|
|
675
|
+
const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`;
|
|
676
|
+
const varType = formatVarType({ varName: quotedKey, schema: value });
|
|
676
677
|
return ` ${varType}`;
|
|
677
678
|
}).join(";\n ");
|
|
678
|
-
const indexSignature =
|
|
679
|
+
const indexSignature = schema.additionalProperties === true ? "\n [key: string]: any;" : "";
|
|
679
680
|
return `export type ${typeName} = {
|
|
680
681
|
${properties};${indexSignature}
|
|
681
682
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -124,7 +124,7 @@ class BagelAuth {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
async resetPassword(ctx: { token: string,
|
|
127
|
+
async resetPassword(ctx: { token: string, new_password: string }) {
|
|
128
128
|
return this.bagel.post('auth/reset-password', ctx).catch((err) => {
|
|
129
129
|
throw responses(err.response?.data?.detail)
|
|
130
130
|
})
|
|
@@ -3,25 +3,25 @@ import { isSchemaObject } from './types/utils'
|
|
|
3
3
|
import { formatType, formatVarType, schemaToType } from './utils'
|
|
4
4
|
|
|
5
5
|
export function generateTypes(schemas: ComponentsObject['schemas']): string {
|
|
6
|
-
if (!schemas) {return ''}
|
|
6
|
+
if (!schemas) { return '' }
|
|
7
7
|
const schemaEntries = Object.entries(schemas)
|
|
8
8
|
|
|
9
9
|
return schemaEntries
|
|
10
10
|
.map(([_typeName, schema]) => {
|
|
11
11
|
const typeName = formatType(_typeName)
|
|
12
12
|
|
|
13
|
-
if (!isSchemaObject(schema)) {return ''}
|
|
13
|
+
if (!isSchemaObject(schema)) { return '' }
|
|
14
14
|
|
|
15
15
|
if (schema?.enum) {
|
|
16
16
|
return `export type ${typeName} = ${schema.enum.map((item: string) => `'${item}'`).join(' | ')};\n`
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if ('array'
|
|
19
|
+
if (schema?.type === 'array' && schema.items) {
|
|
20
20
|
return `export type ${typeName} = (${schemaToType(schema.items)})[];\n`
|
|
21
21
|
}
|
|
22
22
|
if (!schema.properties) {
|
|
23
23
|
// Handle case where schema has additionalProperties: true
|
|
24
|
-
if (
|
|
24
|
+
if (schema.additionalProperties === true) {
|
|
25
25
|
return `export type ${typeName} = { [key: string]: any };\n`
|
|
26
26
|
}
|
|
27
27
|
// #region Debug
|
|
@@ -33,20 +33,22 @@ export function generateTypes(schemas: ComponentsObject['schemas']): string {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Handle empty properties with additionalProperties
|
|
36
|
-
if (
|
|
36
|
+
if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
|
|
37
37
|
return `export type ${typeName} = { [key: string]: any };\n`
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const properties = Object.entries(schema.properties)
|
|
41
41
|
.map(([key, value]) => {
|
|
42
|
-
|
|
42
|
+
// Wrap key in quotes if it contains hyphens or isn't a valid identifier
|
|
43
|
+
const quotedKey = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`
|
|
44
|
+
const varType = formatVarType({ varName: quotedKey, schema: value })
|
|
43
45
|
|
|
44
46
|
return `\t\t${varType}`
|
|
45
47
|
})
|
|
46
48
|
.join(';\n ')
|
|
47
49
|
|
|
48
50
|
// Add index signature for additionalProperties if true
|
|
49
|
-
const indexSignature =
|
|
51
|
+
const indexSignature = schema.additionalProperties === true ? '\n\t\t[key: string]: any;' : ''
|
|
50
52
|
|
|
51
53
|
return `export type ${typeName} = {\n ${properties};${indexSignature}\n };\n`
|
|
52
54
|
})
|