Skip to content

Commit f01fa6b

Browse files
committed
ci: regenerated with OpenAPI Doc 0.1.0, Speakeay CLI 0.15.7
1 parent cbedf27 commit f01fa6b

File tree

10 files changed

+61
-105
lines changed

10 files changed

+61
-105
lines changed

gen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
management:
22
openapi-checksum: eb72fa251c1471dd090eb0b974395d58
33
openapi-version: 0.1.0
4-
speakeasy-version: 0.15.1
4+
speakeasy-version: 0.15.7
55
telemetryenabled: null
66
typescript:
77
author: Speakeasy
88
packagename: '@speakeasy-api/speakeasy-client-sdk-typescript'
9-
version: 0.5.1
9+
version: 0.5.2

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"name": "@speakeasy-api/speakeasy-client-sdk-typescript",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"author": "Speakeasy",
55
"scripts": {
66
"lint:fix": "tsc --noemit && eslint \"./src\" --ext .ts,.tsx --fix",
7-
"build": "tsc --build",
8-
"prepare": "npm run build"
7+
"prepare": "tsc --build"
98
},
109
"dependencies": {
1110
"axios": "^1.1.3",
@@ -18,7 +17,6 @@
1817
"@typescript-eslint/parser": "^5.40.0",
1918
"@types/node": "^18.11.5",
2019
"@types/qs": "^6.9.7",
21-
"@types/reflect-metadata": "^0.1.0",
2220
"eslint": "^8.25.0",
2321
"eslint-config-prettier": "^8.5.0",
2422
"eslint-plugin-prettier": "^4.2.1",

src/internal/utils/requestbody.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { createReadStream, writeFileSync } from "fs";
2-
31
import FormData from "form-data";
4-
import { join } from "path";
52
import qs from "qs";
63

74
const requestMetadataKey = "request";
85
const mpFormMetadataKey = "multipart_form";
96

107
export function serializeRequestBody(request: any): [object, any] {
11-
const fieldNames: string[] = Object.getOwnPropertyNames(request);
8+
if (!request.hasOwnProperty(requestMetadataKey)) {
9+
throw new Error("request body not found");
10+
}
11+
const requestBodyObj = request[requestMetadataKey];
12+
const fieldNames: string[] = Object.getOwnPropertyNames(requestBodyObj);
1213
let [requestHeaders, requestBody]: [object, any] = [{}, {}];
1314
fieldNames.forEach((fname) => {
1415
const requestAnn: string = Reflect.getMetadata(
1516
requestMetadataKey,
16-
request,
17+
requestBodyObj,
1718
fname
1819
);
1920
if (requestAnn == null) return;
@@ -22,22 +23,35 @@ export function serializeRequestBody(request: any): [object, any] {
2223
switch (requestDecorator.MediaType) {
2324
case "multipart/form-data":
2425
case "multipart/mixed":
25-
requestBody = encodeMultipartFormData(request[fname]);
26+
requestBody = encodeMultipartFormData(requestBodyObj[fname]);
2627
requestHeaders = (requestBody as FormData).getHeaders();
2728
break;
2829
case "application/x-www-form-urlencoded":
2930
[requestHeaders, requestBody] = [
3031
{ "Content-Type": `${requestDecorator.MediaType}` },
31-
qs.stringify({ ...request[fname] }),
32+
qs.stringify(requestBodyObj[fname]),
3233
];
3334
break;
3435
case "application/json":
3536
case "text/json":
36-
default:
3737
[requestHeaders, requestBody] = [
3838
{ "Content-Type": `${requestDecorator.MediaType}` },
39-
{ ...request[fname] },
39+
{ ...requestBodyObj[fname] },
4040
];
41+
break;
42+
default:
43+
requestBody = requestBodyObj[fname];
44+
const requestBodyType: string = typeof requestBody;
45+
if (
46+
requestBodyType === "string" ||
47+
requestBody instanceof String ||
48+
requestBody instanceof Uint8Array
49+
)
50+
requestHeaders = { "Content-Type": `${requestDecorator.MediaType}` };
51+
else
52+
throw new Error(
53+
`invalid request body type ${requestBodyType} for mediaType ${requestDecorator.MediaType}`
54+
);
4155
}
4256
});
4357
return [requestHeaders, requestBody];
@@ -58,14 +72,14 @@ function encodeMultipartFormData(form: any): FormData {
5872
if (mpFormDecorator.File)
5973
return encodeMultipartFormDataFile(formData, form[fname]);
6074
else if (mpFormDecorator.JSON) {
61-
formData.append(mpFormDecorator.Name, { ...form[fname] });
75+
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname]));
6276
} else {
6377
if (Array.isArray(form[fname])) {
6478
form[fname].forEach((val: any) => {
65-
formData.append(mpFormDecorator.Name + "[]", JSON.stringify(val));
79+
formData.append(mpFormDecorator.Name + "[]", String(val));
6680
});
6781
} else {
68-
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname]));
82+
formData.append(mpFormDecorator.Name, String(form[fname]));
6983
}
7084
}
7185
});
@@ -98,14 +112,12 @@ function encodeMultipartFormDataFile(formData: FormData, file: any): FormData {
98112
}
99113
});
100114

101-
if (mpFormDecoratorName === "" || fileName === "" || content == null)
115+
if (mpFormDecoratorName === "" || fileName === "" || content == null) {
102116
throw new Error("invalid multipart/form-data file");
103-
writeFileSync(join(__dirname, fileName), content, {
104-
flag: "w",
105-
});
117+
}
106118
formData.append(
107119
mpFormDecoratorName,
108-
createReadStream(join(__dirname, fileName))
120+
Buffer.from(content)
109121
);
110122
return formData;
111123
}

src/sdk/apiendpoints.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
2-
import FormData from "form-data";
32
import * as operations from "./models/operations";
43
import * as utils from "../internal/utils";
54

@@ -370,16 +369,13 @@ export class ApiEndpoints {
370369

371370
const client: AxiosInstance = this._securityClient!;
372371
const headers = {...reqBodyHeaders, ...config?.headers};
373-
let body: any;
374-
if (reqBody instanceof FormData) body = reqBody;
375-
else body = {...reqBody};
376-
if (body == null || Object.keys(body).length === 0) throw new Error("request body is required");
372+
if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required");
377373
return client
378374
.request({
379375
url: url,
380376
method: "put",
381377
headers: headers,
382-
data: body,
378+
data: reqBody,
383379
...config,
384380
}).then((httpRes: AxiosResponse) => {
385381
const contentType: string = httpRes?.headers?.["content-type"] ?? "";

src/sdk/apis.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, ParamsSerializerOptions } from "axios";
2-
import FormData from "form-data";
32
import * as operations from "./models/operations";
43
import * as utils from "../internal/utils";
54

@@ -300,16 +299,13 @@ export class Apis {
300299

301300
const client: AxiosInstance = this._securityClient!;
302301
const headers = {...reqBodyHeaders, ...config?.headers};
303-
let body: any;
304-
if (reqBody instanceof FormData) body = reqBody;
305-
else body = {...reqBody};
306-
if (body == null || Object.keys(body).length === 0) throw new Error("request body is required");
302+
if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required");
307303
return client
308304
.request({
309305
url: url,
310306
method: "put",
311307
headers: headers,
312-
data: body,
308+
data: reqBody,
313309
...config,
314310
}).then((httpRes: AxiosResponse) => {
315311
const contentType: string = httpRes?.headers?.["content-type"] ?? "";

src/sdk/metadata.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
2-
import FormData from "form-data";
32
import * as operations from "./models/operations";
43
import * as utils from "../internal/utils";
54

@@ -133,16 +132,13 @@ export class Metadata {
133132

134133
const client: AxiosInstance = this._securityClient!;
135134
const headers = {...reqBodyHeaders, ...config?.headers};
136-
let body: any;
137-
if (reqBody instanceof FormData) body = reqBody;
138-
else body = {...reqBody};
139-
if (body == null || Object.keys(body).length === 0) throw new Error("request body is required");
135+
if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required");
140136
return client
141137
.request({
142138
url: url,
143139
method: "post",
144140
headers: headers,
145-
data: body,
141+
data: reqBody,
146142
...config,
147143
}).then((httpRes: AxiosResponse) => {
148144
const contentType: string = httpRes?.headers?.["content-type"] ?? "";

src/sdk/schemas.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
2-
import FormData from "form-data";
32
import * as operations from "./models/operations";
43
import * as utils from "../internal/utils";
54

@@ -382,16 +381,13 @@ export class Schemas {
382381

383382
const client: AxiosInstance = this._securityClient!;
384383
const headers = {...reqBodyHeaders, ...config?.headers};
385-
let body: any;
386-
if (reqBody instanceof FormData) body = reqBody;
387-
else body = {...reqBody};
388-
if (body == null || Object.keys(body).length === 0) throw new Error("request body is required");
384+
if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required");
389385
return client
390386
.request({
391387
url: url,
392388
method: "post",
393389
headers: headers,
394-
data: body,
390+
data: reqBody,
395391
...config,
396392
}).then((httpRes: AxiosResponse) => {
397393
const contentType: string = httpRes?.headers?.["content-type"] ?? "";

src/sdk/sdk.ts

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,14 @@ export const ServerList: Record<string, string> = {
1717
[ServerProd]: "https://api.prod.speakeasyapi.dev",
1818
} as const;
1919

20-
export function withServerURL(
21-
serverURL: string,
22-
params?: Map<string, string>
23-
): OptsFunc {
24-
return (sdk: SDK) => {
25-
if (params != null) {
26-
serverURL = utils.replaceParameters(serverURL, params);
27-
}
28-
sdk._serverURL = serverURL;
29-
};
30-
}
3120

32-
export function withServer(
33-
server: string,
34-
params?: Map<string, string>
35-
): OptsFunc {
36-
return (sdk: SDK) => {
37-
if (!ServerList.hasOwnProperty(server)) {
38-
throw new Error("Invalid server: " + server);
39-
}
40-
withServerURL(ServerList[server], params)(sdk);
41-
};
42-
}
4321

44-
export function withClient(client: AxiosInstance): OptsFunc {
45-
return (sdk: SDK) => {
46-
sdk._defaultClient = client;
47-
};
48-
}
22+
export type SDKProps = {
23+
defaultClient?: AxiosInstance;
4924

50-
export function withSecurity(security: Security): OptsFunc {
51-
if (!(security instanceof utils.SpeakeasyBase)) {
52-
security = new Security(security);
53-
}
54-
return (sdk: SDK) => {
55-
sdk._security = security;
56-
};
25+
security?: Security;
26+
27+
serverUrl?: string;
5728
}
5829

5930
/* SDK Documentation: https://docs.speakeasyapi.dev - The Speakeasy Platform Documentation*/
@@ -67,31 +38,22 @@ export class SDK {
6738

6839
public _defaultClient: AxiosInstance;
6940
public _securityClient: AxiosInstance;
70-
public _security?: Security;
7141
public _serverURL: string;
7242
private _language = "typescript";
73-
private _sdkVersion = "0.5.1";
43+
private _sdkVersion = "0.5.2";
7444
private _genVersion = "";
7545

76-
constructor(...opts: OptsFunc[]) {
77-
opts.forEach((o) => o(this));
78-
if (!this._serverURL) {
79-
this._serverURL = ServerList[ServerProd];
80-
}
46+
constructor(props: SDKProps) {
47+
this._serverURL = props.serverUrl ?? ServerList[ServerProd];
8148

82-
if (!this._defaultClient) {
83-
this._defaultClient = axios.create({ baseURL: this._serverURL });
84-
}
85-
86-
if (!this._securityClient) {
87-
if (this._security) {
88-
this._securityClient = utils.createSecurityClient(
89-
this._defaultClient,
90-
this._security
91-
);
92-
} else {
93-
this._securityClient = this._defaultClient;
94-
}
49+
this._defaultClient = props.defaultClient ?? axios.create({ baseURL: this._serverURL });
50+
if (props.security) {
51+
this._securityClient = utils.createSecurityClient(
52+
this._defaultClient,
53+
props.security
54+
);
55+
} else {
56+
this._securityClient = this._defaultClient;
9557
}
9658

9759
this.apiEndpoints = new ApiEndpoints(
@@ -148,4 +110,4 @@ export class SDK {
148110
this._genVersion
149111
);
150112
}
151-
}
113+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": ["esnext", "DOM"],
4+
"lib": ["es2021"],
55
"baseUrl": "src",
66
"rootDir": "src",
77
"outDir": "dist",

0 commit comments

Comments
 (0)