Skip to content

Commit 0aa8062

Browse files
Refactor OpenAPI generation script to use ES modules and update TypeScript configuration
1 parent 324f3b3 commit 0aa8062

4 files changed

Lines changed: 31 additions & 33 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"update-db": "wrangler d1 execute bars-db --remote --file schema.sql",
1111
"prettify": "prettier --write .",
1212
"build": "wrangler build",
13-
"openapi": "ts-node --esm scripts/generate-openapi.ts"
13+
"openapi": "node scripts/generate-openapi.mjs"
1414
},
1515
"devDependencies": {
1616
"@cloudflare/vitest-pool-workers": "^0.8.56",

scripts/generate-openapi.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import swaggerJsdoc from 'swagger-jsdoc';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const root = path.resolve(__dirname, '..');
10+
11+
const options = {
12+
definition: {
13+
openapi: '3.0.0',
14+
info: {
15+
title: 'BARS Core API',
16+
version: '2.0.0',
17+
description: 'API documentation for BARS Core'
18+
},
19+
servers: [
20+
{ url: 'https://v2.stopbars.com', description: 'Production' },
21+
{ url: 'http://localhost:8787', description: 'Local development (wrangler dev)' }
22+
]
23+
},
24+
apis: [path.join(root, 'src', '**', '*.ts')]
25+
};
26+
27+
const openapiSpec = swaggerJsdoc(options);
28+
fs.writeFileSync(path.join(root, 'openapi.json'), JSON.stringify(openapiSpec, null, 2));
29+
console.log('OpenAPI spec generated at openapi.json');

scripts/generate-openapi.ts

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

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
"skipLibCheck": true
3434
},
3535
"exclude": ["test"],
36-
"include": ["worker-configuration.d.ts", "src/**/*.ts", "scripts/**/*.ts"]
36+
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
3737
}

0 commit comments

Comments
 (0)