Skip to content

Commit 2d70a07

Browse files
committed
ci: regenerated with OpenAPI Doc 0.1.0, Speakeay CLI 0.15.13
1 parent d5e480c commit 2d70a07

18 files changed

+222
-145
lines changed

USAGE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!-- Start SDK Example Usage -->
2+
```typescript
3+
import { SDK, withSecurity} from "@speakeasy-api/speakeasy-client-sdk-typescript";
4+
import { GetApisRequest, GetApisResponse } from "@speakeasy-api/speakeasy-client-sdk-typescript/src/sdk/models/operations";
5+
import { AxiosError } from "axios";
6+
7+
const sdk = new SDK(withSecurity(
8+
security: {
9+
apiKey: {
10+
apiKey: "YOUR_API_KEY_HERE",
11+
},
12+
}
13+
));
14+
15+
const req: GetApisRequest = {
16+
queryParams: {
17+
metadata: {
18+
"voluptas": [
19+
"expedita",
20+
"consequuntur",
21+
],
22+
},
23+
op: {
24+
and: false,
25+
},
26+
},
27+
};
28+
29+
sdk.apis.getApis(req).then((res: GetApisResponse | AxiosError) => {
30+
// handle response
31+
});
32+
```
33+
<!-- End SDK Example Usage -->

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: 8e8183d84cace76310a3208e63cd7855
33
openapi-version: 0.1.0
4-
speakeasy-version: 0.15.9
4+
speakeasy-version: 0.15.13
55
telemetryenabled: null
66
typescript:
77
author: Speakeasy
88
packagename: '@speakeasy-api/speakeasy-client-sdk-typescript'
9-
version: 0.5.4
9+
version: 0.5.5

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@speakeasy-api/speakeasy-client-sdk-typescript",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"author": "Speakeasy",
55
"scripts": {
66
"lint:fix": "tsc --noemit && eslint \"./src\" --ext .ts,.tsx --fix",

src/internal/utils/headers.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
22

33
import { ParamDecorator } from "./pathparams";
44
import { parseParamDecorator } from "./utils";
5+
import { isStringRecord, isNumberRecord, isBooleanRecord, isEmpty } from "./utils";
56

6-
export const headerMetadataKey = "headerParam";
7+
export const headerMetadataKey = "header";
78

89
export function getHeadersFromRequest(headerParams: any): any {
910
if (headerParams == null) return;
10-
const headers: any = {};
11+
let headers: any = {};
1112
const fieldNames: string[] = Object.getOwnPropertyNames(headerParams);
1213
fieldNames.forEach((fname) => {
1314
const headerAnn: string = Reflect.getMetadata(
@@ -45,16 +46,33 @@ function serializeHeader(header: any, explode: boolean): string {
4546
header.forEach((val: any) => {
4647
headerVals.push(String(val));
4748
});
48-
} else if (header instanceof Map) {
49-
header.forEach((headerVal, headerKey) => {
50-
if (explode) headerVals.push(`${headerKey}=${headerVal}`);
51-
else headerVals.push(`${headerKey},${headerVal}`);
52-
});
53-
} else if (header instanceof Object) {
49+
} else if (isStringRecord(header) || isNumberRecord(header) || isBooleanRecord(header)) {
5450
Object.getOwnPropertyNames(header).forEach((headerKey: string) => {
5551
if (explode) headerVals.push(`${headerKey}=${header[headerKey]}`);
5652
else headerVals.push(`${headerKey},${header[headerKey]}`);
5753
});
54+
} else if (header instanceof Object) {
55+
Object.getOwnPropertyNames(header).forEach((headerKey: string) => {
56+
const headerAnn: string = Reflect.getMetadata(
57+
headerMetadataKey,
58+
header,
59+
headerKey
60+
);
61+
if (headerAnn == null) return;
62+
const headerDecorator: ParamDecorator = parseParamDecorator(
63+
headerAnn,
64+
headerKey,
65+
"simple",
66+
explode
67+
);
68+
if (headerDecorator == null) return;
69+
70+
const headerFieldValue = header[headerKey];
71+
if (isEmpty(headerFieldValue)) return;
72+
else if (explode)
73+
headerVals.push(`${headerDecorator.ParamName}=${headerFieldValue}`);
74+
else headerVals.push(`${headerDecorator.ParamName},${headerFieldValue}`);
75+
});
5876
} else {
5977
return String(header);
6078
}

src/internal/utils/pathparams.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { parseParamDecorator } from "./utils";
2+
import { isStringRecord, isNumberRecord, isBooleanRecord, isEmpty } from "./utils";
23

34
export const ppMetadataKey = "pathParam";
45

@@ -14,29 +15,29 @@ export function getSimplePathParams(
1415
ppVals.push(String(param));
1516
});
1617
pathParams.set(paramName, ppVals.join(","));
17-
} else if (paramValue instanceof Map) {
18-
paramValue.forEach((paramVal, paramName) => {
19-
if (explode) ppVals.push(`${paramName}=${paramVal}`);
20-
else ppVals.push(`${paramName},${paramVal}`);
18+
} else if (isStringRecord(paramValue) || isNumberRecord(paramValue) || isBooleanRecord(paramValue)) {
19+
Object.getOwnPropertyNames(paramValue).forEach((paramKey: string) => {
20+
if (explode) ppVals.push(`${paramKey}=${paramValue[paramKey]}`);
21+
else ppVals.push(`${paramKey},${paramValue[paramKey]}`);
2122
});
2223
pathParams.set(paramName, ppVals.join(","));
2324
} else if (paramValue instanceof Object) {
24-
Object.getOwnPropertyNames(paramValue).forEach((paramName: string) => {
25+
Object.getOwnPropertyNames(paramValue).forEach((paramKey: string) => {
2526
const ppAnn: string = Reflect.getMetadata(
2627
ppMetadataKey,
2728
paramValue,
28-
paramName
29+
paramKey
2930
);
3031
if (ppAnn == null) return;
3132
const ppDecorator: ParamDecorator = parseParamDecorator(
3233
ppAnn,
33-
paramName,
34+
paramKey,
3435
"simple",
3536
explode
3637
);
3738
if (ppDecorator == null) return;
3839

39-
const paramFieldValue = paramValue[paramName];
40+
const paramFieldValue = paramValue[paramKey];
4041

4142
if (isEmpty(paramFieldValue)) return;
4243
else if (explode)
@@ -50,14 +51,6 @@ export function getSimplePathParams(
5051
return pathParams;
5152
}
5253

53-
function isEmpty(value: any): boolean {
54-
// check for undefined, null, and NaN
55-
let res: boolean = false;
56-
if (typeof value === "number") res = Number.isNaN(value);
57-
else if (typeof value === "string") res = value === "";
58-
return res || value == null;
59-
}
60-
6154
export class ParamDecorator {
6255
Style: string;
6356
Explode: boolean;

src/internal/utils/queryparams.ts

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,96 @@
1-
import { ParamDecorator } from "./pathparams";
2-
import { ParamsSerializerOptions } from "axios";
3-
import { parseParamDecorator } from "./utils";
1+
import {ParamDecorator} from "./pathparams";
2+
import {ParamsSerializerOptions} from "axios";
3+
import {parseParamDecorator} from "./utils";
44
import qs from "qs";
55

66
export const qpMetadataKey = "queryParam";
77

88
export function getQueryParamSerializer(
9-
queryParams: any
9+
queryParams: any
1010
): ParamsSerializerOptions {
11-
let paramsSerializer: ParamsSerializerOptions = {
12-
serialize: formSerializerExplode,
13-
};
14-
if (queryParams == null) return paramsSerializer;
15-
const fieldNames: string[] = Object.getOwnPropertyNames(queryParams);
16-
fieldNames.forEach((fname) => {
17-
const qpAnn: string = Reflect.getMetadata(
18-
qpMetadataKey,
19-
queryParams,
20-
fname
21-
);
22-
if (qpAnn == null) return { serialize: (params: any) => "" };
23-
const qpDecorator: ParamDecorator = parseParamDecorator(
24-
qpAnn,
25-
fname,
26-
"form",
27-
true
28-
);
29-
if (qpDecorator == null) return;
30-
if (qpDecorator.Serialization === "json")
31-
paramsSerializer = {
32-
serialize: (params: any) => {
33-
return JSON.stringify(params);
34-
},
35-
};
36-
else {
37-
switch (qpDecorator.Style) {
38-
case "deepObject":
39-
paramsSerializer = {
40-
serialize: (params: any) => {
41-
return qs.stringify(params);
42-
},
43-
};
44-
break;
45-
case "form":
46-
if (qpDecorator.Explode) {
11+
let paramsSerializer: ParamsSerializerOptions = {
12+
serialize: formSerializerExplode,
13+
};
14+
if (queryParams == null) return paramsSerializer;
15+
const fieldNames: string[] = Object.getOwnPropertyNames(queryParams);
16+
fieldNames.forEach((fname) => {
17+
const qpAnn: string = Reflect.getMetadata(
18+
qpMetadataKey,
19+
queryParams,
20+
fname
21+
);
22+
if (qpAnn == null) return {serialize: (params: any) => ""};
23+
const qpDecorator: ParamDecorator = parseParamDecorator(
24+
qpAnn,
25+
fname,
26+
"form",
27+
true
28+
);
29+
if (qpDecorator == null) return;
30+
if (qpDecorator.Serialization === "json")
4731
paramsSerializer = {
48-
serialize: formSerializerExplode,
32+
serialize: (params: any) => Object.keys(params).map(key =>
33+
`${key}=${JSON.stringify(params[key])}`
34+
).join("&"),
4935
};
50-
} else {
51-
paramsSerializer = {
52-
serialize: formSerializer,
53-
};
54-
}
55-
break;
56-
default:
57-
// go to next query parameter field, assume first implemented serializer will serialize all query parameters for this request
58-
return;
59-
}
60-
}
61-
});
62-
return paramsSerializer;
36+
else {
37+
switch (qpDecorator.Style) {
38+
case "deepObject":
39+
paramsSerializer = {
40+
serialize: (params: any) => {
41+
return qs.stringify(params);
42+
},
43+
};
44+
break;
45+
case "form":
46+
if (qpDecorator.Explode) {
47+
paramsSerializer = {
48+
serialize: formSerializerExplode,
49+
};
50+
} else {
51+
paramsSerializer = {
52+
serialize: formSerializer,
53+
};
54+
}
55+
break;
56+
default:
57+
// go to next query parameter field, assume first implemented serializer will serialize all query parameters for this request
58+
return;
59+
}
60+
}
61+
});
62+
return paramsSerializer;
6363
}
6464

6565
function formSerializer(params: any): string {
66-
const query: string[] = [];
67-
Object.entries(Object.assign({}, params)).forEach(([key, value]) => {
68-
if (value !== Object(value)) query.push(`${key}=${value}`);
69-
else if (Array.isArray(value)) {
70-
const values: string = value.join(",");
71-
query.push(`${key}=${values}`);
72-
} else if (value instanceof Map) {
73-
const values: string[] = [];
74-
value.forEach((v, k) => {
75-
values.push(`${k},${v}`);
76-
});
77-
query.push(`${key}=${values.join(",")}`);
78-
} else {
79-
const values: string = Object.entries(Object.assign({}, value))
80-
.map(([objKey, objValue]) => `${objKey},${objValue}`)
81-
.join(",");
82-
query.push(`${key}=${values}`);
83-
}
84-
});
85-
return query.join("&");
66+
const query: string[] = [];
67+
Object.entries(Object.assign({}, params)).forEach(([key, value]) => {
68+
if (value !== Object(value)) query.push(`${key}=${value}`);
69+
else if (Array.isArray(value)) {
70+
const values: string = value.join(",");
71+
query.push(`${key}=${values}`);
72+
} else {
73+
const values: string = Object.entries(Object.assign({}, value))
74+
.map(([objKey, objValue]) => `${objKey},${objValue}`)
75+
.join(",");
76+
query.push(`${key}=${values}`);
77+
}
78+
});
79+
return query.join("&");
8680
}
8781

8882
function formSerializerExplode(params: any): string {
89-
const query: string[] = [];
90-
Object.entries(Object.assign({}, params)).forEach(([key, value]) => {
91-
if (value !== Object(value)) query.push(`${key}=${value}`);
92-
else if (Array.isArray(value)) {
93-
query.push(value.map((aValue) => `${key}=${aValue}`).join("&"));
94-
} else if (value instanceof Map) {
95-
const values: string[] = [];
96-
value.forEach((v, k) => {
97-
values.push(`${k}=${v}`);
98-
});
99-
query.push(values.join("&"));
100-
} else
101-
query.push(
102-
Object.entries(Object.assign({}, value))
103-
.map(([objKey, objValue]) => `${objKey}=${objValue}`)
104-
.join("&")
105-
);
106-
});
107-
return query.join("&");
83+
const query: string[] = [];
84+
Object.entries(Object.assign({}, params)).forEach(([key, value]) => {
85+
if (value !== Object(value)) query.push(`${key}=${value}`);
86+
else if (Array.isArray(value)) {
87+
query.push(value.map((aValue) => `${key}=${aValue}`).join("&"));
88+
} else
89+
query.push(
90+
Object.entries(Object.assign({}, value))
91+
.map(([objKey, objValue]) => `${objKey}=${objValue}`)
92+
.join("&")
93+
);
94+
});
95+
return query.join("&");
10896
}

0 commit comments

Comments
 (0)