Skip to content

Commit f800f28

Browse files
committed
chore: try with object again
1 parent c49f524 commit f800f28

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/upload.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'node:fs'
1+
import fs from 'node:fs'
22

33
/**
44
* Read and upload the provided OpenAPI specification to Hey API.
@@ -26,37 +26,37 @@ export async function upload({
2626

2727
let data: Buffer
2828
try {
29-
data = readFileSync(pathToOpenApi)
29+
data = fs.readFileSync(pathToOpenApi)
3030
} catch {
3131
throw new Error('invalid OpenAPI path')
3232
}
3333

34-
// const formData: Record<string, string | number | boolean> = {
35-
// github_repo: process.env.GITHUB_REPOSITORY!,
36-
// github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
37-
// openapi: data.toString()
38-
// }
34+
const formData: Record<string, string | number | boolean> = {
35+
// github_repo: process.env.GITHUB_REPOSITORY!,
36+
// github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
37+
spec: data.toString(),
38+
}
3939

40-
const formData = new FormData();
40+
// const formData = new FormData();
4141

42-
formData.set('spec', data.toString());
42+
// formData.set('spec', data.toString());
4343

4444
// if (dryRun) {
4545
// formData['dry-run'] = dryRun
4646
// }
4747

48-
// const body = Object.entries(formData)
49-
// .flatMap(
50-
// ([key, value]) =>
51-
// `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
52-
// )
53-
// .join('&')
48+
const body = Object.entries(formData)
49+
.flatMap(
50+
([key, value]) =>
51+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
52+
)
53+
.join('&')
5454

5555
const response = await fetch(`${baseUrl}/v1/specs`, {
56-
body: formData,
56+
body,
5757
headers: {
5858
Authorization: `Bearer ${heyApiToken}`,
59-
'Content-Type': 'multipart/form-data'
59+
// 'Content-Type': 'multipart/form-data'
6060
},
6161
method: 'POST'
6262
})

0 commit comments

Comments
 (0)