nuxt-openapi-hyperfetch 0.2.7-alpha.1 β 0.3.0-beta
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/.editorconfig +26 -26
- package/.prettierignore +17 -17
- package/CONTRIBUTING.md +291 -291
- package/INSTRUCTIONS.md +327 -327
- package/LICENSE +202 -202
- package/README.md +309 -231
- package/dist/cli/config.d.ts +9 -2
- package/dist/cli/config.js +1 -1
- package/dist/cli/logo.js +5 -5
- package/dist/cli/messages.d.ts +1 -0
- package/dist/cli/messages.js +2 -0
- package/dist/cli/prompts.d.ts +5 -0
- package/dist/cli/prompts.js +12 -0
- package/dist/cli/types.d.ts +1 -1
- package/dist/generators/components/connector-generator/templates.js +68 -19
- package/dist/generators/shared/runtime/useFormConnector.js +8 -1
- package/dist/generators/shared/runtime/useListConnector.js +13 -6
- package/dist/generators/use-async-data/generator.js +4 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncData.js +4 -4
- package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +4 -4
- package/dist/generators/use-async-data/templates.js +17 -17
- package/dist/generators/use-fetch/generator.js +4 -0
- package/dist/generators/use-fetch/templates.js +14 -14
- package/dist/index.js +40 -27
- package/dist/module/index.js +19 -0
- package/dist/module/types.d.ts +7 -0
- package/docs/API-REFERENCE.md +886 -886
- package/docs/generated-components.md +615 -615
- package/docs/headless-composables-ui.md +569 -569
- package/eslint.config.js +85 -85
- package/package.json +1 -1
- package/src/cli/config.ts +147 -140
- package/src/cli/logger.ts +124 -124
- package/src/cli/logo.ts +25 -25
- package/src/cli/messages.ts +4 -0
- package/src/cli/prompts.ts +14 -1
- package/src/cli/types.ts +50 -50
- package/src/generators/components/connector-generator/generator.ts +138 -138
- package/src/generators/components/connector-generator/templates.ts +307 -254
- package/src/generators/components/connector-generator/types.ts +34 -34
- package/src/generators/components/schema-analyzer/index.ts +44 -44
- package/src/generators/components/schema-analyzer/intent-detector.ts +187 -187
- package/src/generators/components/schema-analyzer/openapi-reader.ts +96 -96
- package/src/generators/components/schema-analyzer/resource-grouper.ts +166 -166
- package/src/generators/components/schema-analyzer/schema-field-mapper.ts +268 -268
- package/src/generators/components/schema-analyzer/types.ts +177 -177
- package/src/generators/nuxt-server/generator.ts +272 -272
- package/src/generators/shared/runtime/apiHelpers.ts +535 -535
- package/src/generators/shared/runtime/pagination.ts +323 -323
- package/src/generators/shared/runtime/useDeleteConnector.ts +109 -109
- package/src/generators/shared/runtime/useDetailConnector.ts +64 -64
- package/src/generators/shared/runtime/useFormConnector.ts +147 -139
- package/src/generators/shared/runtime/useListConnector.ts +158 -148
- package/src/generators/shared/runtime/zod-error-merger.ts +119 -119
- package/src/generators/shared/templates/api-callbacks-plugin.ts +399 -399
- package/src/generators/shared/templates/api-pagination-plugin.ts +158 -158
- package/src/generators/use-async-data/generator.ts +213 -205
- package/src/generators/use-async-data/runtime/useApiAsyncData.ts +329 -329
- package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +324 -324
- package/src/generators/use-async-data/templates.ts +257 -257
- package/src/generators/use-fetch/generator.ts +178 -170
- package/src/generators/use-fetch/runtime/useApiRequest.ts +354 -354
- package/src/generators/use-fetch/templates.ts +214 -214
- package/src/index.ts +306 -303
- package/src/module/index.ts +158 -133
- package/src/module/types.ts +39 -31
- package/dist/generators/tanstack-query/generator.d.ts +0 -5
- package/dist/generators/tanstack-query/generator.js +0 -11
package/README.md
CHANGED
|
@@ -1,231 +1,309 @@
|
|
|
1
|
-
ο»Ώ
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
api
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
###
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
1
|
+
ο»Ώ<p align="center">
|
|
2
|
+
<img src="./public/nuxt-openapi-hyperfetch-logo.png" alt="Nuxt OpenAPI Hyperfetch logo" width="260" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# π Nuxt OpenAPI Generator
|
|
6
|
+
|
|
7
|
+
**Generate type-safe, SSR-compatible Nuxt composables from OpenAPI/Swagger specifications.**
|
|
8
|
+
|
|
9
|
+
π **[Full documentation β nuxt-openapi-hyperfetch.netlify.app](https://nuxt-openapi-hyperfetch.netlify.app/)**
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Transform your API documentation into production-ready **100% Nuxt-native** codeβ`useFetch` composables, `useAsyncData` composables, and Nuxt Server Routesβwith full TypeScript support, lifecycle callbacks, and request interception. Use it either as a CLI with `nxh generate` or as a Nuxt module wired directly from `nuxt.config.ts`.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## β¨ Features
|
|
18
|
+
|
|
19
|
+
- π **Type-Safe**: Full TypeScript support derived from your OpenAPI schema
|
|
20
|
+
- β‘ **SSR Compatible**: Works seamlessly with Nuxt server-side rendering
|
|
21
|
+
- π **Lifecycle Callbacks**: `onRequest`, `onSuccess`, `onError`, `onFinish`
|
|
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
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## π§ Generator Engines
|
|
34
|
+
|
|
35
|
+
Two generation engines are available. The CLI will ask you to choose one when running `nxh generate`:
|
|
36
|
+
|
|
37
|
+
| Engine | Tool | Node Native | Best for |
|
|
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 |
|
|
41
|
+
|
|
42
|
+
> The CLI checks for Java automatically when `official` is selected and aborts with an install link if it is not found. Get Java at [adoptium.net](https://adoptium.net).
|
|
43
|
+
|
|
44
|
+
You can also pre-select the engine in your `nxh.config.js` β the CLI will skip the prompt entirely:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// nxh.config.js
|
|
48
|
+
export default {
|
|
49
|
+
generator: 'openapi', // 'openapi' | 'heyapi'
|
|
50
|
+
input: './swagger.yaml',
|
|
51
|
+
output: './api',
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## π¦ Installation
|
|
58
|
+
|
|
59
|
+
### Use as CLI
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install -g nuxt-openapi-hyperfetch
|
|
63
|
+
# or
|
|
64
|
+
yarn global add nuxt-openapi-hyperfetch
|
|
65
|
+
# or
|
|
66
|
+
pnpm add -g nuxt-openapi-hyperfetch
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or use directly with npx:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx nuxt-openapi-hyperfetch generate
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Use as Nuxt module
|
|
76
|
+
|
|
77
|
+
Install it in your Nuxt project:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm install -D nuxt-openapi-hyperfetch
|
|
81
|
+
# or
|
|
82
|
+
pnpm add -D nuxt-openapi-hyperfetch
|
|
83
|
+
# or
|
|
84
|
+
yarn add -D nuxt-openapi-hyperfetch
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Then register the module in `nuxt.config.ts`:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
export default defineNuxtConfig({
|
|
91
|
+
modules: ['nuxt-openapi-hyperfetch'],
|
|
92
|
+
|
|
93
|
+
openApiHyperFetch: {
|
|
94
|
+
input: './swagger.yaml',
|
|
95
|
+
output: './composables/api',
|
|
96
|
+
generators: ['useFetch', 'useAsyncData'],
|
|
97
|
+
backend: 'heyapi',
|
|
98
|
+
enableDevBuild: true,
|
|
99
|
+
enableProductionBuild: true,
|
|
100
|
+
enableAutoGeneration: false,
|
|
101
|
+
enableAutoImport: true,
|
|
102
|
+
createUseAsyncDataConnectors: false,
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The module uses `openApiHyperFetch` as its Nuxt config key and runs generation during Nuxt build hooks. If you include `nuxtServer` in `generators`, you can also configure `serverRoutePath` and `enableBff` here.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## π Quick Start
|
|
112
|
+
|
|
113
|
+
### 1. Run the generator with the CLI
|
|
114
|
+
|
|
115
|
+
<p align="center">
|
|
116
|
+
<img src="./public/nuxt-openapi-hyperfetch-cli.png" alt="Nuxt OpenAPI Hyperfetch CLI" width="720" />
|
|
117
|
+
</p>
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
nxh generate
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The CLI will ask you for:
|
|
124
|
+
|
|
125
|
+
- π Path to your OpenAPI/Swagger file (`.yaml` or `.json`)
|
|
126
|
+
- π Output directory for generated files
|
|
127
|
+
- π§ Which generation engine to use (`official` or `heyapi`)
|
|
128
|
+
- β
Which composables to generate (`useFetch`, `useAsyncData`, `Nuxt server routes`)
|
|
129
|
+
|
|
130
|
+
Or pass arguments directly:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
nxh generate -i ./swagger.yaml -o ./api
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 2. Or generate through the Nuxt module
|
|
137
|
+
|
|
138
|
+
If you prefer generation to run from Nuxt itself, add the module and configure it in `nuxt.config.ts`:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
export default defineNuxtConfig({
|
|
142
|
+
modules: ['nuxt-openapi-hyperfetch'],
|
|
143
|
+
|
|
144
|
+
openApiHyperFetch: {
|
|
145
|
+
input: './swagger.yaml',
|
|
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
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Useful module options:
|
|
158
|
+
|
|
159
|
+
- `input`: OpenAPI file path relative to the Nuxt root.
|
|
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.
|
|
169
|
+
|
|
170
|
+
### 3. Generated output
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
api/
|
|
174
|
+
+-- runtime.ts
|
|
175
|
+
+-- apis/
|
|
176
|
+
β +-- PetApi.ts
|
|
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
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 4. Configure the API base URL
|
|
192
|
+
|
|
193
|
+
Add to `nuxt.config.ts`:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
export default defineNuxtConfig({
|
|
197
|
+
runtimeConfig: {
|
|
198
|
+
public: {
|
|
199
|
+
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'https://api.example.com'
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
And in `.env`:
|
|
206
|
+
|
|
207
|
+
```env
|
|
208
|
+
NUXT_PUBLIC_API_BASE_URL=https://api.example.com
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
All generated `useFetch` and `useAsyncData` composables will automatically use this as `baseURL`. You can still override it per-composable via `options.baseURL`.
|
|
212
|
+
|
|
213
|
+
### 5. Use in your Nuxt app
|
|
214
|
+
|
|
215
|
+
```vue
|
|
216
|
+
<script setup lang="ts">
|
|
217
|
+
import { useFetchGetPetById } from '@/api/composables/use-fetch';
|
|
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>
|
|
227
|
+
|
|
228
|
+
<template>
|
|
229
|
+
<div>
|
|
230
|
+
<div v-if="pending">Loading...</div>
|
|
231
|
+
<div v-else-if="error">Error: {{ error }}</div>
|
|
232
|
+
<div v-else-if="pet">{{ pet.name }} β {{ pet.status }}</div>
|
|
233
|
+
</div>
|
|
234
|
+
</template>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## π₯οΈ Nuxt Server Routes Generator
|
|
240
|
+
|
|
241
|
+
In addition to client-side composables, you can generate **Nuxt Server Routes** that proxy requests to your backend APIβkeeping API keys and secrets server-side.
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
Client β Nuxt Server Route (generated) β External API
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
After generation, configure your backend URL in `.env`:
|
|
248
|
+
|
|
249
|
+
```env
|
|
250
|
+
API_BASE_URL=https://your-backend-api.com/api
|
|
251
|
+
API_SECRET=your-secret-token
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
And add it to `nuxt.config.ts`:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
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
|
+
```
|
|
265
|
+
|
|
266
|
+
> **Note:** `runtimeConfig.apiBaseUrl` (private) is only for **Server Routes**. For `useFetch`/`useAsyncData` composables use `runtimeConfig.public.apiBaseUrl` instead β see the [Quick Start](#-quick-start) section above.
|
|
267
|
+
|
|
268
|
+
Then use standard `useFetch` against your Nuxt routes:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
const { data: pet } = useFetch('/api/pet/123');
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
> **BFF (Backend for Frontend) mode** is also available β generates a transformer layer for auth context, data enrichment, and permission filtering without ever overwriting your custom code. See the [Server Routes Guide](./docs/DEVELOPMENT.md) for details.
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## π Documentation
|
|
279
|
+
|
|
280
|
+
| Guide | Description |
|
|
281
|
+
|-------|-------------|
|
|
282
|
+
| [Quick Start Guide](./docs/QUICK-START.md) | Understand the project in 5 minutes |
|
|
283
|
+
| [Architecture](./docs/ARCHITECTURE.md) | Design patterns, two-stage generation, shared code |
|
|
284
|
+
| [API Reference](./docs/API-REFERENCE.md) | All CLI options, TypeScript types, composable APIs |
|
|
285
|
+
| [Development Guide](./docs/DEVELOPMENT.md) | Contributing, adding generators, code style |
|
|
286
|
+
| [Troubleshooting](./docs/TROUBLESHOOTING.md) | Common errors and solutions |
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## π€ Contributing
|
|
291
|
+
|
|
292
|
+
Contributions are welcome! Please read the [Contributing Guidelines](./CONTRIBUTING.md) before submitting a PR.
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
# Development setup
|
|
296
|
+
npm install
|
|
297
|
+
npm run build
|
|
298
|
+
npm run validate # lint + type check
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## π License
|
|
304
|
+
|
|
305
|
+
Apache-2.0 β see [LICENSE](./LICENSE) for details.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
**Made with β€οΈ for Nuxt developers**
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface GeneratorConfig {
|
|
|
24
24
|
/** Watch mode - regenerate on file changes */
|
|
25
25
|
watch?: boolean;
|
|
26
26
|
/** Generator types to use */
|
|
27
|
-
generators?: ('useFetch' | 'useAsyncData' | 'nuxtServer')[];
|
|
27
|
+
generators?: ('useFetch' | 'useAsyncData' | 'nuxtServer' | 'connectors')[];
|
|
28
28
|
/** Server route path (for nuxtServer mode) */
|
|
29
29
|
serverRoutePath?: string;
|
|
30
30
|
/** Enable BFF pattern (for nuxtServer mode) */
|
|
@@ -38,6 +38,13 @@ export interface GeneratorConfig {
|
|
|
38
38
|
* When set, the CLI will not ask which engine to use.
|
|
39
39
|
*/
|
|
40
40
|
generator?: ConfigGenerator;
|
|
41
|
+
/**
|
|
42
|
+
* Generate headless UI connector composables on top of useAsyncData.
|
|
43
|
+
* Connectors provide ready-made logic for tables, pagination, forms and delete actions.
|
|
44
|
+
* Requires useAsyncData to also be generated.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
createUseAsyncDataConnectors?: boolean;
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* Load configuration from nxh.config.js, nuxt-openapi-generator.config.js, or package.json
|
|
@@ -54,4 +61,4 @@ export declare function parseTags(tagsString?: string): string[] | undefined;
|
|
|
54
61
|
/**
|
|
55
62
|
* Parse generators string into array
|
|
56
63
|
*/
|
|
57
|
-
export declare function parseGenerators(generatorsString?: string): ('useFetch' | 'useAsyncData' | 'nuxtServer')[] | undefined;
|
|
64
|
+
export declare function parseGenerators(generatorsString?: string): ('useFetch' | 'useAsyncData' | 'nuxtServer' | 'connectors')[] | undefined;
|
package/dist/cli/config.js
CHANGED
|
@@ -81,5 +81,5 @@ export function parseGenerators(generatorsString) {
|
|
|
81
81
|
return undefined;
|
|
82
82
|
}
|
|
83
83
|
const parts = generatorsString.split(',').map((g) => g.trim());
|
|
84
|
-
return parts.filter((g) => ['useFetch', 'useAsyncData', 'nuxtServer'].includes(g));
|
|
84
|
+
return parts.filter((g) => ['useFetch', 'useAsyncData', 'nuxtServer', 'connectors'].includes(g));
|
|
85
85
|
}
|
package/dist/cli/logo.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import gradient from 'gradient-string';
|
|
2
|
-
const NUXT_LOGO = `ββββ ββββββ ββββββ ββββββββββββ
|
|
3
|
-
βββββ ββββββ ββββββββββββββββββββ
|
|
4
|
-
ββββββ ββββββ βββ ββββββ βββ
|
|
5
|
-
βββββββββββββ βββ ββββββ βββ
|
|
6
|
-
βββ βββββββββββββββββββ βββ βββ
|
|
2
|
+
const NUXT_LOGO = `ββββ ββββββ ββββββ ββββββββββββ
|
|
3
|
+
βββββ ββββββ ββββββββββββββββββββ
|
|
4
|
+
ββββββ ββββββ βββ ββββββ βββ
|
|
5
|
+
βββββββββββββ βββ ββββββ βββ
|
|
6
|
+
βββ βββββββββββββββββββ βββ βββ
|
|
7
7
|
βββ βββββ βββββββ βββ βββ βββ`;
|
|
8
8
|
const SUBTITLE = 'Nuxt OpenAPI Generator - useFetch, useAsyncData & Nuxt server';
|
|
9
9
|
/**
|
package/dist/cli/messages.d.ts
CHANGED
package/dist/cli/messages.js
CHANGED
|
@@ -57,6 +57,8 @@ export const CHOICES = {
|
|
|
57
57
|
label: 'Nuxt Server Routes - Generate server/api/* proxy routes',
|
|
58
58
|
},
|
|
59
59
|
],
|
|
60
|
+
// Connectors prompt (shown only when useAsyncData is selected)
|
|
61
|
+
connectorsPrompt: 'Generate headless UI connectors? (tables, pagination, forms & delete logic built on top of useAsyncData)',
|
|
60
62
|
// Server path options
|
|
61
63
|
serverPaths: [
|
|
62
64
|
{
|
package/dist/cli/prompts.d.ts
CHANGED
|
@@ -28,3 +28,8 @@ export declare function promptServerRoutePath(): Promise<string>;
|
|
|
28
28
|
* Returns whether BFF should be enabled
|
|
29
29
|
*/
|
|
30
30
|
export declare function promptBffConfig(): Promise<BffConfig>;
|
|
31
|
+
/**
|
|
32
|
+
* Ask whether to generate headless UI connectors on top of useAsyncData.
|
|
33
|
+
* Only called when useAsyncData was selected and no config value is present.
|
|
34
|
+
*/
|
|
35
|
+
export declare function promptConnectors(): Promise<boolean>;
|
package/dist/cli/prompts.js
CHANGED
|
@@ -116,3 +116,15 @@ export async function promptBffConfig() {
|
|
|
116
116
|
checkCancellation(result);
|
|
117
117
|
return { enableBff: result };
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Ask whether to generate headless UI connectors on top of useAsyncData.
|
|
121
|
+
* Only called when useAsyncData was selected and no config value is present.
|
|
122
|
+
*/
|
|
123
|
+
export async function promptConnectors() {
|
|
124
|
+
const result = await p.confirm({
|
|
125
|
+
message: CHOICES.connectorsPrompt,
|
|
126
|
+
initialValue: false,
|
|
127
|
+
});
|
|
128
|
+
checkCancellation(result);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
package/dist/cli/types.d.ts
CHANGED