nuxt-openapi-hyperfetch 0.3.81-beta → 1.0.0
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 +218 -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,315 @@
|
|
|
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="#connectors">Connectors</a> ·
|
|
13
|
+
<a href="#installation">Installation</a> ·
|
|
14
|
+
<a href="#quick-start">Quick Start</a>
|
|
15
|
+
</p>
|
|
10
16
|
|
|
11
17
|
---
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
---
|
|
19
|
+
## Installation
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
```bash
|
|
22
|
+
# Global CLI
|
|
23
|
+
npm install -g nuxt-openapi-hyperfetch
|
|
18
24
|
|
|
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
|
|
25
|
+
# Or as a Nuxt module (dev dependency)
|
|
26
|
+
npm install -D nuxt-openapi-hyperfetch
|
|
27
|
+
```
|
|
30
28
|
|
|
31
29
|
---
|
|
32
30
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
Two generation engines are available. The CLI will ask you to choose one when running `nxh generate`:
|
|
31
|
+
## What it does
|
|
36
32
|
|
|
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 |
|
|
33
|
+
Point it at an OpenAPI spec, pick an output folder, run one command. You get four kinds of output:
|
|
41
34
|
|
|
42
|
-
|
|
35
|
+
- **`useFetch` composables** — one per endpoint, reactive, bound to template lifecycle
|
|
36
|
+
- **`useAsyncData` composables** — SSR-compatible, awaitable, ideal for page-level data
|
|
37
|
+
- **Nuxt Server Routes** — generated proxy endpoints that keep API keys server-side
|
|
38
|
+
- **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
39
|
|
|
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
|
-
```
|
|
40
|
+
All output is 100% Nuxt-native. No runtime dependencies in the generated code.
|
|
54
41
|
|
|
55
42
|
---
|
|
56
43
|
|
|
57
|
-
##
|
|
44
|
+
## Also generates: `useFetch` and `useAsyncData` composables
|
|
58
45
|
|
|
59
|
-
|
|
46
|
+
One composable per endpoint, for when you need direct control:
|
|
60
47
|
|
|
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:
|
|
48
|
+
```ts
|
|
49
|
+
// useFetch — reactive, bound to template lifecycle
|
|
50
|
+
const { data: pet, pending, error } = useFetchGetPetById({ petId: 123 })
|
|
70
51
|
|
|
71
|
-
|
|
72
|
-
|
|
52
|
+
// useAsyncData — SSR-compatible, awaitable
|
|
53
|
+
const { data: pets } = await useAsyncDataFindPets({ status: 'available' })
|
|
73
54
|
```
|
|
74
55
|
|
|
75
|
-
|
|
56
|
+
With callbacks and request modification:
|
|
76
57
|
|
|
77
|
-
|
|
58
|
+
```ts
|
|
59
|
+
// useFetch — onRequest receives ctx and must return modifications
|
|
60
|
+
const { data } = useFetchFindPets(
|
|
61
|
+
{ status: 'available' },
|
|
62
|
+
{
|
|
63
|
+
onRequest: (ctx) => {
|
|
64
|
+
// ctx: { url, method, headers, query, body }
|
|
65
|
+
return { headers: { 'X-Source': 'pets-page' } }
|
|
66
|
+
},
|
|
67
|
+
onSuccess: (pets) => console.log(`${pets.length} pets loaded`),
|
|
68
|
+
onError: (err) => console.error(err.message),
|
|
69
|
+
onFinish: ({ success }) => console.log('Done:', success),
|
|
70
|
+
}
|
|
71
|
+
)
|
|
78
72
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
// useAsyncData — onSuccess and onError receive a second context argument
|
|
74
|
+
const { data: pets } = await useAsyncDataFindPets(
|
|
75
|
+
{ status: 'available' },
|
|
76
|
+
{
|
|
77
|
+
onRequest: (ctx) => ({ headers: { 'X-Source': 'pets-page' } }),
|
|
78
|
+
onSuccess: (pets, ctx) => console.log(`${pets.length} from ${ctx.url}`),
|
|
79
|
+
onError: (err, ctx) => console.error(err.message, ctx.url),
|
|
80
|
+
}
|
|
81
|
+
)
|
|
85
82
|
```
|
|
86
83
|
|
|
87
|
-
|
|
84
|
+
---
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
export default defineNuxtConfig({
|
|
91
|
-
modules: ['nuxt-openapi-hyperfetch'],
|
|
86
|
+
## Also generates: Nuxt Server Routes
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
backend: 'heyapi',
|
|
98
|
-
enableDevBuild: true,
|
|
99
|
-
enableProductionBuild: true,
|
|
100
|
-
enableAutoGeneration: false,
|
|
101
|
-
enableAutoImport: true,
|
|
102
|
-
createUseAsyncDataConnectors: false,
|
|
103
|
-
},
|
|
104
|
-
})
|
|
88
|
+
Proxy endpoints to keep API keys server-side:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Client → Nuxt Server Route (generated) → External API
|
|
105
92
|
```
|
|
106
93
|
|
|
107
|
-
|
|
94
|
+
```ts
|
|
95
|
+
// Works automatically after generation
|
|
96
|
+
const { data } = useFetch('/api/pet/123')
|
|
97
|
+
```
|
|
108
98
|
|
|
109
99
|
---
|
|
110
100
|
|
|
111
|
-
##
|
|
101
|
+
## Connectors
|
|
112
102
|
|
|
113
|
-
|
|
103
|
+
A connector exposes five sub-composables for one resource. For a `pet` tag in your spec:
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
</p>
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
nxh generate
|
|
105
|
+
```ts
|
|
106
|
+
const { getAll, get, create, update, del } = usePetsConnector()
|
|
121
107
|
```
|
|
122
108
|
|
|
123
|
-
|
|
109
|
+
### Full CRUD page in one component
|
|
124
110
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- ✅ Which composables to generate (`useFetch`, `useAsyncData`, `Nuxt server routes`)
|
|
111
|
+
```vue
|
|
112
|
+
<script setup lang="ts">
|
|
113
|
+
const { getAll, create, update, del } = usePetsConnector()
|
|
129
114
|
|
|
130
|
-
|
|
115
|
+
// Reload the list after every mutation
|
|
116
|
+
create.onSuccess(() => getAll.load())
|
|
117
|
+
update.onSuccess(() => getAll.load())
|
|
118
|
+
del.onSuccess(() => getAll.load())
|
|
119
|
+
</script>
|
|
131
120
|
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
<template>
|
|
122
|
+
<!-- List -->
|
|
123
|
+
<UTable
|
|
124
|
+
:columns="getAll.columns.value"
|
|
125
|
+
:rows="getAll.items.value"
|
|
126
|
+
:loading="getAll.loading.value"
|
|
127
|
+
>
|
|
128
|
+
<template #actions-data="{ row }">
|
|
129
|
+
<UButton @click="update.ui.open(row)">Edit</UButton>
|
|
130
|
+
<UButton color="red" @click="del.ui.open(row)">Delete</UButton>
|
|
131
|
+
</template>
|
|
132
|
+
</UTable>
|
|
133
|
+
|
|
134
|
+
<!-- Create -->
|
|
135
|
+
<UButton @click="create.ui.open()">Add pet</UButton>
|
|
136
|
+
<UModal v-model:open="create.ui.isOpen.value">
|
|
137
|
+
<UCard>
|
|
138
|
+
<UFormField label="Name" :error="create.errors.value.name?.[0]">
|
|
139
|
+
<UInput v-model="create.model.value.name" />
|
|
140
|
+
</UFormField>
|
|
141
|
+
<UFormField label="Status">
|
|
142
|
+
<USelect v-model="create.model.value.status"
|
|
143
|
+
:options="['available','pending','sold']" />
|
|
144
|
+
</UFormField>
|
|
145
|
+
<template #footer>
|
|
146
|
+
<UButton :loading="create.loading.value" @click="create.execute()">Save</UButton>
|
|
147
|
+
</template>
|
|
148
|
+
</UCard>
|
|
149
|
+
</UModal>
|
|
150
|
+
|
|
151
|
+
<!-- Edit -->
|
|
152
|
+
<UModal v-model:open="update.ui.isOpen.value">
|
|
153
|
+
<UCard>
|
|
154
|
+
<UInput v-model="update.model.value.name" />
|
|
155
|
+
<template #footer>
|
|
156
|
+
<UButton :loading="update.loading.value"
|
|
157
|
+
@click="update.execute(update.model.value.id)">Save changes</UButton>
|
|
158
|
+
</template>
|
|
159
|
+
</UCard>
|
|
160
|
+
</UModal>
|
|
161
|
+
|
|
162
|
+
<!-- Delete confirmation -->
|
|
163
|
+
<UModal v-model:open="del.ui.isOpen.value">
|
|
164
|
+
<UCard>
|
|
165
|
+
<p>Delete <strong>{{ del.staged.value?.name }}</strong>?</p>
|
|
166
|
+
<template #footer>
|
|
167
|
+
<UButton color="red" :loading="del.loading.value" @click="del.execute()">Delete</UButton>
|
|
168
|
+
<UButton variant="outline" @click="del.ui.close()">Cancel</UButton>
|
|
169
|
+
</template>
|
|
170
|
+
</UCard>
|
|
171
|
+
</UModal>
|
|
172
|
+
</template>
|
|
134
173
|
```
|
|
135
174
|
|
|
136
|
-
###
|
|
175
|
+
### What each sub-connector provides
|
|
137
176
|
|
|
138
|
-
|
|
177
|
+
| Key | Transport | What you get |
|
|
178
|
+
|---|---|---|
|
|
179
|
+
| `getAll` | `useAsyncData` | `items`, `columns`, `loading`, `error`, `pagination`, `selected`, `load()` |
|
|
180
|
+
| `get` | `$fetch` | `data`, `loading`, `error`, `load(id)`, `clear()` |
|
|
181
|
+
| `create` | `$fetch` | `model`, `errors`, `isValid`, `execute()`, `reset()`, `ui.open/close` |
|
|
182
|
+
| `update` | `$fetch` | Same as create + `load(id)`, `ui.open(row)`, `targetId` |
|
|
183
|
+
| `del` | `$fetch` | `staged`, `hasStaged`, `execute()`, `ui.open(item)/close` |
|
|
184
|
+
|
|
185
|
+
### Reactive list parameters
|
|
139
186
|
|
|
140
187
|
```ts
|
|
141
|
-
|
|
142
|
-
modules: ['nuxt-openapi-hyperfetch'],
|
|
188
|
+
const status = ref('available')
|
|
143
189
|
|
|
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
|
-
})
|
|
190
|
+
// Re-fetches automatically when status changes
|
|
191
|
+
const { getAll } = usePetsConnector(() => ({ status: status.value }))
|
|
155
192
|
```
|
|
156
193
|
|
|
157
|
-
|
|
194
|
+
### Zod validation, out of the box
|
|
158
195
|
|
|
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.
|
|
196
|
+
Schemas are generated from your OpenAPI `requestBody`. `create.execute()` validates before sending — the network call is never made if the data is invalid.
|
|
169
197
|
|
|
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
|
|
198
|
+
```ts
|
|
199
|
+
// Extend the generated schema for extra rules
|
|
200
|
+
const { create } = usePetsConnector({}, {
|
|
201
|
+
createSchema: (base) => base.extend({
|
|
202
|
+
name: z.string().min(2, 'At least 2 characters'),
|
|
203
|
+
})
|
|
204
|
+
})
|
|
189
205
|
```
|
|
190
206
|
|
|
191
|
-
###
|
|
207
|
+
### Global callbacks
|
|
192
208
|
|
|
193
|
-
|
|
209
|
+
Register once, applies to every API call in the app:
|
|
194
210
|
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
```ts
|
|
212
|
+
// plugins/api-callbacks.plugin.ts
|
|
213
|
+
defineGlobalApiCallbacks([
|
|
214
|
+
{
|
|
215
|
+
onRequest: (ctx) => ({
|
|
216
|
+
headers: { Authorization: `Bearer ${useAuthStore().token}` }
|
|
217
|
+
}),
|
|
218
|
+
onError: (err) => useToast().add({ title: err.message, color: 'red' }),
|
|
201
219
|
}
|
|
202
|
-
|
|
220
|
+
])
|
|
203
221
|
```
|
|
204
222
|
|
|
205
|
-
|
|
223
|
+
Connector-level and per-operation callbacks are also available — see [Callbacks docs](./docs/connectors/callbacks.md).
|
|
206
224
|
|
|
207
|
-
|
|
208
|
-
NUXT_PUBLIC_API_BASE_URL=https://api.example.com
|
|
209
|
-
```
|
|
225
|
+
---
|
|
210
226
|
|
|
211
|
-
|
|
227
|
+
## Quick Start
|
|
212
228
|
|
|
213
|
-
###
|
|
229
|
+
### CLI
|
|
214
230
|
|
|
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>
|
|
231
|
+
<p align="center">
|
|
232
|
+
<img src="https://raw.githubusercontent.com/dmartindiaz/nuxt-openapi-hyperfetch/main/public/nuxt-openapi-hyperfetch-cli.png" alt="Nuxt OpenAPI Hyperfetch CLI" width="720" />
|
|
233
|
+
</p>
|
|
227
234
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
<div v-else-if="pet">{{ pet.name }} — {{ pet.status }}</div>
|
|
233
|
-
</div>
|
|
234
|
-
</template>
|
|
235
|
+
```bash
|
|
236
|
+
nxh generate
|
|
237
|
+
# or with arguments:
|
|
238
|
+
nxh generate -i ./swagger.yaml -o ./composables/api
|
|
235
239
|
```
|
|
236
240
|
|
|
237
|
-
|
|
241
|
+
The CLI asks for your spec path, output folder, engine (`heyapi` or `official`), and which generators to run.
|
|
238
242
|
|
|
239
|
-
|
|
243
|
+
### Nuxt module
|
|
240
244
|
|
|
241
|
-
|
|
245
|
+
```ts
|
|
246
|
+
// nuxt.config.ts
|
|
247
|
+
export default defineNuxtConfig({
|
|
248
|
+
modules: ['nuxt-openapi-hyperfetch'],
|
|
242
249
|
|
|
243
|
-
|
|
244
|
-
|
|
250
|
+
openApiHyperFetch: {
|
|
251
|
+
input: './swagger.yaml',
|
|
252
|
+
output: './composables/api',
|
|
253
|
+
generators: ['useFetch', 'useAsyncData', 'nuxtServer'],
|
|
254
|
+
backend: 'heyapi',
|
|
255
|
+
enableAutoImport: true,
|
|
256
|
+
},
|
|
257
|
+
})
|
|
245
258
|
```
|
|
246
259
|
|
|
247
|
-
|
|
260
|
+
### Configure the base URL
|
|
248
261
|
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
```ts
|
|
263
|
+
// nuxt.config.ts
|
|
264
|
+
runtimeConfig: {
|
|
265
|
+
public: { apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'https://api.example.com' }
|
|
266
|
+
}
|
|
252
267
|
```
|
|
253
268
|
|
|
254
|
-
|
|
269
|
+
All generated composables and connectors pick up `apiBaseUrl` automatically.
|
|
255
270
|
|
|
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
|
-
```
|
|
271
|
+
---
|
|
265
272
|
|
|
266
|
-
|
|
273
|
+
## Two generation engines
|
|
267
274
|
|
|
268
|
-
|
|
275
|
+
| Engine | Requires | Best for |
|
|
276
|
+
|---|---|---|
|
|
277
|
+
| `heyapi` | Node only | Quick setup, CI/CD |
|
|
278
|
+
| `official` | Java 11+ | Maximum spec compatibility |
|
|
269
279
|
|
|
270
|
-
|
|
271
|
-
const { data: pet } = useFetch('/api/pet/123');
|
|
272
|
-
```
|
|
280
|
+
Pre-select in `nxh.config.js` to skip the prompt:
|
|
273
281
|
|
|
274
|
-
|
|
282
|
+
```js
|
|
283
|
+
export default { generator: 'heyapi', input: './swagger.yaml', output: './api' }
|
|
284
|
+
```
|
|
275
285
|
|
|
276
286
|
---
|
|
277
287
|
|
|
278
|
-
##
|
|
288
|
+
## Documentation
|
|
279
289
|
|
|
280
|
-
|
|
|
281
|
-
|
|
282
|
-
| [
|
|
283
|
-
| [
|
|
284
|
-
| [API Reference](./docs/API-REFERENCE.md) | All
|
|
285
|
-
| [
|
|
290
|
+
| | |
|
|
291
|
+
|---|---|
|
|
292
|
+
| [Connectors](./docs/connectors/index.md) | Full connector API reference and examples |
|
|
293
|
+
| [Quick Start](./docs/QUICK-START.md) | From zero to working composables in 5 minutes |
|
|
294
|
+
| [API Reference](./docs/API-REFERENCE.md) | All options and TypeScript types |
|
|
295
|
+
| [Architecture](./docs/ARCHITECTURE.md) | How the generator works internally |
|
|
286
296
|
| [Troubleshooting](./docs/TROUBLESHOOTING.md) | Common errors and solutions |
|
|
287
297
|
|
|
288
298
|
---
|
|
289
299
|
|
|
290
|
-
##
|
|
291
|
-
|
|
292
|
-
Contributions are welcome! Please read the [Contributing Guidelines](./CONTRIBUTING.md) before submitting a PR.
|
|
300
|
+
## Contributing
|
|
293
301
|
|
|
294
302
|
```bash
|
|
295
|
-
# Development setup
|
|
296
303
|
npm install
|
|
297
304
|
npm run build
|
|
298
305
|
npm run validate # lint + type check
|
|
299
306
|
```
|
|
300
307
|
|
|
301
|
-
|
|
308
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
302
309
|
|
|
303
|
-
## 📄 License
|
|
304
|
-
|
|
305
|
-
Apache-2.0 — see [LICENSE](./LICENSE) for details.
|
|
306
310
|
|
|
307
311
|
---
|
|
308
312
|
|
|
309
|
-
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
Apache-2.0 — see [LICENSE](./LICENSE) for details.
|