@bagelink/sdk 1.6.53 → 1.6.61
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 +15 -1
- package/dist/index.mjs +15 -1
- package/package.json +1 -1
- package/src/openAPITools/index.ts +11 -1
- package/src/openAPITools/utils.ts +8 -0
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,13 @@ function schemaToType(schema) {
|
|
|
74
74
|
}
|
|
75
75
|
return _t;
|
|
76
76
|
}
|
|
77
|
+
if (schema.oneOf) {
|
|
78
|
+
let _t = schema.oneOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
|
|
79
|
+
if (_t === "" || _t === "null") {
|
|
80
|
+
_t = "any";
|
|
81
|
+
}
|
|
82
|
+
return _t;
|
|
83
|
+
}
|
|
77
84
|
if (schema.allOf) {
|
|
78
85
|
return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
|
|
79
86
|
}
|
|
@@ -693,6 +700,7 @@ function generateTypes(schemas) {
|
|
|
693
700
|
const basicAuthHeader = { Authorization: "Basic YmFnZWxfdXNlcm5hbWU6Tm90U2VjdXJlQGJhZ2Vs" };
|
|
694
701
|
const index = async (openApiUrl, baseUrl) => {
|
|
695
702
|
try {
|
|
703
|
+
console.log(`Fetching OpenAPI spec from: ${openApiUrl}`);
|
|
696
704
|
const { data: openApi } = await axios__default.get(openApiUrl, { headers: basicAuthHeader });
|
|
697
705
|
const schemas = openApi.components?.schemas;
|
|
698
706
|
if (!schemas) {
|
|
@@ -706,7 +714,13 @@ const index = async (openApiUrl, baseUrl) => {
|
|
|
706
714
|
const code = generateFunctions(paths, baseUrl);
|
|
707
715
|
return { types, code };
|
|
708
716
|
} catch (error) {
|
|
709
|
-
|
|
717
|
+
if (error.response) {
|
|
718
|
+
throw new Error(`HTTP ${error.response.status}: ${error.response.statusText} - Failed to fetch OpenAPI spec from ${openApiUrl}`);
|
|
719
|
+
} else if (error.request) {
|
|
720
|
+
throw new Error(`Unable to connect to ${openApiUrl}. Is the server running and accessible?`);
|
|
721
|
+
} else {
|
|
722
|
+
throw new Error(`Error fetching OpenAPI spec: ${error.message}`);
|
|
723
|
+
}
|
|
710
724
|
}
|
|
711
725
|
};
|
|
712
726
|
|
package/dist/index.mjs
CHANGED
|
@@ -68,6 +68,13 @@ function schemaToType(schema) {
|
|
|
68
68
|
}
|
|
69
69
|
return _t;
|
|
70
70
|
}
|
|
71
|
+
if (schema.oneOf) {
|
|
72
|
+
let _t = schema.oneOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" | ");
|
|
73
|
+
if (_t === "" || _t === "null") {
|
|
74
|
+
_t = "any";
|
|
75
|
+
}
|
|
76
|
+
return _t;
|
|
77
|
+
}
|
|
71
78
|
if (schema.allOf) {
|
|
72
79
|
return schema.allOf.map((s) => schemaToType(s)).filter((p) => p !== "any").join(" & ");
|
|
73
80
|
}
|
|
@@ -687,6 +694,7 @@ function generateTypes(schemas) {
|
|
|
687
694
|
const basicAuthHeader = { Authorization: "Basic YmFnZWxfdXNlcm5hbWU6Tm90U2VjdXJlQGJhZ2Vs" };
|
|
688
695
|
const index = async (openApiUrl, baseUrl) => {
|
|
689
696
|
try {
|
|
697
|
+
console.log(`Fetching OpenAPI spec from: ${openApiUrl}`);
|
|
690
698
|
const { data: openApi } = await axios$1.get(openApiUrl, { headers: basicAuthHeader });
|
|
691
699
|
const schemas = openApi.components?.schemas;
|
|
692
700
|
if (!schemas) {
|
|
@@ -700,7 +708,13 @@ const index = async (openApiUrl, baseUrl) => {
|
|
|
700
708
|
const code = generateFunctions(paths, baseUrl);
|
|
701
709
|
return { types, code };
|
|
702
710
|
} catch (error) {
|
|
703
|
-
|
|
711
|
+
if (error.response) {
|
|
712
|
+
throw new Error(`HTTP ${error.response.status}: ${error.response.statusText} - Failed to fetch OpenAPI spec from ${openApiUrl}`);
|
|
713
|
+
} else if (error.request) {
|
|
714
|
+
throw new Error(`Unable to connect to ${openApiUrl}. Is the server running and accessible?`);
|
|
715
|
+
} else {
|
|
716
|
+
throw new Error(`Error fetching OpenAPI spec: ${error.message}`);
|
|
717
|
+
}
|
|
704
718
|
}
|
|
705
719
|
};
|
|
706
720
|
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ const basicAuthHeader = { Authorization: 'Basic YmFnZWxfdXNlcm5hbWU6Tm90U2VjdXJl
|
|
|
11
11
|
|
|
12
12
|
export default async (openApiUrl: string, baseUrl: string): Promise<OpenAPIResponse> => {
|
|
13
13
|
try {
|
|
14
|
+
console.log(`Fetching OpenAPI spec from: ${openApiUrl}`)
|
|
14
15
|
const { data: openApi } = await axios.get<OpenAPIObject>(openApiUrl, { headers: basicAuthHeader })
|
|
15
16
|
const schemas = openApi.components?.schemas
|
|
16
17
|
if (!schemas) { throw new Error('No schemas found in OpenAPI document') }
|
|
@@ -21,7 +22,16 @@ export default async (openApiUrl: string, baseUrl: string): Promise<OpenAPIRespo
|
|
|
21
22
|
const code = generateFunctions(paths, baseUrl) // TODO baseURL should not be set here, but should be instatiated in runtime somehow
|
|
22
23
|
return { types, code }
|
|
23
24
|
} catch (error: any) {
|
|
24
|
-
|
|
25
|
+
if (error.response) {
|
|
26
|
+
// Server responded with error status
|
|
27
|
+
throw new Error(`HTTP ${error.response.status}: ${error.response.statusText} - Failed to fetch OpenAPI spec from ${openApiUrl}`)
|
|
28
|
+
} else if (error.request) {
|
|
29
|
+
// Request was made but no response received
|
|
30
|
+
throw new Error(`Unable to connect to ${openApiUrl}. Is the server running and accessible?`)
|
|
31
|
+
} else {
|
|
32
|
+
// Something else went wrong
|
|
33
|
+
throw new Error(`Error fetching OpenAPI spec: ${error.message}`)
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
|
|
@@ -70,6 +70,14 @@ export function schemaToType(schema?: SchemaObject | ReferenceObject): string {
|
|
|
70
70
|
if (_t === '' || _t === 'null') { _t = 'any' }
|
|
71
71
|
return _t
|
|
72
72
|
}
|
|
73
|
+
if (schema.oneOf) {
|
|
74
|
+
let _t = schema.oneOf
|
|
75
|
+
.map(s => schemaToType(s))
|
|
76
|
+
.filter(p => p !== 'any')
|
|
77
|
+
.join(' | ')
|
|
78
|
+
if (_t === '' || _t === 'null') { _t = 'any' }
|
|
79
|
+
return _t
|
|
80
|
+
}
|
|
73
81
|
if (schema.allOf) {
|
|
74
82
|
return schema.allOf
|
|
75
83
|
.map(s => schemaToType(s))
|