nuxt-openapi-hyperfetch
| Install | |
|---|---|
npm install nuxt-openapi-hyperfetch |
|
| Latest Version: | 2.0.4 |
| Vue: | 3 |
| License: | Apache-2.0 |
| Last Updated: | May 19, 2026 |
| Links: | npm |
Nuxt-only OpenAPI generation.
Configure one module and generate a typed OpenAPI client, Nuxt composables, optional server routes, and headless connectors.
Documentation · Installation · Quick Start · Generators · Contributing
Installation
Install the module in your Nuxt project.
npm install nuxt-openapi-hyperfetch
If you use connectors, also install zod:
npm install zod
Peer dependencies:
- Nuxt 3 or 4
@nuxt/kitzodwhen usingconnectors
What It Generates
The module uses an OpenAPI document as input and generates a layered output.
Base output under openapi/:
- typed SDK functions
- generated OpenAPI types
- generated client files and barrel exports
Optional higher-level layers:
useFetchcomposablesuseAsyncDatacomposablesnuxtServerNitro routes- headless CRUD connectors
Default generated root:
openapi/
index.ts
sdk.gen.ts
types.gen.ts
client.gen.ts
client/
core/
composables/
When nuxtServer is enabled, route handlers are generated outside openapi/, under server/routes/api by default.
Quick Start
Register the module and point it to your OpenAPI file.
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-openapi-hyperfetch'],
openapi: {
input: './swagger.yaml',
output: './openapi',
generators: ['useFetch', 'useAsyncData'],
enableAutoImport: true,
},
})
Then start Nuxt normally:
npm run dev
Generation runs during the Nuxt build lifecycle.
Current module defaults:
output: './openapi'generators: ['useFetch', 'useAsyncData']enableDevBuild: trueenableProductionBuild: trueenableAutoGeneration: falseenableAutoImport: true
Generated Composables
Generated names follow the OpenAPI operationId.
Example with useAsyncData:
<script setup lang="ts">
const { data: pet, error } = await useAsyncDataGetPetById({
path: {
petId: 123,
},
})
</script>
<template>
<div v-if="error">Request failed</div>
<div v-else>{{ pet?.name }}</div>
</template>
If you enable useFetch, the module also generates the parallel openapi/composables/use-fetch/ tree.
Generators
Generators are additive. Choose the smallest set that matches your app.
| Generator | Output | Use it for |
|---|---|---|
useFetch |
openapi/composables/use-fetch/ |
straightforward component-level requests |
useAsyncData |
openapi/composables/use-async-data/ |
async flows, cache keys, raw variants, connector foundation |
nuxtServer |
server/routes/api/ by default |
server-owned API access and BFF patterns |
connectors |
openapi/composables/connectors/ |
headless CRUD helpers built on top of useAsyncData |
Examples:
openapi: {
input: './swagger.yaml',
generators: ['useFetch', 'useAsyncData'],
}
openapi: {
input: './swagger.yaml',
generators: ['useAsyncData', 'connectors'],
}
openapi: {
input: './swagger.yaml',
generators: ['nuxtServer'],
serverRoutePath: 'server/routes/api',
enableBff: true,
}
Connectors
When connectors is enabled, the module generates resource-oriented headless CRUD helpers on top of useAsyncData.
const { getAll, get, create, update, del } = usePetsConnector()
Connectors are useful when your app repeatedly builds list, detail, create, update, and delete flows around the same resource model.
Base URL Configuration
Generated composables and connectors can resolve their base URL from runtimeConfig.public.apiBaseUrl.
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
public: {
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'https://api.example.com',
},
},
})
If you do not want a global fallback, you can still pass baseURL per call.
Global Headers and Callbacks
The generated runtime can integrate with two lightweight extension points:
useApiHeaders()or$getApiHeadersfor shared request headersgetGlobalApiCallbacksfor shared request lifecycle callbacks
This keeps auth and cross-cutting request behavior in your Nuxt app instead of hardcoding it into generated output.
Local Development
This repository includes a small development harness for contributor workflows:
npm run dev:generate:all
npm run dev:generate:openapi
npm run dev:generate:use-fetch
npm run dev:generate:use-async-data
These scripts are for repository development and smoke-testing generator changes.
Documentation
- Documentation site
- Getting Started
- Choosing a Generator
- Connectors
- Troubleshooting
- Contributing
Contributing
npm install
npm run build
npm run validate
If your change affects generated output, also run the relevant dev:generate:* command and inspect openapi/.
See CONTRIBUTING.md.
License
Apache-2.0. See LICENSE.
Related Packages
Generate type-safe Nuxt 3 & 4 composables from OpenAPI schemas
Auto-generated composables for any API, typed from OpenAPI and never exposing yo...
Strongly-typed fetch client for Nuxt 3/4 with interceptors, retry/backoff, and a...
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 2.0.4 | ^3.0 | Apache-2.0 | |
| 2.0.2 | ^3.0 | Apache-2.0 | |
| 2.0.1 | ^3.0 | Apache-2.0 | |
| 2.0.0 | ^3.0 | Apache-2.0 | |
| 1.0.4 | ^3.0 | Apache-2.0 | |
| 1.0.3 | ^3.0 | Apache-2.0 | |
| 1.0.2 | ^3.0 | Apache-2.0 | |
| 1.0.1 | ^3.0 | Apache-2.0 | |
| 1.0.0 | ^3.0 | Apache-2.0 |
Pre-releases (19)
| Version | Released | Vue | License |
|---|---|---|---|
| 0.3.81-beta | ^3.0 | Apache-2.0 | |
| 0.3.8-beta | ^3.0 | Apache-2.0 | |
| 0.3.7-beta | ^3.0 | Apache-2.0 | |
| 0.3.6-beta | ^3.0 | Apache-2.0 | |
| 0.3.5-beta | ^3.0 | Apache-2.0 | |
| 0.3.4-beta | ^3.0 | Apache-2.0 | |
| 0.3.3-beta | ^3.0 | Apache-2.0 | |
| 0.3.2-beta | ^3.0 | Apache-2.0 | |
| 0.3.1-beta | ^3.0 | Apache-2.0 | |
| 0.3.0-beta | ^3.0 | Apache-2.0 | |
| 0.2.8-alpha.1 | ^3.0 | Apache-2.0 | |
| 0.2.7-alpha.1 | ^3.0 | Apache-2.0 | |
| 0.1.8-alpha.1 | ^3.0 | Apache-2.0 | |
| 0.1.7-alpha.1 | Apache-2.0 | ||
| 0.1.6-alpha.1 | Apache-2.0 | ||
| 0.1.5-alpha.1 | Apache-2.0 | ||
| 0.1.4-alpha.1 | Apache-2.0 | ||
| 0.1.2-alpha.1 | Apache-2.0 | ||
| 0.1.0-alpha.1 | Apache-2.0 |