Skip to content

Commit 619c784

Browse files
fix: changes har request format for snippets API some more
1 parent 29ec6b7 commit 619c784

File tree

8 files changed

+110
-130
lines changed

8 files changed

+110
-130
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 15
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-5ca77894755b023e347be818cea03fc11810d3de5df5167772a7ab44111d9413.yml
3-
openapi_spec_hash: e1df8ec98c9bcc6d93c9bafa8ff79d29
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-332dd93ce7473cdf7114d71d7dcaf7a4acc1491717c5cd55fbf984475d92bad7.yml
3+
openapi_spec_hash: 15cea3398093ddc80c926606aa31d41a
44
config_hash: 4cc7a55bc88549c1b7d1e960fa207961

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ const client = new Stainless({
3030
apiKey: process.env['STAINLESS_V0_API_KEY'], // This is the default and can be omitted
3131
});
3232

33-
const buildObject = await client.builds.create({ revision: 'string' });
33+
async function main() {
34+
const buildObject = await client.builds.create({ revision: 'string' });
3435

35-
console.log(buildObject.id);
36+
console.log(buildObject.id);
37+
}
38+
39+
main();
3640
```
3741

3842
### Request & Response types
@@ -48,8 +52,12 @@ const client = new Stainless({
4852
apiKey: process.env['STAINLESS_V0_API_KEY'], // This is the default and can be omitted
4953
});
5054

51-
const params: Stainless.BuildCreateParams = { revision: 'string' };
52-
const buildObject: Stainless.BuildObject = await client.builds.create(params);
55+
async function main() {
56+
const params: Stainless.BuildCreateParams = { revision: 'string' };
57+
const buildObject: Stainless.BuildObject = await client.builds.create(params);
58+
}
59+
60+
main();
5361
```
5462

5563
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -62,15 +70,19 @@ a subclass of `APIError` will be thrown:
6270

6371
<!-- prettier-ignore -->
6472
```ts
65-
const buildObject = await client.builds.create({ revision: 'string' }).catch(async (err) => {
66-
if (err instanceof Stainless.APIError) {
67-
console.log(err.status); // 400
68-
console.log(err.name); // BadRequestError
69-
console.log(err.headers); // {server: 'nginx', ...}
70-
} else {
71-
throw err;
72-
}
73-
});
73+
async function main() {
74+
const buildObject = await client.builds.create({ revision: 'string' }).catch(async (err) => {
75+
if (err instanceof Stainless.APIError) {
76+
console.log(err.status); // 400
77+
console.log(err.name); // BadRequestError
78+
console.log(err.headers); // {server: 'nginx', ...}
79+
} else {
80+
throw err;
81+
}
82+
});
83+
}
84+
85+
main();
7486
```
7587

7688
Error codes are as follows:

scripts/build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ npm exec tsc-multi
3737
# when building .mjs
3838
node scripts/utils/fix-index-exports.cjs
3939
cp tsconfig.dist-src.json dist/src/tsconfig.json
40+
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.ts
41+
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.mts
4042

4143
node scripts/utils/postprocess-files.cjs
4244

src/internal/shim-types.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
/**
4+
* Shims for types that we can't always rely on being available globally.
5+
*
6+
* Note: these only exist at the type-level, there is no corresponding runtime
7+
* version for any of these symbols.
8+
*/
9+
10+
/**
11+
* In order to properly access the global `NodeJS` type, if it's available, we
12+
* need to make use of declaration shadowing. Without this, any checks for the
13+
* presence of `NodeJS.ReadableStream` will fail.
14+
*/
15+
declare namespace NodeJS {
16+
interface ReadableStream {}
17+
}
18+
19+
type HasProperties<T> = keyof T extends never ? false : true;
20+
21+
// @ts-ignore
22+
type _ReadableStream<R = any> =
23+
// @ts-ignore
24+
HasProperties<NodeJS.ReadableStream> extends true ? NodeJS.ReadableStream<R> : ReadableStream<R>;
25+
26+
// @ts-ignore
27+
declare const _ReadableStream: unknown extends typeof ReadableStream ? never : typeof ReadableStream;
28+
export { _ReadableStream as ReadableStream };

src/internal/shim-types.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/internal/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* messages in cases where an environment isn't fully supported.
88
*/
99

10-
import type { Fetch } from './builtin-types';
11-
import type { ReadableStream } from './shim-types';
10+
import { type Fetch } from './builtin-types';
11+
import { type ReadableStream } from './shim-types';
1212

1313
export function getDefaultFetch(): Fetch {
1414
if (typeof fetch !== 'undefined') {

src/resources/projects/snippets.ts

Lines changed: 48 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,110 +19,73 @@ export interface SnippetCreateRequestResponse {
1919
snippet: string;
2020
}
2121

22-
export type SnippetCreateRequestParams =
23-
| SnippetCreateRequestParams.Variant0
24-
| SnippetCreateRequestParams.Variant1;
25-
26-
export declare namespace SnippetCreateRequestParams {
27-
export interface Variant0 {
28-
request: Variant0.Request;
29-
30-
har?: null;
31-
32-
language?:
33-
| 'node'
34-
| 'typescript'
35-
| 'python'
36-
| 'go'
37-
| 'java'
38-
| 'kotlin'
39-
| 'ruby'
40-
| 'terraform'
41-
| 'cli'
42-
| 'php'
43-
| 'csharp';
44-
45-
version?: 'next' | 'latest_released';
46-
}
47-
48-
export namespace Variant0 {
49-
export interface Request {
50-
method: string;
51-
52-
parameters: Array<Request.Parameter>;
22+
export interface SnippetCreateRequestParams {
23+
language:
24+
| 'node'
25+
| 'typescript'
26+
| 'python'
27+
| 'go'
28+
| 'java'
29+
| 'kotlin'
30+
| 'ruby'
31+
| 'terraform'
32+
| 'cli'
33+
| 'php'
34+
| 'csharp';
35+
36+
request: SnippetCreateRequestParams.UnionMember0 | SnippetCreateRequestParams.UnionMember1;
37+
38+
version: 'next' | 'latest_released';
39+
}
5340

54-
path: string;
41+
export namespace SnippetCreateRequestParams {
42+
export interface UnionMember0 {
43+
method: string;
5544

56-
body?: Request.Body;
57-
}
45+
parameters: Array<UnionMember0.Parameter>;
5846

59-
export namespace Request {
60-
export interface Parameter {
61-
in: 'path' | 'query' | 'header' | 'cookie';
47+
path: string;
6248

63-
name: string;
49+
body?: UnionMember0.Body;
50+
}
6451

65-
value?: unknown;
66-
}
52+
export namespace UnionMember0 {
53+
export interface Parameter {
54+
in: 'path' | 'query' | 'header' | 'cookie';
6755

68-
export interface Body {
69-
fileParam?: string;
56+
name: string;
7057

71-
filePath?: string;
72-
}
58+
value?: unknown;
7359
}
74-
}
7560

76-
export interface Variant1 {
77-
har: Variant1.Har;
78-
79-
language?:
80-
| 'node'
81-
| 'typescript'
82-
| 'python'
83-
| 'go'
84-
| 'java'
85-
| 'kotlin'
86-
| 'ruby'
87-
| 'terraform'
88-
| 'cli'
89-
| 'php'
90-
| 'csharp';
91-
92-
request?: null;
93-
94-
version?: 'next' | 'latest_released';
95-
}
61+
export interface Body {
62+
fileParam?: string;
9663

97-
export namespace Variant1 {
98-
export interface Har {
99-
request: Har.Request;
64+
filePath?: string;
10065
}
66+
}
10167

102-
export namespace Har {
103-
export interface Request {
104-
method: string;
68+
export interface UnionMember1 {
69+
method: string;
10570

106-
queryString: Array<Request.QueryString>;
71+
queryString: Array<UnionMember1.QueryString>;
10772

108-
url: string;
73+
url: string;
10974

110-
postData?: Request.PostData;
111-
}
75+
postData?: UnionMember1.PostData;
76+
}
11277

113-
export namespace Request {
114-
export interface QueryString {
115-
name: string;
78+
export namespace UnionMember1 {
79+
export interface QueryString {
80+
name: string;
11681

117-
value: string;
118-
}
82+
value: string;
83+
}
11984

120-
export interface PostData {
121-
mimeType: string;
85+
export interface PostData {
86+
mimeType: string;
12287

123-
text: string;
124-
}
125-
}
88+
text: string;
12689
}
12790
}
12891
}

tests/api-resources/projects/snippets.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ describe('resource snippets', () => {
1212
// skipped: tests are disabled for the time being
1313
test.skip('createRequest: only required params', async () => {
1414
const responsePromise = client.projects.snippets.createRequest('projectName', {
15+
language: 'node',
1516
request: { method: 'method', parameters: [{ in: 'path', name: 'name' }], path: 'path' },
17+
version: 'next',
1618
});
1719
const rawResponse = await responsePromise.asResponse();
1820
expect(rawResponse).toBeInstanceOf(Response);
@@ -26,14 +28,13 @@ describe('resource snippets', () => {
2628
// skipped: tests are disabled for the time being
2729
test.skip('createRequest: required and optional params', async () => {
2830
const response = await client.projects.snippets.createRequest('projectName', {
31+
language: 'node',
2932
request: {
3033
method: 'method',
3134
parameters: [{ in: 'path', name: 'name', value: {} }],
3235
path: 'path',
3336
body: { fileParam: 'fileParam', filePath: 'filePath' },
3437
},
35-
har: null,
36-
language: 'node',
3738
version: 'next',
3839
});
3940
});

0 commit comments

Comments
 (0)