Skip to content

Commit 29f81f6

Browse files
committed
chore: now it works
1 parent 5e7cc20 commit 29f81f6

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

dist/index.js

Lines changed: 11 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs'
2+
import path from 'node:path'
23

34
/**
45
* Read and upload the provided OpenAPI specification to Hey API.
@@ -24,39 +25,23 @@ export async function upload({
2425
throw new Error('invalid OpenAPI path')
2526
}
2627

27-
let data: Buffer
28-
try {
29-
data = fs.readFileSync(pathToOpenApi)
30-
} catch {
31-
throw new Error('invalid OpenAPI path')
32-
}
28+
const formData = new FormData();
29+
30+
formData.append('spec', new Blob([fs.readFileSync(pathToOpenApi)]), path.basename(pathToOpenApi));
3331

3432
// const formData: Record<string, string | number | boolean> = {
3533
// // github_repo: process.env.GITHUB_REPOSITORY!,
3634
// // github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
37-
// spec: data.toString(),
3835
// }
3936

40-
const formData = new FormData();
41-
42-
formData.set('spec', data.toString());
43-
4437
// if (dryRun) {
4538
// formData['dry-run'] = dryRun
4639
// }
4740

48-
// const body = Object.entries(formData)
49-
// .flatMap(
50-
// ([key, value]) =>
51-
// `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
52-
// )
53-
// .join('&')
54-
5541
const response = await fetch(`${baseUrl}/v1/specs`, {
5642
body: formData,
5743
headers: {
5844
Authorization: `Bearer ${heyApiToken}`,
59-
'Content-Type': 'multipart/form-data'
6045
},
6146
method: 'POST'
6247
})

0 commit comments

Comments
 (0)