Skip to content

Commit 19f0c7c

Browse files
chore(infra) - Add openapi-ts:local script for local API development (#1025)
* Add openapi-ts:local script for local API development This adds a new npm script `openapi-ts:local` that allows developers to generate TypeScript client code from a local OpenAPI gateway instance. Changes: - Add openapi-ts.config.local.ts for local gateway configuration - Add scripts/cleanup-local-openapi.ts to remove /api/eor prefix from generated URLs - Add npm script: openapi-ts:local - Update openapi-ts.config.ts with clarifying comments about production vs local usage Usage: - Production: npm run openapi-ts (existing) - Local development: npm run openapi-ts:local (new) Co-authored-by: Cursor <cursoragent@cursor.com> * fix script --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 53445e6 commit 19f0c7c

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

openapi-ts.config.local.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig, defaultPlugins } from '@hey-api/openapi-ts';
2+
3+
export default defineConfig({
4+
// Local gateway with new endpoints
5+
input: 'http://localhost:4000/api/eor/openapi',
6+
output: 'src/client',
7+
plugins: defaultPlugins,
8+
});

openapi-ts.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineConfig, defaultPlugins } from '@hey-api/openapi-ts';
22

33
export default defineConfig({
4+
// Production gateway - use npm run openapi-ts for production generation
5+
// For local gateway with new endpoints, use npm run openapi-ts:local instead
46
input: 'https://gateway.remote.com/v1/docs/openapi.json',
57
output: 'src/client',
68
plugins: defaultPlugins,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lint:workflows:fix": "zizmor --fix .github/workflows/",
1919
"format": "oxfmt",
2020
"openapi-ts": "openapi-ts && npm run format",
21+
"openapi-ts:local": "openapi-ts -f openapi-ts.config.local.ts && tsx scripts/cleanup-local-openapi.ts && npm run format",
2122
"test": "vitest",
2223
"test:coverage": "vitest --coverage",
2324
"coverage:extract": "tsx scripts/extract-coverage.ts",

scripts/cleanup-local-openapi.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { readFileSync, writeFileSync } from 'fs';
2+
import { resolve } from 'path';
3+
4+
/**
5+
* Removes /api/eor prefix from generated OpenAPI client files
6+
* This is needed when generating from local OpenAPI spec that includes the prefix
7+
*/
8+
function cleanupApiEorPrefix() {
9+
const files = [
10+
resolve(process.cwd(), 'src/client/sdk.gen.ts'),
11+
resolve(process.cwd(), 'src/client/types.gen.ts'),
12+
];
13+
14+
let totalReplacements = 0;
15+
16+
for (const filePath of files) {
17+
try {
18+
let content = readFileSync(filePath, 'utf-8');
19+
const originalContent = content;
20+
21+
// Replace /api/eor/ prefix with / (handles v1/, v2/, auth/, and any other paths)
22+
content = content.replace(/url: '\/api\/eor\//g, "url: '/");
23+
24+
if (content !== originalContent) {
25+
writeFileSync(filePath, content, 'utf-8');
26+
const fileName = filePath.split('/').pop();
27+
const replacements = (originalContent.match(/\/api\/eor\//g) || [])
28+
.length;
29+
console.log(`✓ Cleaned ${replacements} URLs in ${fileName}`);
30+
totalReplacements += replacements;
31+
}
32+
} catch (error) {
33+
console.error(`Error processing ${filePath}:`, error);
34+
process.exit(1);
35+
}
36+
}
37+
38+
if (totalReplacements > 0) {
39+
console.log(
40+
`\n✓ Successfully removed /api/eor prefix from ${totalReplacements} URLs`,
41+
);
42+
} else {
43+
console.log('\n✓ No /api/eor prefixes found');
44+
}
45+
}
46+
47+
cleanupApiEorPrefix();

0 commit comments

Comments
 (0)