@bagelink/sdk 1.4.26 → 1.4.28
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 +49 -16
- package/dist/index.d.cts +353 -2
- package/dist/index.d.mts +353 -2
- package/dist/index.d.ts +353 -2
- package/dist/index.mjs +46 -17
- package/package.json +5 -20
- package/src/index.ts +3 -5
- package/src/openAPITools/functionGenerator.ts +45 -33
- package/src/openAPITools/index.ts +4 -2
- package/src/openAPITools/typeGenerator.ts +13 -12
- package/src/openAPITools/types/index.ts +360 -0
- package/src/openAPITools/types/utils.ts +36 -0
- package/src/openAPITools/utils.ts +16 -7
- package/src/openAPITools/openApiTypes.ts +0 -96
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,355 @@
|
|
|
1
|
+
declare function getPath(pathsObject: PathsObject | undefined, path: string): PathItemObject | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* A type guard to check if the given value is a `ReferenceObject`.
|
|
4
|
+
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types
|
|
5
|
+
*
|
|
6
|
+
* @param obj The value to check.
|
|
7
|
+
*/
|
|
8
|
+
declare function isReferenceObject(obj: any): obj is ReferenceObject;
|
|
9
|
+
/**
|
|
10
|
+
* A type guard to check if the given object is a `SchemaObject`.
|
|
11
|
+
* Useful to distinguish from `ReferenceObject` values that can be used
|
|
12
|
+
* in most places where `SchemaObject` is allowed.
|
|
13
|
+
*
|
|
14
|
+
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types
|
|
15
|
+
*
|
|
16
|
+
* @param schema The value to check.
|
|
17
|
+
*/
|
|
18
|
+
declare function isSchemaObject(schema: SchemaObject | ReferenceObject): schema is SchemaObject;
|
|
19
|
+
declare function dereference<T>(property: ReferenceObject | T): Exclude<T, ReferenceObject>;
|
|
20
|
+
|
|
21
|
+
interface ServerObject {
|
|
22
|
+
url: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
variables?: {
|
|
25
|
+
[v: string]: ServerVariableObject;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface ServerVariableObject {
|
|
29
|
+
enum?: string[] | boolean[] | number[];
|
|
30
|
+
default: string | boolean | number;
|
|
31
|
+
description?: string;
|
|
32
|
+
}
|
|
33
|
+
interface OpenAPIObject {
|
|
34
|
+
openapi: string;
|
|
35
|
+
info: InfoObject;
|
|
36
|
+
servers?: ServerObject[];
|
|
37
|
+
paths?: PathsObject;
|
|
38
|
+
components?: ComponentsObject;
|
|
39
|
+
security?: SecurityRequirementObject[];
|
|
40
|
+
tags?: TagObject[];
|
|
41
|
+
externalDocs?: ExternalDocumentationObject;
|
|
42
|
+
/** Webhooks added in v. 3.1.0 */
|
|
43
|
+
webhooks?: PathsObject;
|
|
44
|
+
}
|
|
45
|
+
interface InfoObject {
|
|
46
|
+
title: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
termsOfService?: string;
|
|
49
|
+
contact?: ContactObject;
|
|
50
|
+
license?: LicenseObject;
|
|
51
|
+
version: string;
|
|
52
|
+
}
|
|
53
|
+
interface ContactObject {
|
|
54
|
+
name?: string;
|
|
55
|
+
url?: string;
|
|
56
|
+
email?: string;
|
|
57
|
+
}
|
|
58
|
+
interface LicenseObject {
|
|
59
|
+
name: string;
|
|
60
|
+
identifier?: string;
|
|
61
|
+
url?: string;
|
|
62
|
+
}
|
|
63
|
+
interface ComponentsObject {
|
|
64
|
+
schemas?: {
|
|
65
|
+
[schema: string]: SchemaObject | ReferenceObject;
|
|
66
|
+
};
|
|
67
|
+
responses?: {
|
|
68
|
+
[response: string]: ResponseObject | ReferenceObject;
|
|
69
|
+
};
|
|
70
|
+
parameters?: {
|
|
71
|
+
[parameter: string]: ParameterObject | ReferenceObject;
|
|
72
|
+
};
|
|
73
|
+
examples?: {
|
|
74
|
+
[example: string]: ExampleObject | ReferenceObject;
|
|
75
|
+
};
|
|
76
|
+
requestBodies?: {
|
|
77
|
+
[request: string]: RequestBodyObject | ReferenceObject;
|
|
78
|
+
};
|
|
79
|
+
headers?: {
|
|
80
|
+
[header: string]: HeaderObject | ReferenceObject;
|
|
81
|
+
};
|
|
82
|
+
securitySchemes?: {
|
|
83
|
+
[securityScheme: string]: SecuritySchemeObject | ReferenceObject;
|
|
84
|
+
};
|
|
85
|
+
links?: {
|
|
86
|
+
[link: string]: LinkObject | ReferenceObject;
|
|
87
|
+
};
|
|
88
|
+
callbacks?: {
|
|
89
|
+
[callback: string]: CallbackObject | ReferenceObject;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Rename it to Paths Object to be consistent with the spec
|
|
94
|
+
* See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject
|
|
95
|
+
*/
|
|
96
|
+
interface PathsObject {
|
|
97
|
+
[path: string]: PathItemObject;
|
|
98
|
+
}
|
|
99
|
+
interface PathItemObject {
|
|
100
|
+
$ref?: string;
|
|
101
|
+
summary?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
get?: OperationObject;
|
|
104
|
+
put?: OperationObject;
|
|
105
|
+
post?: OperationObject;
|
|
106
|
+
delete?: OperationObject;
|
|
107
|
+
options?: OperationObject;
|
|
108
|
+
head?: OperationObject;
|
|
109
|
+
patch?: OperationObject;
|
|
110
|
+
trace?: OperationObject;
|
|
111
|
+
servers?: ServerObject[];
|
|
112
|
+
parameters?: (ParameterObject | ReferenceObject)[];
|
|
113
|
+
}
|
|
114
|
+
interface OperationObject {
|
|
115
|
+
tags?: string[];
|
|
116
|
+
summary?: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
externalDocs?: ExternalDocumentationObject;
|
|
119
|
+
operationId?: string;
|
|
120
|
+
parameters?: (ParameterObject | ReferenceObject)[];
|
|
121
|
+
requestBody?: RequestBodyObject | ReferenceObject;
|
|
122
|
+
responses?: ResponsesObject;
|
|
123
|
+
callbacks?: CallbacksObject;
|
|
124
|
+
deprecated?: boolean;
|
|
125
|
+
security?: SecurityRequirementObject[];
|
|
126
|
+
servers?: ServerObject[];
|
|
127
|
+
}
|
|
128
|
+
interface ExternalDocumentationObject {
|
|
129
|
+
description?: string;
|
|
130
|
+
url: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The location of a parameter.
|
|
134
|
+
* Possible values are "query", "header", "path" or "cookie".
|
|
135
|
+
* Specification:
|
|
136
|
+
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-locations
|
|
137
|
+
*/
|
|
138
|
+
type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
|
|
139
|
+
/**
|
|
140
|
+
* The style of a parameter.
|
|
141
|
+
* Describes how the parameter value will be serialized.
|
|
142
|
+
* (serialization is not implemented yet)
|
|
143
|
+
* Specification:
|
|
144
|
+
* https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
|
|
145
|
+
*/
|
|
146
|
+
type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
|
|
147
|
+
interface BaseParameterObject {
|
|
148
|
+
description?: string;
|
|
149
|
+
required?: boolean;
|
|
150
|
+
deprecated?: boolean;
|
|
151
|
+
allowEmptyValue?: boolean;
|
|
152
|
+
style?: ParameterStyle;
|
|
153
|
+
explode?: boolean;
|
|
154
|
+
allowReserved?: boolean;
|
|
155
|
+
schema?: SchemaObject | ReferenceObject;
|
|
156
|
+
examples?: {
|
|
157
|
+
[param: string]: ExampleObject | ReferenceObject;
|
|
158
|
+
};
|
|
159
|
+
example?: any;
|
|
160
|
+
content?: ContentObject;
|
|
161
|
+
}
|
|
162
|
+
interface ParameterObject extends BaseParameterObject {
|
|
163
|
+
name: string;
|
|
164
|
+
in: ParameterLocation;
|
|
165
|
+
}
|
|
166
|
+
interface RequestBodyObject {
|
|
167
|
+
description?: string;
|
|
168
|
+
content: ContentObject;
|
|
169
|
+
required?: boolean;
|
|
170
|
+
}
|
|
171
|
+
interface ContentObject {
|
|
172
|
+
[mediatype: string]: MediaTypeObject;
|
|
173
|
+
}
|
|
174
|
+
interface MediaTypeObject {
|
|
175
|
+
schema?: SchemaObject | ReferenceObject;
|
|
176
|
+
examples?: ExamplesObject;
|
|
177
|
+
example?: any;
|
|
178
|
+
encoding?: EncodingObject;
|
|
179
|
+
}
|
|
180
|
+
interface EncodingObject {
|
|
181
|
+
[property: string]: EncodingPropertyObject;
|
|
182
|
+
}
|
|
183
|
+
interface EncodingPropertyObject {
|
|
184
|
+
contentType?: string;
|
|
185
|
+
headers?: {
|
|
186
|
+
[key: string]: HeaderObject | ReferenceObject;
|
|
187
|
+
};
|
|
188
|
+
style?: string;
|
|
189
|
+
explode?: boolean;
|
|
190
|
+
allowReserved?: boolean;
|
|
191
|
+
}
|
|
192
|
+
interface ResponsesObject {
|
|
193
|
+
[statuscode: string]: ResponseObject | ReferenceObject;
|
|
194
|
+
}
|
|
195
|
+
interface ResponseObject {
|
|
196
|
+
description: string;
|
|
197
|
+
headers?: HeadersObject;
|
|
198
|
+
content?: ContentObject;
|
|
199
|
+
links?: LinksObject;
|
|
200
|
+
}
|
|
201
|
+
interface CallbacksObject {
|
|
202
|
+
[name: string]: CallbackObject | ReferenceObject;
|
|
203
|
+
}
|
|
204
|
+
interface CallbackObject {
|
|
205
|
+
[name: string]: PathItemObject;
|
|
206
|
+
}
|
|
207
|
+
interface HeadersObject {
|
|
208
|
+
[name: string]: HeaderObject | ReferenceObject;
|
|
209
|
+
}
|
|
210
|
+
interface ExampleObject {
|
|
211
|
+
summary?: string;
|
|
212
|
+
description?: string;
|
|
213
|
+
value?: any;
|
|
214
|
+
externalValue?: string;
|
|
215
|
+
}
|
|
216
|
+
interface LinksObject {
|
|
217
|
+
[name: string]: LinkObject | ReferenceObject;
|
|
218
|
+
}
|
|
219
|
+
interface LinkObject {
|
|
220
|
+
operationRef?: string;
|
|
221
|
+
operationId?: string;
|
|
222
|
+
parameters?: LinkParametersObject;
|
|
223
|
+
requestBody?: any | string;
|
|
224
|
+
description?: string;
|
|
225
|
+
server?: ServerObject;
|
|
226
|
+
}
|
|
227
|
+
interface LinkParametersObject {
|
|
228
|
+
[name: string]: any | string;
|
|
229
|
+
}
|
|
230
|
+
interface HeaderObject extends BaseParameterObject {
|
|
231
|
+
$ref?: string;
|
|
232
|
+
}
|
|
233
|
+
interface TagObject {
|
|
234
|
+
name: string;
|
|
235
|
+
description?: string;
|
|
236
|
+
externalDocs?: ExternalDocumentationObject;
|
|
237
|
+
}
|
|
238
|
+
interface ExamplesObject {
|
|
239
|
+
[name: string]: ExampleObject | ReferenceObject;
|
|
240
|
+
}
|
|
241
|
+
interface ReferenceObject {
|
|
242
|
+
$ref: string;
|
|
243
|
+
summary?: string;
|
|
244
|
+
description?: string;
|
|
245
|
+
}
|
|
246
|
+
type SchemaObjectType = 'integer' | 'number' | 'string' | 'boolean' | 'object' | 'null' | 'array' | 'undefined';
|
|
247
|
+
declare const TYPE_FORMATS: readonly ["uuid", "uri", "date-time", "date", "email", "binary", "password", "phone", "uuid4", "int32", "int64", "float", "double", "byte"];
|
|
248
|
+
type TypeFormatT = (typeof TYPE_FORMATS)[number] | (string & {});
|
|
249
|
+
interface SchemaObject {
|
|
250
|
+
discriminator?: DiscriminatorObject;
|
|
251
|
+
readOnly?: boolean;
|
|
252
|
+
writeOnly?: boolean;
|
|
253
|
+
xml?: XmlObject;
|
|
254
|
+
externalDocs?: ExternalDocumentationObject;
|
|
255
|
+
/** @deprecated use examples instead */
|
|
256
|
+
example?: any;
|
|
257
|
+
examples?: any[];
|
|
258
|
+
deprecated?: boolean;
|
|
259
|
+
type?: SchemaObjectType | SchemaObjectType[];
|
|
260
|
+
format?: TypeFormatT;
|
|
261
|
+
allOf?: (SchemaObject | ReferenceObject)[];
|
|
262
|
+
oneOf?: (SchemaObject | ReferenceObject)[];
|
|
263
|
+
anyOf?: (SchemaObject | ReferenceObject)[];
|
|
264
|
+
not?: SchemaObject | ReferenceObject;
|
|
265
|
+
items?: SchemaObject | ReferenceObject;
|
|
266
|
+
properties?: {
|
|
267
|
+
[propertyName: string]: SchemaObject | ReferenceObject;
|
|
268
|
+
};
|
|
269
|
+
additionalProperties?: SchemaObject | ReferenceObject | boolean;
|
|
270
|
+
propertyNames?: SchemaObject | ReferenceObject;
|
|
271
|
+
description?: string;
|
|
272
|
+
default?: any;
|
|
273
|
+
title?: string;
|
|
274
|
+
multipleOf?: number;
|
|
275
|
+
maximum?: number;
|
|
276
|
+
const?: any;
|
|
277
|
+
/** @desc In OpenAPI 3.1: number */
|
|
278
|
+
exclusiveMaximum?: number;
|
|
279
|
+
minimum?: number;
|
|
280
|
+
/** @desc In OpenAPI 3.1: number */
|
|
281
|
+
exclusiveMinimum?: number;
|
|
282
|
+
maxLength?: number;
|
|
283
|
+
minLength?: number;
|
|
284
|
+
pattern?: string;
|
|
285
|
+
maxItems?: number;
|
|
286
|
+
minItems?: number;
|
|
287
|
+
uniqueItems?: boolean;
|
|
288
|
+
maxProperties?: number;
|
|
289
|
+
minProperties?: number;
|
|
290
|
+
required?: string[];
|
|
291
|
+
enum?: any[];
|
|
292
|
+
prefixItems?: (SchemaObject | ReferenceObject)[];
|
|
293
|
+
/**
|
|
294
|
+
* @desc JSON Schema compliant Content-Type, optional when specified as a key of ContentObject
|
|
295
|
+
* @example image/png
|
|
296
|
+
*/
|
|
297
|
+
contentMediaType?: string;
|
|
298
|
+
/**
|
|
299
|
+
* @desc Specifies the Content-Encoding for the schema, supports all encodings from RFC4648, and "quoted-printable" from RFC2045
|
|
300
|
+
* @override
|
|
301
|
+
* @see https://datatracker.ietf.org/doc/html/rfc4648
|
|
302
|
+
* @see https://datatracker.ietf.org/doc/html/rfc2045#section-6.7
|
|
303
|
+
* @example base64
|
|
304
|
+
*/
|
|
305
|
+
contentEncoding?: string;
|
|
306
|
+
}
|
|
307
|
+
interface SchemasObject {
|
|
308
|
+
[schema: string]: SchemaObject;
|
|
309
|
+
}
|
|
310
|
+
interface DiscriminatorObject {
|
|
311
|
+
propertyName: string;
|
|
312
|
+
mapping?: {
|
|
313
|
+
[key: string]: string;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
interface XmlObject {
|
|
317
|
+
name?: string;
|
|
318
|
+
namespace?: string;
|
|
319
|
+
prefix?: string;
|
|
320
|
+
attribute?: boolean;
|
|
321
|
+
wrapped?: boolean;
|
|
322
|
+
}
|
|
323
|
+
type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
|
|
324
|
+
interface SecuritySchemeObject {
|
|
325
|
+
type: SecuritySchemeType;
|
|
326
|
+
description?: string;
|
|
327
|
+
name?: string;
|
|
328
|
+
in?: string;
|
|
329
|
+
scheme?: string;
|
|
330
|
+
bearerFormat?: string;
|
|
331
|
+
flows?: OAuthFlowsObject;
|
|
332
|
+
openIdConnectUrl?: string;
|
|
333
|
+
}
|
|
334
|
+
interface OAuthFlowsObject {
|
|
335
|
+
implicit?: OAuthFlowObject;
|
|
336
|
+
password?: OAuthFlowObject;
|
|
337
|
+
clientCredentials?: OAuthFlowObject;
|
|
338
|
+
authorizationCode?: OAuthFlowObject;
|
|
339
|
+
}
|
|
340
|
+
interface OAuthFlowObject {
|
|
341
|
+
authorizationUrl?: string;
|
|
342
|
+
tokenUrl?: string;
|
|
343
|
+
refreshUrl?: string;
|
|
344
|
+
scopes: ScopesObject;
|
|
345
|
+
}
|
|
346
|
+
interface ScopesObject {
|
|
347
|
+
[scope: string]: any;
|
|
348
|
+
}
|
|
349
|
+
interface SecurityRequirementObject {
|
|
350
|
+
[name: string]: string[];
|
|
351
|
+
}
|
|
352
|
+
|
|
1
353
|
interface OpenAPIResponse {
|
|
2
354
|
types: string;
|
|
3
355
|
code: string;
|
|
@@ -8,7 +360,6 @@ declare function formatAPIErrorMessage(err: unknown): string;
|
|
|
8
360
|
|
|
9
361
|
type Tables = '';
|
|
10
362
|
type TableToTypeMapping = Record<Tables, any>;
|
|
11
|
-
|
|
12
363
|
interface User {
|
|
13
364
|
id: string;
|
|
14
365
|
first_name?: string;
|
|
@@ -108,4 +459,4 @@ declare class Bagel {
|
|
|
108
459
|
uploadFile<T>(file: File, options?: UploadOptions): Promise<T>;
|
|
109
460
|
}
|
|
110
461
|
|
|
111
|
-
export { Bagel, type TableToTypeMapping, type Tables, type UploadOptions, type User, formatAPIErrorMessage, _default as openAPI };
|
|
462
|
+
export { Bagel, type BaseParameterObject, type CallbackObject, type CallbacksObject, type ComponentsObject, type ContactObject, type ContentObject, type DiscriminatorObject, type EncodingObject, type EncodingPropertyObject, type ExampleObject, type ExamplesObject, type ExternalDocumentationObject, type HeaderObject, type HeadersObject, type InfoObject, type LicenseObject, type LinkObject, type LinkParametersObject, type LinksObject, type MediaTypeObject, type OAuthFlowObject, type OAuthFlowsObject, type OpenAPIObject, type OperationObject, type ParameterLocation, type ParameterObject, type ParameterStyle, type PathItemObject, type PathsObject, type ReferenceObject, type RequestBodyObject, type ResponseObject, type ResponsesObject, type SchemaObject, type SchemaObjectType, type SchemasObject, type ScopesObject, type SecurityRequirementObject, type SecuritySchemeObject, type SecuritySchemeType, type ServerObject, type ServerVariableObject, type TableToTypeMapping, type Tables, type TagObject, type TypeFormatT, type UploadOptions, type User, type XmlObject, dereference, formatAPIErrorMessage, getPath, isReferenceObject, isSchemaObject, _default as openAPI };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import axios$1 from 'axios';
|
|
2
2
|
|
|
3
|
+
function getPath(pathsObject, path) {
|
|
4
|
+
return pathsObject ? pathsObject[path] : void 0;
|
|
5
|
+
}
|
|
6
|
+
function isReferenceObject(obj) {
|
|
7
|
+
if (!obj) return false;
|
|
8
|
+
return Object.prototype.hasOwnProperty.call(obj, "$ref");
|
|
9
|
+
}
|
|
10
|
+
function isSchemaObject(schema) {
|
|
11
|
+
return !Object.prototype.hasOwnProperty.call(schema, "$ref");
|
|
12
|
+
}
|
|
13
|
+
function dereference(property) {
|
|
14
|
+
return property;
|
|
15
|
+
}
|
|
16
|
+
|
|
3
17
|
function toCamelCase(str) {
|
|
4
18
|
return str?.replaceAll(/[-._\s]+(.)?/g, (_, c) => c?.toUpperCase() || "").replace(/^./, (str2) => str2.toLowerCase()) || str || "";
|
|
5
19
|
}
|
|
@@ -32,6 +46,13 @@ function handleArrayItems(schema) {
|
|
|
32
46
|
}
|
|
33
47
|
function schemaToType(schema) {
|
|
34
48
|
if (!schema) return "any";
|
|
49
|
+
if (isReferenceObject(schema)) {
|
|
50
|
+
if (schema.$ref) return resolveReference(schema.$ref);
|
|
51
|
+
}
|
|
52
|
+
if (!isSchemaObject(schema)) {
|
|
53
|
+
console.warn("Schema is not a SchemaObject:", schema);
|
|
54
|
+
return "any";
|
|
55
|
+
}
|
|
35
56
|
if (schema.anyOf) {
|
|
36
57
|
let _t = schema.anyOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
|
|
37
58
|
if (_t === "" || _t === "null") _t = "any";
|
|
@@ -40,7 +61,6 @@ function schemaToType(schema) {
|
|
|
40
61
|
if (schema.allOf) {
|
|
41
62
|
return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
|
|
42
63
|
}
|
|
43
|
-
if (schema.$ref) return resolveReference(schema.$ref);
|
|
44
64
|
switch (schema.type) {
|
|
45
65
|
case "object":
|
|
46
66
|
return "{ [key: string]: any }";
|
|
@@ -73,7 +93,7 @@ function isOptional(schema) {
|
|
|
73
93
|
const splitType = type.split(/\s+\|\s+/);
|
|
74
94
|
const includesNull = splitType.includes("null");
|
|
75
95
|
const includesUndefined = splitType.includes("undefined");
|
|
76
|
-
return includesNull || includesUndefined || schema
|
|
96
|
+
return includesNull || includesUndefined || schema?.default !== void 0;
|
|
77
97
|
}
|
|
78
98
|
function cleanOptionals(str) {
|
|
79
99
|
return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
|
|
@@ -136,6 +156,9 @@ function schemaToTypeWithCollection(schema) {
|
|
|
136
156
|
return type;
|
|
137
157
|
}
|
|
138
158
|
function getResponseType(response) {
|
|
159
|
+
if (isReferenceObject(response)) {
|
|
160
|
+
return void 0;
|
|
161
|
+
}
|
|
139
162
|
const mediaTypeObject = response.content?.["application/json"];
|
|
140
163
|
if (!mediaTypeObject?.schema) return void 0;
|
|
141
164
|
return schemaToTypeWithCollection(mediaTypeObject.schema);
|
|
@@ -163,12 +186,13 @@ function formatPathWithParams(path) {
|
|
|
163
186
|
return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCase(paramName)}}`)}\``;
|
|
164
187
|
}
|
|
165
188
|
function generateRequestBody(requestBody) {
|
|
166
|
-
|
|
189
|
+
const content = dereference(requestBody)?.content;
|
|
190
|
+
if (!content || Object.keys(content).length === 0) {
|
|
167
191
|
return { requestBodyParam: "", requestBodyPayload: "" };
|
|
168
|
-
|
|
192
|
+
}
|
|
169
193
|
if (content["multipart/form-data"]) {
|
|
170
194
|
const multipartFormData = content["multipart/form-data"];
|
|
171
|
-
if (multipartFormData.schema?.$ref?.includes("Body_upload_files")) {
|
|
195
|
+
if (isReferenceObject(multipartFormData.schema) && multipartFormData.schema?.$ref?.includes("Body_upload_files")) {
|
|
172
196
|
return {
|
|
173
197
|
requestBodyParam: "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }",
|
|
174
198
|
requestBodyPayload: "formData"
|
|
@@ -183,7 +207,7 @@ function generateRequestBody(requestBody) {
|
|
|
183
207
|
if (!jsonContent || !jsonContent.schema) {
|
|
184
208
|
return { requestBodyParam: "", requestBodyPayload: "" };
|
|
185
209
|
}
|
|
186
|
-
const bodySchema = jsonContent.schema;
|
|
210
|
+
const bodySchema = dereference(jsonContent.schema);
|
|
187
211
|
const requestBodyType = schemaToType(bodySchema);
|
|
188
212
|
collectTypeForImportStatement(requestBodyType);
|
|
189
213
|
const requestBodyPayload = toCamelCase(bodySchema.title) || toCamelCase(requestBodyType) || "requestBody";
|
|
@@ -207,8 +231,10 @@ function generateFunctionParameters(params, isFileUpload = false) {
|
|
|
207
231
|
}
|
|
208
232
|
const functionParams = [];
|
|
209
233
|
const queryParams = [];
|
|
210
|
-
for (const
|
|
211
|
-
const
|
|
234
|
+
for (const p of params) {
|
|
235
|
+
const param = dereference(p);
|
|
236
|
+
const pSchema = dereference(param.schema);
|
|
237
|
+
const paramType = schemaToType(pSchema);
|
|
212
238
|
collectTypeForImportStatement(paramType);
|
|
213
239
|
const paramName = param.name;
|
|
214
240
|
const varName = toCamelCase(param.name);
|
|
@@ -216,9 +242,9 @@ function generateFunctionParameters(params, isFileUpload = false) {
|
|
|
216
242
|
functionParams.push(
|
|
217
243
|
formatVarType({
|
|
218
244
|
varName,
|
|
219
|
-
schema:
|
|
245
|
+
schema: pSchema,
|
|
220
246
|
required: param.required,
|
|
221
|
-
defaultValue:
|
|
247
|
+
defaultValue: pSchema?.default
|
|
222
248
|
})
|
|
223
249
|
);
|
|
224
250
|
}
|
|
@@ -293,7 +319,8 @@ function buildJSDocComment(operation, method, path) {
|
|
|
293
319
|
}
|
|
294
320
|
function generateFunctionForOperation(method, path, operation) {
|
|
295
321
|
if (!operation) return "";
|
|
296
|
-
const
|
|
322
|
+
const multiPartSchema = dereference(operation.requestBody)?.content?.["multipart/form-data"]?.schema;
|
|
323
|
+
const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes("Body_upload_files");
|
|
297
324
|
const parameters = generateFunctionParameters(
|
|
298
325
|
operation.parameters,
|
|
299
326
|
isFileUpload
|
|
@@ -419,13 +446,16 @@ ${tsString}`;
|
|
|
419
446
|
}
|
|
420
447
|
|
|
421
448
|
function generateTypes(schemas) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
449
|
+
if (!schemas) return "";
|
|
450
|
+
const schemaEntries = Object.entries(schemas);
|
|
451
|
+
return schemaEntries.map(([_typeName, schema]) => {
|
|
452
|
+
const typeName = formatType(_typeName);
|
|
453
|
+
if (!isSchemaObject(schema)) return "";
|
|
454
|
+
if (schema?.enum) {
|
|
425
455
|
return `export type ${typeName} = ${schema.enum.map((item) => `'${item}'`).join(" | ")};
|
|
426
456
|
`;
|
|
427
457
|
}
|
|
428
|
-
if (schema
|
|
458
|
+
if (schema?.type === "array" && schema.items) {
|
|
429
459
|
return `export type ${typeName} = (${schemaToType(schema.items)})[];
|
|
430
460
|
`;
|
|
431
461
|
}
|
|
@@ -570,7 +600,6 @@ function responses(key) {
|
|
|
570
600
|
class BagelAuth {
|
|
571
601
|
constructor(bagel) {
|
|
572
602
|
this.bagel = bagel;
|
|
573
|
-
this.bagel = bagel;
|
|
574
603
|
}
|
|
575
604
|
user = void 0;
|
|
576
605
|
async validateUser() {
|
|
@@ -733,4 +762,4 @@ class Bagel {
|
|
|
733
762
|
}
|
|
734
763
|
}
|
|
735
764
|
|
|
736
|
-
export { Bagel, formatAPIErrorMessage, index as openAPI };
|
|
765
|
+
export { Bagel, dereference, formatAPIErrorMessage, getPath, isReferenceObject, isSchemaObject, index as openAPI };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.28",
|
|
5
5
|
"description": "Bagel core sdk packages",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Neveh Allon",
|
|
@@ -51,31 +51,16 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@typescript-eslint/typescript-estree": "^8.32.1",
|
|
55
54
|
"axios": "^1.9.0"
|
|
56
55
|
},
|
|
57
56
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"handlebars": "^4.7.8",
|
|
60
|
-
"openapi-zod-client": "^1.18.3",
|
|
61
|
-
"openapi3-ts": "^3.1.0"
|
|
57
|
+
"@typescript-eslint/typescript-estree": "^8.33.0"
|
|
62
58
|
},
|
|
63
59
|
"peerDependencies": {
|
|
64
|
-
"@
|
|
65
|
-
"
|
|
66
|
-
"openapi3-ts": "^3.1.0"
|
|
67
|
-
},
|
|
68
|
-
"peerDependenciesMeta": {
|
|
69
|
-
"@apidevtools/swagger-parser": {
|
|
70
|
-
"optional": true
|
|
71
|
-
},
|
|
72
|
-
"openapi-zod-client": {
|
|
73
|
-
"optional": true
|
|
74
|
-
},
|
|
75
|
-
"openapi3-ts": {
|
|
76
|
-
"optional": true
|
|
77
|
-
}
|
|
60
|
+
"@typescript-eslint/typescript-estree": "^8.33.0",
|
|
61
|
+
"type-fest": "^4"
|
|
78
62
|
},
|
|
63
|
+
"peerDependenciesMeta": {},
|
|
79
64
|
"scripts": {
|
|
80
65
|
"dev": "unbuild --stub",
|
|
81
66
|
"build": "unbuild",
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import ax from 'axios'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export * from './openAPITools'
|
|
4
|
+
export { default as openAPI } from './openAPITools'
|
|
4
5
|
|
|
5
6
|
export type Tables = ''
|
|
6
7
|
export type TableToTypeMapping = Record<Tables, any>
|
|
7
8
|
|
|
8
|
-
export { openAPI }
|
|
9
9
|
export interface User {
|
|
10
10
|
id: string
|
|
11
11
|
first_name?: string
|
|
@@ -108,9 +108,7 @@ function responses(key: string) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
class BagelAuth {
|
|
111
|
-
constructor(private bagel: Bagel) {
|
|
112
|
-
this.bagel = bagel
|
|
113
|
-
}
|
|
111
|
+
constructor(private bagel: Bagel) {}
|
|
114
112
|
|
|
115
113
|
user: User | undefined = undefined
|
|
116
114
|
|