Skip to content

Commit 69795f9

Browse files
committed
fix: update service url
1 parent 4ee1b93 commit 69795f9

File tree

3 files changed

+80
-62
lines changed

3 files changed

+80
-62
lines changed

package.json

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,42 @@
22
"name": "@hey-api/upload-openapi-spec",
33
"description": "Upload your OpenAPI specification to Hey API",
44
"version": "0.0.0",
5-
"homepage": "https://heyapi.vercel.app/",
5+
"homepage": "https://heyapi.dev",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/hey-api/upload-openapi-spec.git"
99
},
1010
"bugs": {
1111
"url": "https://github.com/hey-api/upload-openapi-spec/issues"
1212
},
13+
"license": "MIT",
14+
"author": {
15+
"email": "[email protected]",
16+
"name": "Hey API",
17+
"url": "https://heyapi.dev"
18+
},
19+
"funding": "https://github.com/sponsors/hey-api",
1320
"keywords": [
14-
"openapi",
15-
"swagger",
21+
"actions",
22+
"angular",
23+
"axios",
24+
"codegen",
25+
"fetch",
1626
"generator",
17-
"typescript",
27+
"github",
28+
"http",
1829
"javascript",
19-
"codegen",
20-
"yaml",
2130
"json",
22-
"fetch",
23-
"xhr",
24-
"axios",
25-
"angular",
31+
"next",
32+
"next.js",
2633
"node",
27-
"github",
28-
"actions"
34+
"nuxt",
35+
"openapi",
36+
"rest",
37+
"swagger",
38+
"typescript",
39+
"xhr",
40+
"yaml"
2941
],
3042
"exports": {
3143
".": "./dist/index.js"
@@ -45,7 +57,6 @@
4557
"package": "npx ncc build src/index.ts -o dist --source-map --license licenses.txt",
4658
"test": "npx jest"
4759
},
48-
"license": "MIT",
4960
"jest": {
5061
"preset": "ts-jest",
5162
"verbose": true,

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export async function run(): Promise<void> {
2020

2121
core.debug(`Path to OpenAPI: ${pathToOpenApi}`)
2222
core.debug(`Upload started: ${new Date().toTimeString()}`)
23-
await upload(pathToOpenApi, heyApiToken, dryRun)
23+
await upload({
24+
dryRun,
25+
heyApiToken,
26+
pathToOpenApi,
27+
})
2428
core.debug(`Upload completed: ${new Date().toTimeString()}`)
2529
} catch (error) {
2630
if (error instanceof Error) {

src/upload.ts

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,64 @@ import { readFileSync } from 'node:fs'
22

33
/**
44
* Read and upload the provided OpenAPI specification to Hey API.
5-
* @param pathToOpenApi Path to the OpenAPI specification file.
6-
* @param heyApiToken Hey API token.
7-
* @returns {Promise<void>} Resolves after the file is uploaded.
85
*/
9-
export async function upload(
10-
pathToOpenApi: string,
11-
heyApiToken: string,
12-
dryRun?: boolean
13-
): Promise<void> {
14-
return new Promise(async resolve => {
15-
if (!pathToOpenApi) {
16-
throw new Error('invalid OpenAPI path')
17-
}
6+
export async function upload({
7+
dryRun,
8+
heyApiToken,
9+
pathToOpenApi,
10+
}: {
11+
dryRun?: boolean;
12+
/**
13+
* Hey API token.
14+
*/
15+
heyApiToken: string;
16+
/**
17+
* Path to the OpenAPI specification file.
18+
*/
19+
pathToOpenApi: string;
20+
}): Promise<void> {
21+
if (!pathToOpenApi) {
22+
throw new Error('invalid OpenAPI path')
23+
}
1824

19-
let data: Buffer
20-
try {
21-
data = readFileSync(pathToOpenApi)
22-
} catch (error) {
23-
throw new Error('invalid OpenAPI path')
24-
}
25+
let data: Buffer
26+
try {
27+
data = readFileSync(pathToOpenApi)
28+
} catch {
29+
throw new Error('invalid OpenAPI path')
30+
}
2531

26-
const formData: Record<string, string | number | boolean> = {
27-
github_repo: process.env.GITHUB_REPOSITORY!,
28-
github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
29-
openapi: data.toString()
30-
}
31-
32-
if (dryRun) {
33-
formData['dry-run'] = dryRun
34-
}
32+
const formData: Record<string, string | number | boolean> = {
33+
github_repo: process.env.GITHUB_REPOSITORY!,
34+
github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
35+
openapi: data.toString()
36+
}
3537

36-
const body = Object.entries(formData)
37-
.flatMap(
38-
([key, value]) =>
39-
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
40-
)
41-
.join('&')
38+
if (dryRun) {
39+
formData['dry-run'] = dryRun
40+
}
4241

43-
const response = await fetch(
44-
'https://platform-production-25fb.up.railway.app/api/openapi',
45-
{
46-
body,
47-
headers: {
48-
Authorization: `Bearer ${heyApiToken}`,
49-
'Content-Type': 'application/x-www-form-urlencoded'
50-
},
51-
method: 'POST'
52-
}
42+
const body = Object.entries(formData)
43+
.flatMap(
44+
([key, value]) =>
45+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
5346
)
47+
.join('&')
5448

55-
if (response.status >= 300) {
56-
const error = await response.json()
57-
throw new Error(JSON.stringify(error))
49+
const response = await fetch(
50+
'https://platform-production-25fb.up.railway.app/api/openapi',
51+
{
52+
body,
53+
headers: {
54+
Authorization: `Bearer ${heyApiToken}`,
55+
'Content-Type': 'application/x-www-form-urlencoded'
56+
},
57+
method: 'POST'
5858
}
59+
)
5960

60-
resolve()
61-
})
61+
if (response.status >= 300) {
62+
const error = await response.json()
63+
throw new Error(JSON.stringify(error))
64+
}
6265
}

0 commit comments

Comments
 (0)