Skip to content

Commit 4f3e93e

Browse files
committed
🔧 fix(type generator): overrideOutputPath can be string
1 parent 36de735 commit 4f3e93e

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Bug fix:
33
- type generator: if failed, do not generate empty JSON
44
- type generator: friendly error message, and better error handling
5+
- type generator: overrideOutputPath can be string
56

67
# 1.3.7 - 3 Sep 2025
78
Improvement:

example/gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { fromTypes } from '../src/gen'
55
export const app = new Elysia()
66
.use(
77
openapi({
8-
references: fromTypes('example/gen3.ts')
8+
references: fromTypes('gen.ts', {
9+
projectRoot: import.meta.dirname,
10+
overrideOutputPath: 'example/gen.d.ts'
11+
// debug: true
12+
})
913
})
1014
)
1115
.get(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/openapi",
3-
"version": "1.3.7",
3+
"version": "1.3.8",
44
"description": "Plugin for Elysia to auto-generate API documentation",
55
"author": {
66
"name": "saltyAom",

src/gen/index.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const fromTypes =
147147
.replace(/.tsx$/, '.ts')
148148
.replace(/.ts$/, '.d.ts')
149149

150-
let targetFile =
150+
const targetFile =
151151
(overrideOutputPath
152152
? typeof overrideOutputPath === 'string'
153153
? overrideOutputPath.startsWith('/')
@@ -156,41 +156,31 @@ export const fromTypes =
156156
: overrideOutputPath(tmpRoot)
157157
: undefined) ?? join(tmpRoot, 'dist', fileName)
158158

159-
{
160-
const _targetFile = join(
161-
tmpRoot,
162-
'dist',
163-
fileName.slice(fileName.indexOf('/') + 1)
164-
)
165-
166-
if (!existsSync(_targetFile)) {
167-
rmSync(join(tmpRoot, 'tsconfig.json'))
159+
if (!existsSync(targetFile)) {
160+
rmSync(join(tmpRoot, 'tsconfig.json'))
168161

169-
console.warn(
170-
'[@elysiajs/openapi/gen] Failed to generate OpenAPI schema'
171-
)
172-
console.warn("Couldn't find generated declaration file")
173-
174-
if (existsSync(join(tmpRoot, 'dist'))) {
175-
const tempFiles = readdirSync(join(tmpRoot, 'dist'), {
176-
recursive: true
177-
})
178-
.filter((x) => x.toString().endsWith('.d.ts'))
179-
.map((x) => `- ${x}`)
180-
.join('\n')
181-
182-
if (tempFiles) {
183-
console.warn(
184-
'You can override with `overrideOutputPath` with one of the following:'
185-
)
186-
console.warn(tempFiles)
187-
}
162+
console.warn(
163+
'[@elysiajs/openapi/gen] Failed to generate OpenAPI schema'
164+
)
165+
console.warn("Couldn't find generated declaration file")
166+
167+
if (existsSync(join(tmpRoot, 'dist'))) {
168+
const tempFiles = readdirSync(join(tmpRoot, 'dist'), {
169+
recursive: true
170+
})
171+
.filter((x) => x.toString().endsWith('.d.ts'))
172+
.map((x) => `- ${x}`)
173+
.join('\n')
174+
175+
if (tempFiles) {
176+
console.warn(
177+
'You can override with `overrideOutputPath` with one of the following:'
178+
)
179+
console.warn(tempFiles)
188180
}
189-
190-
return
191181
}
192182

193-
targetFile = _targetFile
183+
return
194184
}
195185

196186
const declaration = readFileSync(targetFile, 'utf8')

0 commit comments

Comments
 (0)