Skip to content

Commit bf1fefc

Browse files
Make generated Typescript more idiomatic
1 parent fb4326b commit bf1fefc

Some content is hidden

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

49 files changed

+992
-2163
lines changed

src/internal/utils/contenttype.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function MatchContentType(
2+
contentType: string,
3+
pattern: string
4+
): boolean {
5+
if (contentType === pattern || pattern === "*" || pattern === "*/*")
6+
return true;
7+
if (contentType === pattern) return true;
8+
const parts: string[] = contentType.split("/");
9+
if (parts.length === 2) {
10+
if (`${parts[0]}/*` === pattern || `*/${parts[1]}` === pattern) return true;
11+
}
12+
return false;
13+
}

src/internal/utils/queryparams.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ export const qpMetadataKey = "queryParam";
66

77
export function GetQueryParamSerializer(
88
queryParams: any
9-
): ParamsSerializerOptions | undefined {
10-
if (queryParams == null) return undefined;
9+
): ParamsSerializerOptions {
10+
if (queryParams == null) return { encode: FormSerializerExplode };
1111
const fieldNames: string[] = Object.getOwnPropertyNames(queryParams);
1212
fieldNames.forEach((fname) => {
1313
const qpAnn: string = Reflect.getMetadata(
1414
qpMetadataKey,
1515
queryParams,
1616
fname
1717
);
18-
if (qpAnn == null) return;
18+
if (qpAnn == null) return { encode: (params: unknown) => "" };
1919
const qpDecorator: ParamDecorator = ParseQueryParamDecorator(qpAnn, fname);
2020
if (qpDecorator == null) return;
21-
if (qpDecorator.Serialization === "json") return null;
21+
if (qpDecorator.Serialization === "json")
22+
return {
23+
encode: (params: unknown) => {
24+
return JSON.stringify(params);
25+
},
26+
};
2227
else {
2328
switch (qpDecorator.Style) {
2429
case "deepObject":
@@ -43,7 +48,7 @@ export function GetQueryParamSerializer(
4348
}
4449
}
4550
});
46-
return undefined;
51+
return { encode: FormSerializerExplode };
4752
}
4853

4954
function FormSerializer(params: unknown): string {

src/sdk/models/operations/deleteapi.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ export class DeleteApiPathParams {
66
ApiId: string;
77
@Metadata("pathParam, style=simple;explode=false;name=versionID")
88
VersionId: string;
9-
10-
constructor(ApiId: string, VersionId: string) {
11-
this.ApiId = ApiId;
12-
this.VersionId = VersionId;
13-
}
149
}
1510

1611
export class DeleteApiRequest {
1712
PathParams: DeleteApiPathParams;
18-
19-
constructor(PathParams: DeleteApiPathParams) {
20-
this.PathParams = PathParams;
21-
}
2213
}
2314

2415
export class DeleteApiResponse {
@@ -27,10 +18,4 @@ export class DeleteApiResponse {
2718
Error?: shared.Error;
2819

2920
StatusCode: number;
30-
31-
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
32-
this.ContentType = ContentType;
33-
this.Error = Error;
34-
this.StatusCode = StatusCode;
35-
}
3621
}

src/sdk/models/operations/deleteapiendpoint.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ export class DeleteApiEndpointPathParams {
88
ApiId: string;
99
@Metadata("pathParam, style=simple;explode=false;name=versionID")
1010
VersionId: string;
11-
12-
constructor(ApiEndpointId: string, ApiId: string, VersionId: string) {
13-
this.ApiEndpointId = ApiEndpointId;
14-
this.ApiId = ApiId;
15-
this.VersionId = VersionId;
16-
}
1711
}
1812

1913
export class DeleteApiEndpointRequest {
2014
PathParams: DeleteApiEndpointPathParams;
21-
22-
constructor(PathParams: DeleteApiEndpointPathParams) {
23-
this.PathParams = PathParams;
24-
}
2515
}
2616

2717
export class DeleteApiEndpointResponse {
@@ -30,10 +20,4 @@ export class DeleteApiEndpointResponse {
3020
Error?: shared.Error;
3121

3222
StatusCode: number;
33-
34-
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
35-
this.ContentType = ContentType;
36-
this.Error = Error;
37-
this.StatusCode = StatusCode;
38-
}
3923
}

src/sdk/models/operations/deleteschema.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ export class DeleteSchemaPathParams {
88
RevisionId: string;
99
@Metadata("pathParam, style=simple;explode=false;name=versionID")
1010
VersionId: string;
11-
12-
constructor(ApiId: string, RevisionId: string, VersionId: string) {
13-
this.ApiId = ApiId;
14-
this.RevisionId = RevisionId;
15-
this.VersionId = VersionId;
16-
}
1711
}
1812

1913
export class DeleteSchemaRequest {
2014
PathParams: DeleteSchemaPathParams;
21-
22-
constructor(PathParams: DeleteSchemaPathParams) {
23-
this.PathParams = PathParams;
24-
}
2515
}
2616

2717
export class DeleteSchemaResponse {
@@ -30,10 +20,4 @@ export class DeleteSchemaResponse {
3020
Error?: shared.Error;
3121

3222
StatusCode: number;
33-
34-
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
35-
this.ContentType = ContentType;
36-
this.Error = Error;
37-
this.StatusCode = StatusCode;
38-
}
3923
}

src/sdk/models/operations/deleteversionmetadata.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,10 @@ export class DeleteVersionMetadataPathParams {
1010
MetaValue: string;
1111
@Metadata("pathParam, style=simple;explode=false;name=versionID")
1212
VersionId: string;
13-
14-
constructor(
15-
ApiId: string,
16-
MetaKey: string,
17-
MetaValue: string,
18-
VersionId: string
19-
) {
20-
this.ApiId = ApiId;
21-
this.MetaKey = MetaKey;
22-
this.MetaValue = MetaValue;
23-
this.VersionId = VersionId;
24-
}
2513
}
2614

2715
export class DeleteVersionMetadataRequest {
2816
PathParams: DeleteVersionMetadataPathParams;
29-
30-
constructor(PathParams: DeleteVersionMetadataPathParams) {
31-
this.PathParams = PathParams;
32-
}
3317
}
3418

3519
export class DeleteVersionMetadataResponse {
@@ -38,10 +22,4 @@ export class DeleteVersionMetadataResponse {
3822
Error?: shared.Error;
3923

4024
StatusCode: number;
41-
42-
constructor(ContentType: string, StatusCode: number, Error?: shared.Error) {
43-
this.ContentType = ContentType;
44-
this.Error = Error;
45-
this.StatusCode = StatusCode;
46-
}
4725
}

src/sdk/models/operations/downloadschema.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ export class DownloadSchemaPathParams {
66
ApiId: string;
77
@Metadata("pathParam, style=simple;explode=false;name=versionID")
88
VersionId: string;
9-
10-
constructor(ApiId: string, VersionId: string) {
11-
this.ApiId = ApiId;
12-
this.VersionId = VersionId;
13-
}
149
}
1510

1611
export class DownloadSchemaRequest {
1712
PathParams: DownloadSchemaPathParams;
18-
19-
constructor(PathParams: DownloadSchemaPathParams) {
20-
this.PathParams = PathParams;
21-
}
2213
}
2314

2415
export class DownloadSchemaResponse {
@@ -29,16 +20,4 @@ export class DownloadSchemaResponse {
2920
Schema?: string;
3021

3122
StatusCode: number;
32-
33-
constructor(
34-
ContentType: string,
35-
StatusCode: number,
36-
Error?: shared.Error,
37-
Schema?: string
38-
) {
39-
this.ContentType = ContentType;
40-
this.Error = Error;
41-
this.Schema = Schema;
42-
this.StatusCode = StatusCode;
43-
}
4423
}

src/sdk/models/operations/downloadschemarevision.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ export class DownloadSchemaRevisionPathParams {
88
RevisionId: string;
99
@Metadata("pathParam, style=simple;explode=false;name=versionID")
1010
VersionId: string;
11-
12-
constructor(ApiId: string, RevisionId: string, VersionId: string) {
13-
this.ApiId = ApiId;
14-
this.RevisionId = RevisionId;
15-
this.VersionId = VersionId;
16-
}
1711
}
1812

1913
export class DownloadSchemaRevisionRequest {
2014
PathParams: DownloadSchemaRevisionPathParams;
21-
22-
constructor(PathParams: DownloadSchemaRevisionPathParams) {
23-
this.PathParams = PathParams;
24-
}
2515
}
2616

2717
export class DownloadSchemaRevisionResponse {
@@ -32,16 +22,4 @@ export class DownloadSchemaRevisionResponse {
3222
Schema?: string;
3323

3424
StatusCode: number;
35-
36-
constructor(
37-
ContentType: string,
38-
StatusCode: number,
39-
Error?: shared.Error,
40-
Schema?: string
41-
) {
42-
this.ContentType = ContentType;
43-
this.Error = Error;
44-
this.Schema = Schema;
45-
this.StatusCode = StatusCode;
46-
}
4725
}

src/sdk/models/operations/findapiendpoint.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ export class FindApiEndpointPathParams {
88
DisplayName: string;
99
@Metadata("pathParam, style=simple;explode=false;name=versionID")
1010
VersionId: string;
11-
12-
constructor(ApiId: string, DisplayName: string, VersionId: string) {
13-
this.ApiId = ApiId;
14-
this.DisplayName = DisplayName;
15-
this.VersionId = VersionId;
16-
}
1711
}
1812

1913
export class FindApiEndpointRequest {
2014
PathParams: FindApiEndpointPathParams;
21-
22-
constructor(PathParams: FindApiEndpointPathParams) {
23-
this.PathParams = PathParams;
24-
}
2515
}
2616

2717
export class FindApiEndpointResponse {
@@ -32,16 +22,4 @@ export class FindApiEndpointResponse {
3222
Error?: shared.Error;
3323

3424
StatusCode: number;
35-
36-
constructor(
37-
ContentType: string,
38-
StatusCode: number,
39-
ApiEndpoint?: shared.ApiEndpoint,
40-
Error?: shared.Error
41-
) {
42-
this.ApiEndpoint = ApiEndpoint;
43-
this.ContentType = ContentType;
44-
this.Error = Error;
45-
this.StatusCode = StatusCode;
46-
}
4725
}

src/sdk/models/operations/generateopenapispec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ export class GenerateOpenApiSpecPathParams {
66
ApiId: string;
77
@Metadata("pathParam, style=simple;explode=false;name=versionID")
88
VersionId: string;
9-
10-
constructor(ApiId: string, VersionId: string) {
11-
this.ApiId = ApiId;
12-
this.VersionId = VersionId;
13-
}
149
}
1510

1611
export class GenerateOpenApiSpecRequest {
1712
PathParams: GenerateOpenApiSpecPathParams;
18-
19-
constructor(PathParams: GenerateOpenApiSpecPathParams) {
20-
this.PathParams = PathParams;
21-
}
2213
}
2314

2415
export class GenerateOpenApiSpecResponse {
@@ -29,16 +20,4 @@ export class GenerateOpenApiSpecResponse {
2920
GenerateOpenApiSpecDiff?: shared.GenerateOpenApiSpecDiff;
3021

3122
StatusCode: number;
32-
33-
constructor(
34-
ContentType: string,
35-
StatusCode: number,
36-
Error?: shared.Error,
37-
GenerateOpenApiSpecDiff?: shared.GenerateOpenApiSpecDiff
38-
) {
39-
this.ContentType = ContentType;
40-
this.Error = Error;
41-
this.GenerateOpenApiSpecDiff = GenerateOpenApiSpecDiff;
42-
this.StatusCode = StatusCode;
43-
}
4423
}

0 commit comments

Comments
 (0)