nuxt-openapi-hyperfetch 0.3.81-beta → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -212
- package/dist/generators/components/connector-generator/templates.js +67 -17
- package/dist/generators/components/schema-analyzer/intent-detector.js +1 -12
- package/dist/generators/components/schema-analyzer/openapi-reader.js +10 -1
- package/dist/generators/components/schema-analyzer/resource-grouper.js +7 -0
- package/dist/generators/components/schema-analyzer/schema-field-mapper.js +1 -22
- package/dist/generators/components/schema-analyzer/types.d.ts +10 -0
- package/dist/generators/connectors/generator.d.ts +12 -0
- package/dist/generators/connectors/generator.js +115 -0
- package/dist/generators/connectors/runtime/connector-types.d.ts +147 -0
- package/dist/generators/connectors/runtime/connector-types.js +10 -0
- package/dist/generators/connectors/runtime/useCreateConnector.d.ts +26 -0
- package/dist/generators/connectors/runtime/useCreateConnector.js +156 -0
- package/dist/generators/connectors/runtime/useDeleteConnector.d.ts +30 -0
- package/dist/generators/connectors/runtime/useDeleteConnector.js +143 -0
- package/dist/generators/connectors/runtime/useGetAllConnector.d.ts +25 -0
- package/dist/generators/connectors/runtime/useGetAllConnector.js +127 -0
- package/dist/generators/connectors/runtime/useGetConnector.d.ts +15 -0
- package/dist/generators/connectors/runtime/useGetConnector.js +99 -0
- package/dist/generators/connectors/runtime/useUpdateConnector.d.ts +34 -0
- package/dist/generators/connectors/runtime/useUpdateConnector.js +211 -0
- package/dist/generators/connectors/runtime/zod-error-merger.d.ts +23 -0
- package/dist/generators/connectors/runtime/zod-error-merger.js +106 -0
- package/dist/generators/connectors/templates.d.ts +4 -0
- package/dist/generators/connectors/templates.js +376 -0
- package/dist/generators/connectors/types.d.ts +37 -0
- package/dist/generators/connectors/types.js +7 -0
- package/dist/generators/shared/runtime/useDeleteConnector.js +4 -2
- package/dist/generators/shared/runtime/useDetailConnector.d.ts +0 -1
- package/dist/generators/shared/runtime/useDetailConnector.js +9 -20
- package/dist/generators/shared/runtime/useFormConnector.js +4 -3
- package/dist/generators/use-async-data/runtime/useApiAsyncData.js +14 -5
- package/dist/generators/use-async-data/templates.js +20 -16
- package/dist/generators/use-fetch/templates.js +1 -1
- package/dist/index.js +1 -16
- package/dist/module/index.js +2 -3
- package/package.json +4 -3
- package/src/cli/prompts.ts +1 -7
- package/src/generators/components/connector-generator/templates.ts +97 -22
- package/src/generators/components/schema-analyzer/intent-detector.ts +1 -16
- package/src/generators/components/schema-analyzer/openapi-reader.ts +14 -1
- package/src/generators/components/schema-analyzer/resource-grouper.ts +9 -0
- package/src/generators/components/schema-analyzer/schema-field-mapper.ts +1 -26
- package/src/generators/components/schema-analyzer/types.ts +11 -0
- package/src/generators/connectors/generator.ts +137 -0
- package/src/generators/connectors/runtime/connector-types.ts +207 -0
- package/src/generators/connectors/runtime/useCreateConnector.ts +199 -0
- package/src/generators/connectors/runtime/useDeleteConnector.ts +179 -0
- package/src/generators/connectors/runtime/useGetAllConnector.ts +151 -0
- package/src/generators/connectors/runtime/useGetConnector.ts +120 -0
- package/src/generators/connectors/runtime/useUpdateConnector.ts +257 -0
- package/src/generators/connectors/runtime/zod-error-merger.ts +119 -0
- package/src/generators/connectors/templates.ts +481 -0
- package/src/generators/connectors/types.ts +39 -0
- package/src/generators/shared/runtime/useDeleteConnector.ts +4 -2
- package/src/generators/shared/runtime/useDetailConnector.ts +8 -19
- package/src/generators/shared/runtime/useFormConnector.ts +4 -3
- package/src/generators/use-async-data/runtime/useApiAsyncData.ts +16 -5
- package/src/generators/use-async-data/templates.ts +24 -16
- package/src/generators/use-fetch/templates.ts +1 -1
- package/src/index.ts +2 -19
- package/src/module/index.ts +2 -5
- package/docs/generated-components.md +0 -615
- package/docs/headless-composables-ui.md +0 -569
package/README.md
CHANGED
|
@@ -1,309 +1,317 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="
|
|
2
|
+
<img src="https://raw.githubusercontent.com/dmartindiaz/nuxt-openapi-hyperfetch/main/public/nuxt-openapi-hyperfetch-logo.png" alt="Nuxt OpenAPI Hyperfetch logo" width="260" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>Generate type-safe CRUD composables from your OpenAPI spec.</strong><br/>
|
|
7
|
+
One command. Full TypeScript. SSR-ready.
|
|
8
|
+
</p>
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://nuxt-openapi-hyperfetch.netlify.app/">📖 Documentation</a> ·
|
|
12
|
+
<a href="#ready-to-use-usefetch-and-useasyncdata-composables">useFetch & useAsyncData</a> ·
|
|
13
|
+
<a href="#ready-to-use-nuxt-server-routes">Nuxt Server</a> ·
|
|
14
|
+
<a href="#connectors">Headless UI Connectors</a> ·
|
|
15
|
+
<a href="#installation">Installation</a> ·
|
|
16
|
+
<a href="#quick-start">Quick Start</a>
|
|
17
|
+
</p>
|
|
10
18
|
|
|
11
19
|
---
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
---
|
|
21
|
+
## Installation
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
```bash
|
|
24
|
+
# Global CLI
|
|
25
|
+
npm install -g nuxt-openapi-hyperfetch
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- 🌐 **Global Callbacks Plugin**: Define callbacks once, apply to all requests
|
|
23
|
-
- 🛡️ **Request Interception**: Modify headers, body, and query params before sending
|
|
24
|
-
- 🎯 **Smart Data Selection**: Pick specific fields with dot notation for nested paths
|
|
25
|
-
- 🤖 **Auto Type Inference**: Transform response data with automatic TypeScript type inference
|
|
26
|
-
- ⚡ **Automatic Generation**: Single command generates all composables and server routes
|
|
27
|
-
- 💚 **100% Nuxt Native**: Generated composables use `useFetch` / `useAsyncData`; server routes use `defineEventHandler` — no third-party runtime required
|
|
28
|
-
- 📦 **Zero Runtime Dependencies**: Generated code only uses Nuxt built-ins
|
|
29
|
-
- 💡 **Developer Experience**: Interactive CLI with smart defaults
|
|
27
|
+
# Or as a Nuxt module (dev dependency)
|
|
28
|
+
npm install -D nuxt-openapi-hyperfetch
|
|
29
|
+
```
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
Two generation engines are available. The CLI will ask you to choose one when running `nxh generate`:
|
|
33
|
+
## What it does
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|--------|------|:---:|----------|
|
|
39
|
-
| **official** | [@openapitools/openapi-generator-cli](https://openapi-generator.tech/) | ❌ Requires Java 11+ | Maximum spec compatibility, enterprise projects |
|
|
40
|
-
| **heyapi** | [@hey-api/openapi-ts](https://heyapi.dev/) | ✅ Yes | Quick setup, CI/CD pipelines, Node-only environments |
|
|
35
|
+
Point it at an OpenAPI spec, pick an output folder, run one command. You get four kinds of output:
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
- **`useFetch` composables** — one per endpoint, reactive, bound to template lifecycle
|
|
38
|
+
- **`useAsyncData` composables** — SSR-compatible, awaitable, ideal for page-level data
|
|
39
|
+
- **Nuxt Server Routes** — generated proxy endpoints that keep API keys server-side
|
|
40
|
+
- **Connectors** — headless UI composables (one per resource tag) that combine list, detail, create, update, and delete into a single import — with Zod validation, modal state, reactive params, and pagination built in
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
// nxh.config.js
|
|
48
|
-
export default {
|
|
49
|
-
generator: 'openapi', // 'openapi' | 'heyapi'
|
|
50
|
-
input: './swagger.yaml',
|
|
51
|
-
output: './api',
|
|
52
|
-
};
|
|
53
|
-
```
|
|
42
|
+
All output is 100% Nuxt-native. No runtime dependencies in the generated code.
|
|
54
43
|
|
|
55
44
|
---
|
|
56
45
|
|
|
57
|
-
##
|
|
46
|
+
## Ready to use: `useFetch` and `useAsyncData` composables
|
|
58
47
|
|
|
59
|
-
|
|
48
|
+
One composable per endpoint, for when you need direct control:
|
|
60
49
|
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
yarn global add nuxt-openapi-hyperfetch
|
|
65
|
-
# or
|
|
66
|
-
pnpm add -g nuxt-openapi-hyperfetch
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Or use directly with npx:
|
|
50
|
+
```ts
|
|
51
|
+
// useFetch — reactive, bound to template lifecycle
|
|
52
|
+
const { data: pet, pending, error } = useFetchGetPetById({ petId: 123 })
|
|
70
53
|
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
// useAsyncData — SSR-compatible, awaitable
|
|
55
|
+
const { data: pets } = await useAsyncDataFindPets({ status: 'available' })
|
|
73
56
|
```
|
|
74
57
|
|
|
75
|
-
|
|
58
|
+
With callbacks and request modification:
|
|
76
59
|
|
|
77
|
-
|
|
60
|
+
```ts
|
|
61
|
+
// useFetch — onRequest receives ctx and must return modifications
|
|
62
|
+
const { data } = useFetchFindPets(
|
|
63
|
+
{ status: 'available' },
|
|
64
|
+
{
|
|
65
|
+
onRequest: (ctx) => {
|
|
66
|
+
// ctx: { url, method, headers, query, body }
|
|
67
|
+
return { headers: { 'X-Source': 'pets-page' } }
|
|
68
|
+
},
|
|
69
|
+
onSuccess: (pets) => console.log(`${pets.length} pets loaded`),
|
|
70
|
+
onError: (err) => console.error(err.message),
|
|
71
|
+
onFinish: ({ success }) => console.log('Done:', success),
|
|
72
|
+
}
|
|
73
|
+
)
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
// useAsyncData — onSuccess and onError receive a second context argument
|
|
76
|
+
const { data: pets } = await useAsyncDataFindPets(
|
|
77
|
+
{ status: 'available' },
|
|
78
|
+
{
|
|
79
|
+
onRequest: (ctx) => ({ headers: { 'X-Source': 'pets-page' } }),
|
|
80
|
+
onSuccess: (pets, ctx) => console.log(`${pets.length} from ${ctx.url}`),
|
|
81
|
+
onError: (err, ctx) => console.error(err.message, ctx.url),
|
|
82
|
+
}
|
|
83
|
+
)
|
|
85
84
|
```
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
---
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
export default defineNuxtConfig({
|
|
91
|
-
modules: ['nuxt-openapi-hyperfetch'],
|
|
88
|
+
## Ready to use: Nuxt Server Routes
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
backend: 'heyapi',
|
|
98
|
-
enableDevBuild: true,
|
|
99
|
-
enableProductionBuild: true,
|
|
100
|
-
enableAutoGeneration: false,
|
|
101
|
-
enableAutoImport: true,
|
|
102
|
-
createUseAsyncDataConnectors: false,
|
|
103
|
-
},
|
|
104
|
-
})
|
|
90
|
+
Proxy endpoints to keep API keys server-side:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Client → Nuxt Server Route (generated) → External API
|
|
105
94
|
```
|
|
106
95
|
|
|
107
|
-
|
|
96
|
+
```ts
|
|
97
|
+
// Works automatically after generation
|
|
98
|
+
const { data } = useFetch('/api/pet/123')
|
|
99
|
+
```
|
|
108
100
|
|
|
109
101
|
---
|
|
110
102
|
|
|
111
|
-
##
|
|
103
|
+
## Connectors
|
|
112
104
|
|
|
113
|
-
|
|
105
|
+
A connector exposes five sub-composables for one resource. For a `pet` tag in your spec:
|
|
114
106
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
</p>
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
nxh generate
|
|
107
|
+
```ts
|
|
108
|
+
const { getAll, get, create, update, del } = usePetsConnector()
|
|
121
109
|
```
|
|
122
110
|
|
|
123
|
-
|
|
111
|
+
### Full CRUD page in one component
|
|
124
112
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- ✅ Which composables to generate (`useFetch`, `useAsyncData`, `Nuxt server routes`)
|
|
113
|
+
```vue
|
|
114
|
+
<script setup lang="ts">
|
|
115
|
+
const { getAll, create, update, del } = usePetsConnector()
|
|
129
116
|
|
|
130
|
-
|
|
117
|
+
// Reload the list after every mutation
|
|
118
|
+
create.onSuccess(() => getAll.load())
|
|
119
|
+
update.onSuccess(() => getAll.load())
|
|
120
|
+
del.onSuccess(() => getAll.load())
|
|
121
|
+
</script>
|
|
131
122
|
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
<template>
|
|
124
|
+
<!-- List -->
|
|
125
|
+
<UTable
|
|
126
|
+
:columns="getAll.columns.value"
|
|
127
|
+
:rows="getAll.items.value"
|
|
128
|
+
:loading="getAll.loading.value"
|
|
129
|
+
>
|
|
130
|
+
<template #actions-data="{ row }">
|
|
131
|
+
<UButton @click="update.ui.open(row)">Edit</UButton>
|
|
132
|
+
<UButton color="red" @click="del.ui.open(row)">Delete</UButton>
|
|
133
|
+
</template>
|
|
134
|
+
</UTable>
|
|
135
|
+
|
|
136
|
+
<!-- Create -->
|
|
137
|
+
<UButton @click="create.ui.open()">Add pet</UButton>
|
|
138
|
+
<UModal v-model:open="create.ui.isOpen.value">
|
|
139
|
+
<UCard>
|
|
140
|
+
<UFormField label="Name" :error="create.errors.value.name?.[0]">
|
|
141
|
+
<UInput v-model="create.model.value.name" />
|
|
142
|
+
</UFormField>
|
|
143
|
+
<UFormField label="Status">
|
|
144
|
+
<USelect v-model="create.model.value.status"
|
|
145
|
+
:options="['available','pending','sold']" />
|
|
146
|
+
</UFormField>
|
|
147
|
+
<template #footer>
|
|
148
|
+
<UButton :loading="create.loading.value" @click="create.execute()">Save</UButton>
|
|
149
|
+
</template>
|
|
150
|
+
</UCard>
|
|
151
|
+
</UModal>
|
|
152
|
+
|
|
153
|
+
<!-- Edit -->
|
|
154
|
+
<UModal v-model:open="update.ui.isOpen.value">
|
|
155
|
+
<UCard>
|
|
156
|
+
<UInput v-model="update.model.value.name" />
|
|
157
|
+
<template #footer>
|
|
158
|
+
<UButton :loading="update.loading.value"
|
|
159
|
+
@click="update.execute(update.model.value.id)">Save changes</UButton>
|
|
160
|
+
</template>
|
|
161
|
+
</UCard>
|
|
162
|
+
</UModal>
|
|
163
|
+
|
|
164
|
+
<!-- Delete confirmation -->
|
|
165
|
+
<UModal v-model:open="del.ui.isOpen.value">
|
|
166
|
+
<UCard>
|
|
167
|
+
<p>Delete <strong>{{ del.staged.value?.name }}</strong>?</p>
|
|
168
|
+
<template #footer>
|
|
169
|
+
<UButton color="red" :loading="del.loading.value" @click="del.execute()">Delete</UButton>
|
|
170
|
+
<UButton variant="outline" @click="del.ui.close()">Cancel</UButton>
|
|
171
|
+
</template>
|
|
172
|
+
</UCard>
|
|
173
|
+
</UModal>
|
|
174
|
+
</template>
|
|
134
175
|
```
|
|
135
176
|
|
|
136
|
-
###
|
|
177
|
+
### What each sub-connector provides
|
|
137
178
|
|
|
138
|
-
|
|
179
|
+
| Key | Transport | What you get |
|
|
180
|
+
|---|---|---|
|
|
181
|
+
| `getAll` | `useAsyncData` | `items`, `columns`, `loading`, `error`, `pagination`, `selected`, `load()` |
|
|
182
|
+
| `get` | `$fetch` | `data`, `loading`, `error`, `load(id)`, `clear()` |
|
|
183
|
+
| `create` | `$fetch` | `model`, `errors`, `isValid`, `execute()`, `reset()`, `ui.open/close` |
|
|
184
|
+
| `update` | `$fetch` | Same as create + `load(id)`, `ui.open(row)`, `targetId` |
|
|
185
|
+
| `del` | `$fetch` | `staged`, `hasStaged`, `execute()`, `ui.open(item)/close` |
|
|
186
|
+
|
|
187
|
+
### Reactive list parameters
|
|
139
188
|
|
|
140
189
|
```ts
|
|
141
|
-
|
|
142
|
-
modules: ['nuxt-openapi-hyperfetch'],
|
|
190
|
+
const status = ref('available')
|
|
143
191
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
output: './composables/api',
|
|
147
|
-
generators: ['useFetch', 'useAsyncData', 'nuxtServer'],
|
|
148
|
-
backend: 'heyapi',
|
|
149
|
-
serverRoutePath: 'server/routes/api',
|
|
150
|
-
enableBff: false,
|
|
151
|
-
enableAutoImport: true,
|
|
152
|
-
enableAutoGeneration: true,
|
|
153
|
-
},
|
|
154
|
-
})
|
|
192
|
+
// Re-fetches automatically when status changes
|
|
193
|
+
const { getAll } = usePetsConnector(() => ({ status: status.value }))
|
|
155
194
|
```
|
|
156
195
|
|
|
157
|
-
|
|
196
|
+
### Zod validation, out of the box
|
|
158
197
|
|
|
159
|
-
|
|
160
|
-
- `output`: Directory where the generated SDK/composables are written.
|
|
161
|
-
- `generators`: Any combination of `useFetch`, `useAsyncData`, and `nuxtServer`.
|
|
162
|
-
- `backend`: `heyapi` or `official`.
|
|
163
|
-
- `enableDevBuild` / `enableProductionBuild`: Control generation before dev/build.
|
|
164
|
-
- `enableAutoGeneration`: Regenerate when the input spec changes in dev mode.
|
|
165
|
-
- `enableAutoImport`: Auto-register generated composables for Nuxt auto-imports.
|
|
166
|
-
- `createUseAsyncDataConnectors`: Generate headless connectors on top of `useAsyncData`.
|
|
167
|
-
- `serverRoutePath`: Output path for generated Nuxt server routes.
|
|
168
|
-
- `enableBff`: Enable the BFF transformer layer for server routes.
|
|
198
|
+
Schemas are generated from your OpenAPI `requestBody`. `create.execute()` validates before sending — the network call is never made if the data is invalid.
|
|
169
199
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
│ +-- StoreApi.ts
|
|
178
|
-
+-- models/
|
|
179
|
-
│ +-- Pet.ts
|
|
180
|
-
│ +-- Order.ts
|
|
181
|
-
+-- composables/
|
|
182
|
-
+-- use-fetch/
|
|
183
|
-
+-- runtime/
|
|
184
|
-
│ +-- useApiRequest.ts
|
|
185
|
-
+-- composables/
|
|
186
|
-
│ +-- useFetchGetPetById.ts
|
|
187
|
-
│ +-- useFetchAddPet.ts
|
|
188
|
-
+-- index.ts
|
|
200
|
+
```ts
|
|
201
|
+
// Extend the generated schema for extra rules
|
|
202
|
+
const { create } = usePetsConnector({}, {
|
|
203
|
+
createSchema: (base) => base.extend({
|
|
204
|
+
name: z.string().min(2, 'At least 2 characters'),
|
|
205
|
+
})
|
|
206
|
+
})
|
|
189
207
|
```
|
|
190
208
|
|
|
191
|
-
###
|
|
209
|
+
### Global callbacks
|
|
192
210
|
|
|
193
|
-
|
|
211
|
+
Register once, applies to every API call in the app:
|
|
194
212
|
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
213
|
+
```ts
|
|
214
|
+
// plugins/api-callbacks.plugin.ts
|
|
215
|
+
defineGlobalApiCallbacks([
|
|
216
|
+
{
|
|
217
|
+
onRequest: (ctx) => ({
|
|
218
|
+
headers: { Authorization: `Bearer ${useAuthStore().token}` }
|
|
219
|
+
}),
|
|
220
|
+
onError: (err) => useToast().add({ title: err.message, color: 'red' }),
|
|
201
221
|
}
|
|
202
|
-
|
|
222
|
+
])
|
|
203
223
|
```
|
|
204
224
|
|
|
205
|
-
|
|
225
|
+
Connector-level and per-operation callbacks are also available — see [Callbacks docs](./docs/connectors/callbacks.md).
|
|
206
226
|
|
|
207
|
-
|
|
208
|
-
NUXT_PUBLIC_API_BASE_URL=https://api.example.com
|
|
209
|
-
```
|
|
227
|
+
---
|
|
210
228
|
|
|
211
|
-
|
|
229
|
+
## Quick Start
|
|
212
230
|
|
|
213
|
-
###
|
|
231
|
+
### CLI
|
|
214
232
|
|
|
215
|
-
|
|
216
|
-
<
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const { data: pet, pending, error } = useFetchGetPetById(
|
|
220
|
-
{ petId: 123 },
|
|
221
|
-
{
|
|
222
|
-
onSuccess: (pet) => console.log('Loaded:', pet.name),
|
|
223
|
-
onError: (err) => console.error('Failed:', err),
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
</script>
|
|
233
|
+
<p align="center">
|
|
234
|
+
<img src="https://raw.githubusercontent.com/dmartindiaz/nuxt-openapi-hyperfetch/main/public/nuxt-openapi-hyperfetch-cli.png" alt="Nuxt OpenAPI Hyperfetch CLI" width="720" />
|
|
235
|
+
</p>
|
|
227
236
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
<div v-else-if="pet">{{ pet.name }} — {{ pet.status }}</div>
|
|
233
|
-
</div>
|
|
234
|
-
</template>
|
|
237
|
+
```bash
|
|
238
|
+
nxh generate
|
|
239
|
+
# or with arguments:
|
|
240
|
+
nxh generate -i ./swagger.yaml -o ./composables/api
|
|
235
241
|
```
|
|
236
242
|
|
|
237
|
-
|
|
243
|
+
The CLI asks for your spec path, output folder, engine (`heyapi` or `official`), and which generators to run.
|
|
238
244
|
|
|
239
|
-
|
|
245
|
+
### Nuxt module
|
|
240
246
|
|
|
241
|
-
|
|
247
|
+
```ts
|
|
248
|
+
// nuxt.config.ts
|
|
249
|
+
export default defineNuxtConfig({
|
|
250
|
+
modules: ['nuxt-openapi-hyperfetch'],
|
|
242
251
|
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
openApiHyperFetch: {
|
|
253
|
+
input: './swagger.yaml',
|
|
254
|
+
output: './composables/api',
|
|
255
|
+
generators: ['useFetch', 'useAsyncData', 'nuxtServer'],
|
|
256
|
+
backend: 'heyapi',
|
|
257
|
+
enableAutoImport: true,
|
|
258
|
+
},
|
|
259
|
+
})
|
|
245
260
|
```
|
|
246
261
|
|
|
247
|
-
|
|
262
|
+
### Configure the base URL
|
|
248
263
|
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
|
|
264
|
+
```ts
|
|
265
|
+
// nuxt.config.ts
|
|
266
|
+
runtimeConfig: {
|
|
267
|
+
public: { apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'https://api.example.com' }
|
|
268
|
+
}
|
|
252
269
|
```
|
|
253
270
|
|
|
254
|
-
|
|
271
|
+
All generated composables and connectors pick up `apiBaseUrl` automatically.
|
|
255
272
|
|
|
256
|
-
|
|
257
|
-
export default defineNuxtConfig({
|
|
258
|
-
runtimeConfig: {
|
|
259
|
-
// Private — server-side only (never exposed to the browser)
|
|
260
|
-
apiBaseUrl: process.env.API_BASE_URL || '',
|
|
261
|
-
apiSecret: process.env.API_SECRET || '',
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
```
|
|
273
|
+
---
|
|
265
274
|
|
|
266
|
-
|
|
275
|
+
## Two generation engines
|
|
267
276
|
|
|
268
|
-
|
|
277
|
+
| Engine | Requires | Best for |
|
|
278
|
+
|---|---|---|
|
|
279
|
+
| `heyapi` | Node only | Quick setup, CI/CD |
|
|
280
|
+
| `official` | Java 11+ | Maximum spec compatibility |
|
|
269
281
|
|
|
270
|
-
|
|
271
|
-
const { data: pet } = useFetch('/api/pet/123');
|
|
272
|
-
```
|
|
282
|
+
Pre-select in `nxh.config.js` to skip the prompt:
|
|
273
283
|
|
|
274
|
-
|
|
284
|
+
```js
|
|
285
|
+
export default { generator: 'heyapi', input: './swagger.yaml', output: './api' }
|
|
286
|
+
```
|
|
275
287
|
|
|
276
288
|
---
|
|
277
289
|
|
|
278
|
-
##
|
|
290
|
+
## Documentation
|
|
279
291
|
|
|
280
|
-
|
|
|
281
|
-
|
|
282
|
-
| [
|
|
283
|
-
| [
|
|
284
|
-
| [API Reference](./docs/API-REFERENCE.md) | All
|
|
285
|
-
| [
|
|
292
|
+
| | |
|
|
293
|
+
|---|---|
|
|
294
|
+
| [Connectors](./docs/connectors/index.md) | Full connector API reference and examples |
|
|
295
|
+
| [Quick Start](./docs/QUICK-START.md) | From zero to working composables in 5 minutes |
|
|
296
|
+
| [API Reference](./docs/API-REFERENCE.md) | All options and TypeScript types |
|
|
297
|
+
| [Architecture](./docs/ARCHITECTURE.md) | How the generator works internally |
|
|
286
298
|
| [Troubleshooting](./docs/TROUBLESHOOTING.md) | Common errors and solutions |
|
|
287
299
|
|
|
288
300
|
---
|
|
289
301
|
|
|
290
|
-
##
|
|
291
|
-
|
|
292
|
-
Contributions are welcome! Please read the [Contributing Guidelines](./CONTRIBUTING.md) before submitting a PR.
|
|
302
|
+
## Contributing
|
|
293
303
|
|
|
294
304
|
```bash
|
|
295
|
-
# Development setup
|
|
296
305
|
npm install
|
|
297
306
|
npm run build
|
|
298
307
|
npm run validate # lint + type check
|
|
299
308
|
```
|
|
300
309
|
|
|
301
|
-
|
|
310
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
302
311
|
|
|
303
|
-
## 📄 License
|
|
304
|
-
|
|
305
|
-
Apache-2.0 — see [LICENSE](./LICENSE) for details.
|
|
306
312
|
|
|
307
313
|
---
|
|
308
314
|
|
|
309
|
-
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
Apache-2.0 — see [LICENSE](./LICENSE) for details.
|