Skip to content

Commit fb4326b

Browse files
request body fixes
1 parent d3ca6bc commit fb4326b

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

src/internal/utils/requestbody.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import FormData from "form-data";
33
const requestMetadataKey = "request";
44
const mpFormMetadataKey = "multipart_form";
55

6-
export function SerializeRequestBody(
7-
request: any
8-
): [object, string | FormData] {
6+
export function SerializeRequestBody(request: any): [object, any] {
97
const fieldNames: string[] = Object.getOwnPropertyNames(request);
10-
let [requestHeaders, requestBody]: [object, string | FormData] = [{}, ""];
8+
let [requestHeaders, requestBody]: [object, any] = [{}, {}];
119
fieldNames.forEach((fname) => {
1210
const requestAnn: string = Reflect.getMetadata(
1311
requestMetadataKey,
@@ -27,7 +25,7 @@ export function SerializeRequestBody(
2725
case "text/json":
2826
default:
2927
[requestHeaders, requestBody] = [
30-
{ "Content-Type": `"${requestDecorator.MediaType}"` },
28+
{ "Content-Type": `${requestDecorator.MediaType}` },
3129
request[fname],
3230
];
3331
}

src/internal/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function ReplaceParameters(
1919
let res: string = stringWithParams;
2020
params.forEach((value, key) => {
2121
const match: string = "{" + key + "}";
22-
res = stringWithParams.replaceAll(match, value);
22+
res = res.replaceAll(match, value);
2323
});
2424
return res;
2525
}
@@ -29,7 +29,7 @@ export function GenerateURL(
2929
path: string,
3030
pathParams: any
3131
): string {
32-
const url: string = serverURL.replace(/\/$/, "");
32+
const url: string = serverURL.replace(/\/$/, "") + path;
3333
const parsedParameters: Map<string, string> = new Map<string, string>();
3434
const fieldNames: string[] = Object.getOwnPropertyNames(pathParams);
3535
fieldNames.forEach((fname) => {

src/sdk/models/operations/getapis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export class GetApisQueryParams {
2323
}
2424

2525
export class GetApisRequest {
26-
QueryParams?: GetApisQueryParams;
26+
QueryParams: GetApisQueryParams;
2727

28-
constructor(QueryParams?: GetApisQueryParams) {
28+
constructor(QueryParams: GetApisQueryParams) {
2929
this.QueryParams = QueryParams;
3030
}
3131
}

src/sdk/sdk.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,8 @@ export class SDK {
14141414
props.PathParams
14151415
);
14161416

1417-
let [reqHeaders, reqBody]: [object, string | FormData] = [{}, ""];
1417+
let [reqHeaders, reqBody]: [object, any] = [{}, {}];
1418+
14181419
try {
14191420
[reqHeaders, reqBody] = SerializeRequestBody(props);
14201421
} catch (e: unknown) {
@@ -1432,11 +1433,14 @@ export class SDK {
14321433
| AxiosResponse<operations.InsertVersionMetadataResponse>
14331434
| undefined = undefined;
14341435
try {
1436+
let body: unknown;
1437+
if (reqBody instanceof FormData) body = reqBody;
1438+
else body = { ...reqBody };
14351439
httpRes = await client!.post<
14361440
operations.InsertVersionMetadataResponse,
14371441
AxiosResponse<operations.InsertVersionMetadataResponse>,
14381442
unknown
1439-
>(url, reqBody, {
1443+
>(url, body, {
14401444
headers: headers,
14411445
...config,
14421446
});
@@ -1537,7 +1541,8 @@ export class SDK {
15371541
props.PathParams
15381542
);
15391543

1540-
let [reqHeaders, reqBody]: [object, string | FormData] = [{}, ""];
1544+
let [reqHeaders, reqBody]: [object, any] = [{}, {}];
1545+
15411546
try {
15421547
[reqHeaders, reqBody] = SerializeRequestBody(props);
15431548
} catch (e: unknown) {
@@ -1554,11 +1559,15 @@ export class SDK {
15541559
let httpRes: AxiosResponse<operations.RegisterSchemaResponse> | undefined =
15551560
undefined;
15561561
try {
1562+
let body: unknown;
1563+
if (reqBody instanceof FormData) body = reqBody;
1564+
else body = { ...reqBody };
1565+
15571566
httpRes = await client!.post<
15581567
operations.RegisterSchemaResponse,
15591568
AxiosResponse<operations.RegisterSchemaResponse>,
15601569
unknown
1561-
>(url, reqBody, {
1570+
>(url, body, {
15621571
headers: headers,
15631572
...config,
15641573
});
@@ -1651,7 +1660,8 @@ export class SDK {
16511660
props.PathParams
16521661
);
16531662

1654-
let [reqHeaders, reqBody]: [object, string | FormData] = [{}, ""];
1663+
let [reqHeaders, reqBody]: [object, any] = [{}, {}];
1664+
16551665
try {
16561666
[reqHeaders, reqBody] = SerializeRequestBody(props);
16571667
} catch (e: unknown) {
@@ -1668,11 +1678,15 @@ export class SDK {
16681678
let httpRes: AxiosResponse<operations.UpsertApiResponse> | undefined =
16691679
undefined;
16701680
try {
1681+
let body: unknown;
1682+
if (reqBody instanceof FormData) body = reqBody;
1683+
else body = { ...reqBody };
1684+
16711685
httpRes = await client!.put<
16721686
operations.UpsertApiResponse,
16731687
AxiosResponse<operations.UpsertApiResponse>,
16741688
unknown
1675-
>(url, reqBody, {
1689+
>(url, body, {
16761690
headers: headers,
16771691
...config,
16781692
});
@@ -1715,7 +1729,8 @@ export class SDK {
17151729
props.PathParams
17161730
);
17171731

1718-
let [reqHeaders, reqBody]: [object, string | FormData] = [{}, ""];
1732+
let [reqHeaders, reqBody]: [object, any] = [{}, {}];
1733+
17191734
try {
17201735
[reqHeaders, reqBody] = SerializeRequestBody(props);
17211736
} catch (e: unknown) {
@@ -1733,11 +1748,15 @@ export class SDK {
17331748
| AxiosResponse<operations.UpsertApiEndpointResponse>
17341749
| undefined = undefined;
17351750
try {
1751+
let body: unknown;
1752+
if (reqBody instanceof FormData) body = reqBody;
1753+
else body = { ...reqBody };
1754+
17361755
httpRes = await client!.put<
17371756
operations.UpsertApiEndpointResponse,
17381757
AxiosResponse<operations.UpsertApiEndpointResponse>,
17391758
unknown
1740-
>(url, reqBody, {
1759+
>(url, body, {
17411760
headers: headers,
17421761
...config,
17431762
});

0 commit comments

Comments
 (0)