@bagelink/sdk 0.0.747 → 0.0.751
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/bin/utils.ts +2 -2
- package/dist/index.cjs +20 -20
- package/dist/index.mjs +20 -20
- package/package.json +1 -1
- package/src/openAPITools/functionGenerator.ts +11 -10
- package/src/openAPITools/index.ts +2 -2
package/bin/utils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
|
|
3
|
-
import { join } from 'node:path'
|
|
4
3
|
import { createRequire } from 'node:module'
|
|
5
|
-
import
|
|
4
|
+
import { join } from 'node:path'
|
|
6
5
|
import { ESLint } from 'eslint'
|
|
6
|
+
import * as prettier from 'prettier'
|
|
7
7
|
import { loadEnv } from 'vite'
|
|
8
8
|
|
|
9
9
|
const _require = createRequire(import.meta.url)
|
package/dist/index.cjs
CHANGED
|
@@ -68,26 +68,6 @@ function cleanPath(path) {
|
|
|
68
68
|
return path.split("/").filter((p) => p && !p.match(/\{|\}/)).join("/");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function generateTypes(schemas) {
|
|
72
|
-
return Object.entries(schemas).map(([typeName, schema]) => {
|
|
73
|
-
typeName = formatType(typeName);
|
|
74
|
-
if (schema.enum) {
|
|
75
|
-
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
76
|
-
`;
|
|
77
|
-
}
|
|
78
|
-
if (!schema.properties)
|
|
79
|
-
return "";
|
|
80
|
-
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
81
|
-
const varType = formatVarType(key, value);
|
|
82
|
-
return ` ${varType}`;
|
|
83
|
-
}).join(";\n ");
|
|
84
|
-
return `export type ${typeName} = {
|
|
85
|
-
${properties};
|
|
86
|
-
};
|
|
87
|
-
`;
|
|
88
|
-
}).join("\n");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
71
|
const allTypes = [];
|
|
92
72
|
function collectTypeForImportStatement(typeName) {
|
|
93
73
|
typeName = typeName.trim().replace("[]", "");
|
|
@@ -281,6 +261,26 @@ function generateFunctions(paths, baseUrl) {
|
|
|
281
261
|
return tsString;
|
|
282
262
|
}
|
|
283
263
|
|
|
264
|
+
function generateTypes(schemas) {
|
|
265
|
+
return Object.entries(schemas).map(([typeName, schema]) => {
|
|
266
|
+
typeName = formatType(typeName);
|
|
267
|
+
if (schema.enum) {
|
|
268
|
+
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
269
|
+
`;
|
|
270
|
+
}
|
|
271
|
+
if (!schema.properties)
|
|
272
|
+
return "";
|
|
273
|
+
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
274
|
+
const varType = formatVarType(key, value);
|
|
275
|
+
return ` ${varType}`;
|
|
276
|
+
}).join(";\n ");
|
|
277
|
+
return `export type ${typeName} = {
|
|
278
|
+
${properties};
|
|
279
|
+
};
|
|
280
|
+
`;
|
|
281
|
+
}).join("\n");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
284
|
const index = async (openApiUrl, baseUrl) => {
|
|
285
285
|
try {
|
|
286
286
|
const { data: openApi } = await axios__default.get(openApiUrl);
|
package/dist/index.mjs
CHANGED
|
@@ -62,26 +62,6 @@ function cleanPath(path) {
|
|
|
62
62
|
return path.split("/").filter((p) => p && !p.match(/\{|\}/)).join("/");
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function generateTypes(schemas) {
|
|
66
|
-
return Object.entries(schemas).map(([typeName, schema]) => {
|
|
67
|
-
typeName = formatType(typeName);
|
|
68
|
-
if (schema.enum) {
|
|
69
|
-
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
70
|
-
`;
|
|
71
|
-
}
|
|
72
|
-
if (!schema.properties)
|
|
73
|
-
return "";
|
|
74
|
-
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
75
|
-
const varType = formatVarType(key, value);
|
|
76
|
-
return ` ${varType}`;
|
|
77
|
-
}).join(";\n ");
|
|
78
|
-
return `export type ${typeName} = {
|
|
79
|
-
${properties};
|
|
80
|
-
};
|
|
81
|
-
`;
|
|
82
|
-
}).join("\n");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
65
|
const allTypes = [];
|
|
86
66
|
function collectTypeForImportStatement(typeName) {
|
|
87
67
|
typeName = typeName.trim().replace("[]", "");
|
|
@@ -275,6 +255,26 @@ function generateFunctions(paths, baseUrl) {
|
|
|
275
255
|
return tsString;
|
|
276
256
|
}
|
|
277
257
|
|
|
258
|
+
function generateTypes(schemas) {
|
|
259
|
+
return Object.entries(schemas).map(([typeName, schema]) => {
|
|
260
|
+
typeName = formatType(typeName);
|
|
261
|
+
if (schema.enum) {
|
|
262
|
+
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
if (!schema.properties)
|
|
266
|
+
return "";
|
|
267
|
+
const properties = Object.entries(schema.properties).map(([key, value]) => {
|
|
268
|
+
const varType = formatVarType(key, value);
|
|
269
|
+
return ` ${varType}`;
|
|
270
|
+
}).join(";\n ");
|
|
271
|
+
return `export type ${typeName} = {
|
|
272
|
+
${properties};
|
|
273
|
+
};
|
|
274
|
+
`;
|
|
275
|
+
}).join("\n");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
278
|
const index = async (openApiUrl, baseUrl) => {
|
|
279
279
|
try {
|
|
280
280
|
const { data: openApi } = await axios$1.get(openApiUrl);
|
package/package.json
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
OperationObject,
|
|
3
|
-
ParameterObject,
|
|
4
|
-
PathsObject,
|
|
5
|
-
RequestBodyObject,
|
|
6
|
-
ResponseObject,
|
|
7
|
-
ResponsesObject,
|
|
8
|
-
} from './openApiTypes'
|
|
9
|
-
|
|
10
1
|
import {
|
|
11
2
|
cleanPath,
|
|
12
3
|
formatType,
|
|
@@ -16,6 +7,15 @@ import {
|
|
|
16
7
|
toPascalCase,
|
|
17
8
|
} from './utils'
|
|
18
9
|
|
|
10
|
+
import type {
|
|
11
|
+
OperationObject,
|
|
12
|
+
ParameterObject,
|
|
13
|
+
PathsObject,
|
|
14
|
+
RequestBodyObject,
|
|
15
|
+
ResponseObject,
|
|
16
|
+
ResponsesObject,
|
|
17
|
+
} from './openApiTypes'
|
|
18
|
+
|
|
19
19
|
const allTypes: string[] = []
|
|
20
20
|
|
|
21
21
|
function collectTypeForImportStatement(typeName: string) {
|
|
@@ -124,7 +124,8 @@ function combineAllParams(parameters: { params?: string }, requestBodyParam: str
|
|
|
124
124
|
if (requestBodyParam) allParamsArray.push(requestBodyParam.trim())
|
|
125
125
|
|
|
126
126
|
allParamsArray = allParamsArray
|
|
127
|
-
.filter(p => p)
|
|
127
|
+
.filter(p => p)
|
|
128
|
+
.sort((a, b) => (a.includes('?') ? 1 : -1) - (b.includes('?') ? 1 : -1))
|
|
128
129
|
|
|
129
130
|
return allParamsArray.join(', ')
|
|
130
131
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import type { OpenAPIDocument } from './openApiTypes'
|
|
3
|
-
import { generateTypes } from './typeGenerator'
|
|
4
2
|
import { generateFunctions } from './functionGenerator'
|
|
3
|
+
import { generateTypes } from './typeGenerator'
|
|
4
|
+
import type { OpenAPIDocument } from './openApiTypes'
|
|
5
5
|
|
|
6
6
|
interface OpenAPIResponse {
|
|
7
7
|
types: string
|