Skip to content

Commit 4eeec46

Browse files
authored
fix(openapi): use new Nitro 2.10 format (#365)
1 parent 1d4b112 commit 4eeec46

File tree

7 files changed

+1530
-2657
lines changed

7 files changed

+1530
-2657
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"std-env": "^3.7.0",
5656
"ufo": "^1.5.4",
5757
"uncrypto": "^0.1.3",
58-
"unstorage": "^1.12.0",
58+
"unstorage": "^1.13.1",
5959
"zod": "^3.23.8"
6060
},
6161
"devDependencies": {
@@ -65,13 +65,13 @@
6565
"@nuxt/schema": "^3.13.2",
6666
"@nuxt/test-utils": "^3.14.4",
6767
"@nuxthub/core": "link:",
68-
"@types/node": "^22.8.4",
68+
"@types/node": "^22.8.7",
6969
"changelogen": "^0.5.7",
70-
"eslint": "^9.13.0",
70+
"eslint": "^9.14.0",
7171
"nuxt": "^3.13.2",
7272
"typescript": "^5.6.3",
7373
"vitest": "^2.1.4",
74-
"wrangler": "^3.83.0"
74+
"wrangler": "^3.84.1"
7575
},
7676
"packageManager": "[email protected]"
7777
}

playground/nuxt.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export default defineNuxtConfig({
2525

2626
compatibilityDate: '2024-08-08',
2727

28+
nitro: {
29+
experimental: {
30+
openAPI: true
31+
}
32+
},
33+
2834
hub: {
2935
ai: true,
3036
database: true,

pnpm-lock.yaml

Lines changed: 1507 additions & 2627 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/features.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface HubConfig {
5858
}
5959

6060
migrationsPath?: string
61+
openAPIRoute?: string
6162
}
6263

6364
export function setupBase(nuxt: Nuxt, hub: HubConfig) {
@@ -237,12 +238,15 @@ export function vectorizeRemoteCheck(hub: HubConfig) {
237238
}
238239
}
239240

240-
export function setupOpenAPI(nuxt: Nuxt) {
241-
// Fallback to custom placeholder when openAPI is disabled
242-
nuxt.options.alias['#hub/openapi'] = nuxt.options.nitro?.experimental?.openAPI === true
243-
? 'nitropack/runtime/routes/openapi'
244-
: resolve('./runtime/openapi/server/templates/openapi')
245-
241+
export function setupOpenAPI(nuxt: Nuxt, hub: HubConfig) {
242+
nuxt.options.nitro ||= {}
243+
nuxt.options.nitro.openAPI ||= {}
244+
nuxt.options.nitro.openAPI.production ||= 'runtime'
245+
nuxt.options.nitro.openAPI.route ||= '/api/_hub/openapi.json'
246+
nuxt.options.nitro.openAPI.ui ||= {}
247+
nuxt.options.nitro.openAPI.ui.scalar ||= false
248+
nuxt.options.nitro.openAPI.ui.swagger ||= false
249+
hub.openAPIRoute = nuxt.options.nitro.openAPI.route
246250
addServerScanDir(resolve('./runtime/openapi/server'))
247251
}
248252

src/module.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default defineNuxtModule<ModuleOptions>({
6767
// Extra bindings for the project
6868
bindings: {
6969
hyperdrive: {},
70-
// @ts-expect-error nitro.cloudflare.wrangler is not yet typed
7170
compatibilityFlags: nuxt.options.nitro.cloudflare?.wrangler?.compatibility_flags
7271
},
7372
// Cloudflare Access
@@ -79,12 +78,9 @@ export default defineNuxtModule<ModuleOptions>({
7978
runtimeConfig.hub = hub
8079
runtimeConfig.public.hub = {}
8180
// Make sure to tell Nitro to not generate the wrangler.toml file
82-
// @ts-expect-error nitro.cloudflare.wrangler is not yet typed
8381
delete nuxt.options.nitro.cloudflare?.wrangler?.compatibility_flags
84-
// @ts-expect-error nitro.cloudflare.wrangler is not yet typed
8582
if (nuxt.options.nitro.cloudflare?.wrangler && Object.keys(nuxt.options.nitro.cloudflare.wrangler).length) {
8683
log.warn('The `nitro.cloudflare.wrangler` defined options are not supported by NuxtHub, ignoring...')
87-
// @ts-expect-error nitro.cloudflare.wrangler is not yet typed
8884
nuxt.options.nitro.cloudflare.wrangler = {}
8985
}
9086
// validate remote option
@@ -107,7 +103,7 @@ export default defineNuxtModule<ModuleOptions>({
107103
}
108104

109105
setupBase(nuxt, hub as HubConfig)
110-
setupOpenAPI(nuxt)
106+
hub.openapi && setupOpenAPI(nuxt, hub as HubConfig)
111107
hub.ai && await setupAI(nuxt, hub as HubConfig)
112108
hub.analytics && setupAnalytics(nuxt)
113109
hub.blob && setupBlob(nuxt)

src/runtime/openapi/server/api/_hub/openapi.get.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { eventHandler, createError, type H3Event } from 'h3'
22
import { requireNuxtHubAuthorization } from '../../../../utils/auth'
33
import { useRuntimeConfig } from '#imports'
44

5-
export default eventHandler(async (event) => {
5+
export default eventHandler(async (event: H3Event) => {
66
await requireNuxtHubAuthorization(event)
77
const hub = useRuntimeConfig().hub
88

@@ -13,17 +13,5 @@ export default eventHandler(async (event) => {
1313
})
1414
}
1515

16-
// @ts-expect-error #hub/openapi has no exported types
17-
const openapi: (event: H3Event) => any = await import('#hub/openapi')
18-
.then(mod => mod.default)
19-
.catch(() => undefined)
20-
21-
if (typeof openapi !== 'function') {
22-
throw createError({
23-
statusCode: 404,
24-
message: 'not found'
25-
})
26-
}
27-
28-
return openapi(event)
16+
return $fetch(hub.openAPIRoute).catch(() => ({}))
2917
})

src/runtime/openapi/server/templates/openapi.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)