Skip to content

Commit 19ff245

Browse files
Update README.md
1 parent 6bb0fe5 commit 19ff245

File tree

1 file changed

+10
-119
lines changed

1 file changed

+10
-119
lines changed

README.md

Lines changed: 10 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ const sdk = new SDK({
9292
},
9393
});
9494

95+
const fileBuffer = await fs.readFile("openapi.json");
96+
const fileContent = new Uint8Array(fileBuffer);
97+
9598
async function run() {
9699
const result = await sdk.codesamples.preview({
97100
languages: ["python", "typescript"],
@@ -108,38 +111,6 @@ run();
108111

109112
```
110113

111-
<!-- Start SDK Example Usage [usage] -->
112-
## SDK Example Usage
113-
114-
### Example
115-
116-
```typescript
117-
import { SDK } from "@speakeasyapi/code-samples";
118-
import { openAsBlob } from "node:fs";
119-
120-
const sdk = new SDK({
121-
security: {
122-
apiKey: "<YOUR_API_KEY_HERE>",
123-
},
124-
});
125-
126-
async function run() {
127-
const result = await sdk.codesamples.preview({
128-
languages: [
129-
"<value>",
130-
],
131-
schemaFile: await openAsBlob("example.file"),
132-
});
133-
134-
// Handle the result
135-
console.log(result);
136-
}
137-
138-
run();
139-
140-
```
141-
<!-- End SDK Example Usage [usage] -->
142-
143114
<!-- Start Available Resources and Operations [operations] -->
144115
## Available Resources and Operations
145116

@@ -178,7 +149,6 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
178149
</details>
179150
<!-- End Standalone functions [standalone-funcs] -->
180151

181-
<!-- Start File uploads [file-upload] -->
182152
## File uploads
183153

184154
Certain SDK methods accept files as part of a multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
@@ -194,111 +164,32 @@ Certain SDK methods accept files as part of a multi-part request. It is possible
194164
195165
```typescript
196166
import { SDK } from "@speakeasyapi/code-samples";
197-
import { openAsBlob } from "node:fs";
167+
import { promises as fs } from "fs"
198168

199169
const sdk = new SDK({
200170
security: {
201171
apiKey: "<YOUR_API_KEY_HERE>",
202172
},
203173
});
204174

205-
async function run() {
206-
const result = await sdk.codesamples.preview({
207-
languages: [
208-
"<value>",
209-
],
210-
schemaFile: await openAsBlob("example.file"),
211-
});
212-
213-
// Handle the result
214-
console.log(result);
215-
}
216-
217-
run();
218-
219-
```
220-
<!-- End File uploads [file-upload] -->
221-
222-
<!-- Start Retries [retries] -->
223-
## Retries
224-
225-
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
226-
227-
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
228-
```typescript
229-
import { SDK } from "@speakeasyapi/code-samples";
230-
import { openAsBlob } from "node:fs";
231-
232-
const sdk = new SDK({
233-
security: {
234-
apiKey: "<YOUR_API_KEY_HERE>",
235-
},
236-
});
175+
const fileBuffer = await fs.readFile("openapi.json");
176+
const fileContent = new Uint8Array(fileBuffer);
237177

238178
async function run() {
239179
const result = await sdk.codesamples.preview({
240-
languages: [
241-
"<value>",
242-
],
243-
schemaFile: await openAsBlob("example.file"),
244-
}, {
245-
retries: {
246-
strategy: "backoff",
247-
backoff: {
248-
initialInterval: 1,
249-
maxInterval: 50,
250-
exponent: 1.1,
251-
maxElapsedTime: 100,
252-
},
253-
retryConnectionErrors: false,
254-
},
255-
});
256-
257-
// Handle the result
258-
console.log(result);
259-
}
260-
261-
run();
262-
263-
```
264-
265-
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
266-
```typescript
267-
import { SDK } from "@speakeasyapi/code-samples";
268-
import { openAsBlob } from "node:fs";
269-
270-
const sdk = new SDK({
271-
retryConfig: {
272-
strategy: "backoff",
273-
backoff: {
274-
initialInterval: 1,
275-
maxInterval: 50,
276-
exponent: 1.1,
277-
maxElapsedTime: 100,
180+
languages: ["python", "typescript"],
181+
schemaFile: {
182+
fileName: "openapi.json", // ensure file name is included
183+
content: fileContent,
278184
},
279-
retryConnectionErrors: false,
280-
},
281-
security: {
282-
apiKey: "<YOUR_API_KEY_HERE>",
283-
},
284-
});
285-
286-
async function run() {
287-
const result = await sdk.codesamples.preview({
288-
languages: [
289-
"<value>",
290-
],
291-
schemaFile: await openAsBlob("example.file"),
292185
});
293-
294186
// Handle the result
295187
console.log(result);
296188
}
297189

298190
run();
299191

300192
```
301-
<!-- End Retries [retries] -->
302193

303194
<!-- Start Error Handling [errors] -->
304195
## Error Handling

0 commit comments

Comments
 (0)