Skip to content

Commit bd517cc

Browse files
fix all syntax + reformat
1 parent 1388213 commit bd517cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1537
-1423
lines changed

src/internal/utils/pathparams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function GetSimplePathParams(
3030
paramName: string,
3131
paramValue: any
3232
): Map<string, string> {
33-
let pathParams: Map<string, string> = new Map<string, string>();
33+
const pathParams: Map<string, string> = new Map<string, string>();
3434
if (typeof paramValue === "string") pathParams.set(paramName, paramValue);
3535
else pathParams.set(paramName, JSON.stringify(paramValue));
3636
return pathParams;
@@ -52,4 +52,4 @@ export class ParamDecorator {
5252
this.ParamName = ParamName;
5353
this.Serialization = Serialization;
5454
}
55-
}
55+
}

src/internal/utils/requestbody.ts

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import FormData from "form-data";
2+
13
const requestMetadataKey = "request";
4+
const mpFormMetadataKey = "multipart_form";
25

3-
export function SerializeRequestBody(request: any): [string, unknown] {
6+
export function SerializeRequestBody(
7+
request: any
8+
): [object, string | FormData] {
49
const fieldNames: string[] = Object.getOwnPropertyNames(request);
5-
let [mediaType, requestBody]: [string, unknown] = ["", ""];
10+
let [requestHeaders, requestBody]: [object, string | FormData] = [{}, ""];
611
fieldNames.forEach((fname) => {
712
const requestAnn: string = Reflect.getMetadata(
813
requestMetadataKey,
@@ -15,18 +20,121 @@ export function SerializeRequestBody(request: any): [string, unknown] {
1520
switch (requestDecorator.MediaType) {
1621
case "multipart/form-data":
1722
case "multipart/mixed":
18-
[mediaType, requestBody] = [
19-
requestDecorator.MediaType,
20-
EncodeMultipartFormData(request[fname]),
21-
];
23+
requestBody = EncodeMultipartFormData(request[fname]);
24+
requestHeaders = requestBody.getHeaders();
2225
break;
2326
case "application/json":
2427
case "text/json":
2528
default:
26-
[mediaType, requestBody] = [requestDecorator.MediaType, request[fname]];
29+
[requestHeaders, requestBody] = [
30+
{ "Content-Type": `"${requestDecorator.MediaType}"` },
31+
request[fname],
32+
];
33+
}
34+
});
35+
return [requestHeaders, requestBody];
36+
}
37+
38+
function EncodeMultipartFormData(form: any): FormData {
39+
const formData: FormData = new FormData();
40+
const fieldNames: string[] = Object.getOwnPropertyNames(form);
41+
fieldNames.forEach((fname) => {
42+
const mpFormAnn: string = Reflect.getMetadata(
43+
mpFormMetadataKey,
44+
form,
45+
fname
46+
);
47+
if (mpFormAnn == null) return;
48+
const mpFormDecorator: MultipartFormDecorator =
49+
ParseMultipartFormDecorator(mpFormAnn);
50+
if (mpFormDecorator.File)
51+
return EncodeMultipartFormDataFile(formData, form[fname]);
52+
else if (mpFormDecorator.JSON) {
53+
formData.append(mpFormDecorator.Name, JSON.stringify(form[fname]));
54+
} else {
55+
// let formData: FormData = new FormData();
56+
// const val: unknown = form[fname];
57+
// if (Array.isArray(form[fname]))
58+
// formData.append(mpFormDecorator.Name + "[]", val);
59+
// else
60+
// formData.append(mpFormDecorator.Name, val)
61+
}
62+
});
63+
return formData;
64+
}
65+
66+
function EncodeMultipartFormDataFile(
67+
formData: FormData,
68+
file: any
69+
): FormData | Error {
70+
if (typeof file !== "object" || Array.isArray(file) || file == null) {
71+
return new Error("invalid type for multipart/form-data file");
72+
}
73+
const fieldNames: string[] = Object.getOwnPropertyNames(file);
74+
const content: string | undefined = undefined;
75+
let fileName: string | undefined = undefined;
76+
fieldNames.forEach((fname) => {
77+
const mpFormAnn: string = Reflect.getMetadata(
78+
mpFormMetadataKey,
79+
file,
80+
fname
81+
);
82+
if (mpFormAnn == null) return;
83+
const mpFormDecorator: MultipartFormDecorator =
84+
ParseMultipartFormDecorator(mpFormAnn);
85+
let content = "";
86+
if (!mpFormDecorator.Content && mpFormDecorator.Name == "") return;
87+
if (mpFormDecorator.Content) content = file[fname];
88+
else fileName = file[fname];
89+
});
90+
91+
if (content == null || fileName == null)
92+
return new Error("invalid multipart/form-data file");
93+
formData.append(fileName!, content!);
94+
return formData;
95+
}
96+
97+
function ParseMultipartFormDecorator(
98+
mpFormAnn: string
99+
): MultipartFormDecorator {
100+
// example "name=file"
101+
const mpFormDecorator: MultipartFormDecorator = new MultipartFormDecorator(
102+
false,
103+
false,
104+
false,
105+
""
106+
);
107+
mpFormAnn.split(";").forEach((mpFormAnnPart) => {
108+
const [mpFormKey, mpFormVal]: string[] = mpFormAnnPart.split("=");
109+
switch (mpFormKey) {
110+
case "file":
111+
mpFormDecorator.File = mpFormVal == "true";
112+
break;
113+
case "content":
114+
mpFormDecorator.Content = mpFormVal == "true";
115+
break;
116+
case "name":
117+
mpFormDecorator.Name = mpFormVal;
118+
break;
119+
case "json":
120+
mpFormDecorator.JSON = mpFormVal == "true";
27121
}
28122
});
29-
return [mediaType, requestBody];
123+
124+
return mpFormDecorator;
125+
}
126+
127+
class MultipartFormDecorator {
128+
File: boolean;
129+
Content: boolean;
130+
JSON: boolean;
131+
Name: string;
132+
constructor(File: boolean, Content: boolean, JSON: boolean, Name: string) {
133+
this.File = File;
134+
this.Content = Content;
135+
this.JSON = JSON;
136+
this.Name = Name;
137+
}
30138
}
31139

32140
function ParseRequestDecorator(requestAnn: string): RequestDecorator {

src/internal/utils/security.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ class SecurityDecorator {
181181
this.Scheme = Scheme;
182182
this.SubType = SubType;
183183
}
184-
}
184+
}

src/internal/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ export function GenerateURL(
4949
}
5050
});
5151
return ReplaceParameters(url, parsedParameters);
52-
}
52+
}
Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
import {Metadata} from "../../../internal/utils/utils";
1+
import { Metadata } from "../../../internal/utils/utils";
22
import * as shared from "../shared";
33

44
export class DeleteApiPathParams {
5-
@Metadata("pathParam, style=simple;explode=false;name=apiID")
6-
ApiId: string;
7-
@Metadata("pathParam, style=simple;explode=false;name=versionID")
8-
VersionId: string;
9-
10-
constructor(ApiId: string, VersionId: string) {
11-
this.ApiId = ApiId;
12-
this.VersionId = VersionId;
13-
}
5+
@Metadata("pathParam, style=simple;explode=false;name=apiID")
6+
ApiId: string;
7+
@Metadata("pathParam, style=simple;explode=false;name=versionID")
8+
VersionId: string;
9+
10+
constructor(ApiId: string, VersionId: string) {
11+
this.ApiId = ApiId;
12+
this.VersionId = VersionId;
13+
}
1414
}
1515

1616
export class DeleteApiRequest {
17-
18-
PathParams: DeleteApiPathParams;
19-
20-
constructor(PathParams: DeleteApiPathParams) {
21-
this.PathParams = PathParams;
22-
}
17+
PathParams: DeleteApiPathParams;
18+
19+
constructor(PathParams: DeleteApiPathParams) {
20+
this.PathParams = PathParams;
21+
}
2322
}
2423

2524
export class DeleteApiResponse {
26-
27-
ContentType: string;
28-
29-
Error?: shared.Error;
30-
31-
StatusCode: number;
32-
33-
constructor(ContentType: string, StatusCode: number, Error?: Error) {
34-
this.ContentType = ContentType;
35-
this.Error = Error;
36-
this.StatusCode = StatusCode;
37-
}
38-
}
25+
ContentType: string;
3926

27+
Error?: shared.Error;
4028

29+
StatusCode: number;
4130

31+
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
32+
this.ContentType = ContentType;
33+
this.Error = Error;
34+
this.StatusCode = StatusCode;
35+
}
36+
}
Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
import {Metadata} from "../../../internal/utils/utils";
1+
import { Metadata } from "../../../internal/utils/utils";
22
import * as shared from "../shared";
33

44
export class DeleteApiEndpointPathParams {
5-
@Metadata("pathParam, style=simple;explode=false;name=apiEndpointID")
6-
ApiEndpointId: string;
7-
@Metadata("pathParam, style=simple;explode=false;name=apiID")
8-
ApiId: string;
9-
@Metadata("pathParam, style=simple;explode=false;name=versionID")
10-
VersionId: string;
11-
12-
constructor(ApiEndpointId: string, ApiId: string, VersionId: string) {
13-
this.ApiEndpointId = ApiEndpointId;
14-
this.ApiId = ApiId;
15-
this.VersionId = VersionId;
16-
}
5+
@Metadata("pathParam, style=simple;explode=false;name=apiEndpointID")
6+
ApiEndpointId: string;
7+
@Metadata("pathParam, style=simple;explode=false;name=apiID")
8+
ApiId: string;
9+
@Metadata("pathParam, style=simple;explode=false;name=versionID")
10+
VersionId: string;
11+
12+
constructor(ApiEndpointId: string, ApiId: string, VersionId: string) {
13+
this.ApiEndpointId = ApiEndpointId;
14+
this.ApiId = ApiId;
15+
this.VersionId = VersionId;
16+
}
1717
}
1818

1919
export class DeleteApiEndpointRequest {
20-
21-
PathParams: DeleteApiEndpointPathParams;
22-
23-
constructor(PathParams: DeleteApiEndpointPathParams) {
24-
this.PathParams = PathParams;
25-
}
20+
PathParams: DeleteApiEndpointPathParams;
21+
22+
constructor(PathParams: DeleteApiEndpointPathParams) {
23+
this.PathParams = PathParams;
24+
}
2625
}
2726

2827
export class DeleteApiEndpointResponse {
29-
30-
ContentType: string;
31-
32-
Error?: shared.Error;
33-
34-
StatusCode: number;
35-
36-
constructor(ContentType: string, StatusCode: number, Error?: Error) {
37-
this.ContentType = ContentType;
38-
this.Error = Error;
39-
this.StatusCode = StatusCode;
40-
}
41-
}
28+
ContentType: string;
4229

30+
Error?: shared.Error;
4331

32+
StatusCode: number;
4433

34+
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
35+
this.ContentType = ContentType;
36+
this.Error = Error;
37+
this.StatusCode = StatusCode;
38+
}
39+
}
Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
import {Metadata} from "../../../internal/utils/utils";
1+
import { Metadata } from "../../../internal/utils/utils";
22
import * as shared from "../shared";
33

44
export class DeleteSchemaPathParams {
5-
@Metadata("pathParam, style=simple;explode=false;name=apiID")
6-
ApiId: string;
7-
@Metadata("pathParam, style=simple;explode=false;name=revisionID")
8-
RevisionId: string;
9-
@Metadata("pathParam, style=simple;explode=false;name=versionID")
10-
VersionId: string;
11-
12-
constructor(ApiId: string, RevisionId: string, VersionId: string) {
13-
this.ApiId = ApiId;
14-
this.RevisionId = RevisionId;
15-
this.VersionId = VersionId;
16-
}
5+
@Metadata("pathParam, style=simple;explode=false;name=apiID")
6+
ApiId: string;
7+
@Metadata("pathParam, style=simple;explode=false;name=revisionID")
8+
RevisionId: string;
9+
@Metadata("pathParam, style=simple;explode=false;name=versionID")
10+
VersionId: string;
11+
12+
constructor(ApiId: string, RevisionId: string, VersionId: string) {
13+
this.ApiId = ApiId;
14+
this.RevisionId = RevisionId;
15+
this.VersionId = VersionId;
16+
}
1717
}
1818

1919
export class DeleteSchemaRequest {
20-
21-
PathParams: DeleteSchemaPathParams;
22-
23-
constructor(PathParams: DeleteSchemaPathParams) {
24-
this.PathParams = PathParams;
25-
}
20+
PathParams: DeleteSchemaPathParams;
21+
22+
constructor(PathParams: DeleteSchemaPathParams) {
23+
this.PathParams = PathParams;
24+
}
2625
}
2726

2827
export class DeleteSchemaResponse {
29-
30-
ContentType: string;
31-
32-
Error?: shared.Error;
33-
34-
StatusCode: number;
35-
36-
constructor(ContentType: string, StatusCode: number, Error?: Error) {
37-
this.ContentType = ContentType;
38-
this.Error = Error;
39-
this.StatusCode = StatusCode;
40-
}
41-
}
28+
ContentType: string;
4229

30+
Error?: shared.Error;
4331

32+
StatusCode: number;
4433

34+
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
35+
this.ContentType = ContentType;
36+
this.Error = Error;
37+
this.StatusCode = StatusCode;
38+
}
39+
}

0 commit comments

Comments
 (0)