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/INSTRUCTIONS.md
CHANGED
|
@@ -1,327 +1,327 @@
|
|
|
1
|
-
# Nuxt Generator - Documentation Index
|
|
2
|
-
|
|
3
|
-
> **Note**: This project's documentation has been reorganized for better accessibility. All detailed technical documentation is now in the `docs/` directory.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 📚 Documentation Structure
|
|
8
|
-
|
|
9
|
-
The documentation is organized to help different audiences find what they need quickly:
|
|
10
|
-
|
|
11
|
-
### 🚀 For New Developers & AI Assistants
|
|
12
|
-
|
|
13
|
-
**Start here if you're new to the project:**
|
|
14
|
-
|
|
15
|
-
👉 **[Quick Start Guide](./docs/QUICK-START.md)** - Understand the project in 5 minutes
|
|
16
|
-
|
|
17
|
-
- What is this project and how does it work?
|
|
18
|
-
- Core concepts you need to know (two-stage generation, wrapper pattern, runtime architecture)
|
|
19
|
-
- Key files to read first
|
|
20
|
-
- Most common development tasks
|
|
21
|
-
- Quick commands reference
|
|
22
|
-
|
|
23
|
-
### 🏗️ For Understanding Architecture
|
|
24
|
-
|
|
25
|
-
**Learn about design patterns and decisions:**
|
|
26
|
-
|
|
27
|
-
👉 **[Architecture & Design Documentation](./docs/ARCHITECTURE.md)** - Deep dive into patterns
|
|
28
|
-
|
|
29
|
-
- Architectural overview with diagrams
|
|
30
|
-
- Core patterns explained (two-stage generation, wrapper pattern, shared code, BFF)
|
|
31
|
-
- Design decisions (ADRs) with rationale and trade-offs
|
|
32
|
-
- Component dependency map
|
|
33
|
-
- Global callbacks system architecture
|
|
34
|
-
- Extension points for customization
|
|
35
|
-
|
|
36
|
-
### 📖 For Technical Reference
|
|
37
|
-
|
|
38
|
-
**Look up interfaces, functions, and APIs:**
|
|
39
|
-
|
|
40
|
-
👉 **[Complete API Reference](./docs/API-REFERENCE.md)** - Technical documentation
|
|
41
|
-
|
|
42
|
-
- CLI commands and options
|
|
43
|
-
- Configuration reference
|
|
44
|
-
- All TypeScript interfaces and types (MethodInfo, ApiRequestOptions, etc.)
|
|
45
|
-
- Parser API (extractMethodInfo, parseApiFile, scanApiFiles)
|
|
46
|
-
- Template API (generateComposableFile, generateFunctionBody)
|
|
47
|
-
- Runtime APIs (useApiRequest, useApiAsyncData, useApiAsyncDataRaw)
|
|
48
|
-
- Callback interfaces (RequestContext, SuccessContext, ErrorContext, FinishContext)
|
|
49
|
-
- Generated composables reference
|
|
50
|
-
|
|
51
|
-
### 🔧 For Development & Contributing
|
|
52
|
-
|
|
53
|
-
**Extend the generator or contribute code:**
|
|
54
|
-
|
|
55
|
-
👉 **[Development Guide](./docs/DEVELOPMENT.md)** - Practical development instructions
|
|
56
|
-
|
|
57
|
-
- Getting started with development
|
|
58
|
-
- Development workflow and best practices
|
|
59
|
-
- How to add new features:
|
|
60
|
-
- Adding a new callback type
|
|
61
|
-
- Adding a new generator
|
|
62
|
-
- Adding parser features
|
|
63
|
-
- Testing strategies
|
|
64
|
-
- Code style guidelines
|
|
65
|
-
- Common development tasks
|
|
66
|
-
- Debugging tips and tools
|
|
67
|
-
|
|
68
|
-
### 🐛 For Problem Solving
|
|
69
|
-
|
|
70
|
-
**When things go wrong:**
|
|
71
|
-
|
|
72
|
-
👉 **[Troubleshooting Guide](./docs/TROUBLESHOOTING.md)** - Solutions to common issues
|
|
73
|
-
|
|
74
|
-
- Installation problems
|
|
75
|
-
- Generation errors (APIs directory not found, found 0 methods, etc.)
|
|
76
|
-
- Runtime errors (module not found, useFetch not defined, etc.)
|
|
77
|
-
- Type errors
|
|
78
|
-
- Callback troubleshooting (callbacks not firing, global callbacks not working)
|
|
79
|
-
- Performance optimization
|
|
80
|
-
- OpenAPI spec issues
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## Quick Navigation
|
|
85
|
-
|
|
86
|
-
### By Role
|
|
87
|
-
|
|
88
|
-
| I am a... | Start here... |
|
|
89
|
-
| ----------------------------- | ---------------------------------------------------- |
|
|
90
|
-
| New developer or AI assistant | [Quick Start Guide](./docs/QUICK-START.md) |
|
|
91
|
-
| Contributor adding features | [Development Guide](./docs/DEVELOPMENT.md) |
|
|
92
|
-
| Architect reviewing design | [Architecture Documentation](./docs/ARCHITECTURE.md) |
|
|
93
|
-
| Developer with an error | [Troubleshooting Guide](./docs/TROUBLESHOOTING.md) |
|
|
94
|
-
| Looking up an interface/type | [API Reference](./docs/API-REFERENCE.md) |
|
|
95
|
-
|
|
96
|
-
### By Task
|
|
97
|
-
|
|
98
|
-
| I want to... | See... |
|
|
99
|
-
| -------------------------------- | --------------------------------------------------------------------------------------- |
|
|
100
|
-
| Understand the project quickly | [Quick Start - What is this?](./docs/QUICK-START.md#what-is-this) |
|
|
101
|
-
| Know why it's built this way | [Architecture - Design Decisions](./docs/ARCHITECTURE.md#design-decisions-adrs) |
|
|
102
|
-
| Add a new callback type | [Development - Add Callback](./docs/DEVELOPMENT.md#add-a-new-callback-type) |
|
|
103
|
-
| Add a new generator | [Development - Add Generator](./docs/DEVELOPMENT.md#add-a-new-generator-type) |
|
|
104
|
-
| Understand global callbacks | [Architecture - Global Callbacks](./docs/ARCHITECTURE.md#global-callbacks-deep-dive) |
|
|
105
|
-
| Debug parser not finding methods | [Troubleshooting - Parser Issues](./docs/TROUBLESHOOTING.md#parser-not-finding-methods) |
|
|
106
|
-
| Look up MethodInfo interface | [API Reference - Interfaces](./docs/API-REFERENCE.md#methodinfo) |
|
|
107
|
-
| Understand execution order | [API Reference - Callback Interfaces](./docs/API-REFERENCE.md#callback-interfaces) |
|
|
108
|
-
| See all available CLI commands | [API Reference - CLI Commands](./docs/API-REFERENCE.md#cli-commands) |
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Key Concepts (Quick Reference)
|
|
113
|
-
|
|
114
|
-
### Generator Backends
|
|
115
|
-
|
|
116
|
-
The CLI supports two backends for Stage 1 (OpenAPI → TypeScript Client):
|
|
117
|
-
|
|
118
|
-
| Backend | Flag | Requires | Notes |
|
|
119
|
-
|---|---|---|---|
|
|
120
|
-
| `official` | `--backend official` | Java 11+ | Uses `@openapitools/openapi-generator-cli` |
|
|
121
|
-
| `heyapi` | `--backend heyapi` | Node.js only | Uses `@hey-api/openapi-ts` |
|
|
122
|
-
|
|
123
|
-
Both backends feed into the same Stage 2 parsers (`src/generators/shared/parsers/`), producing identical `MethodInfo[]` so all templates are shared. The CLI checks for Java and aborts with an install link if `official` is selected without Java present.
|
|
124
|
-
|
|
125
|
-
**Read more**: [Quick Start - Generator Backends](./docs/QUICK-START.md#generator-backends)
|
|
126
|
-
|
|
127
|
-
### Two-Stage Generation
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
OpenAPI Spec → [Stage 1: official or heyapi backend] → TypeScript Client
|
|
131
|
-
TypeScript Client → [Stage 2: Our Parser + Templates] → Nuxt Composables
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
**Why?** Leverage the mature OpenAPI ecosystem instead of parsing YAML ourselves.
|
|
135
|
-
|
|
136
|
-
**Read more**: [Architecture - Two-Stage Generation Pattern](./docs/ARCHITECTURE.md#1-two-stage-generation-pattern)
|
|
137
|
-
|
|
138
|
-
### Wrapper Pattern
|
|
139
|
-
|
|
140
|
-
```
|
|
141
|
-
useFetchAddPet → useApiRequest → useFetch (Nuxt native)
|
|
142
|
-
↑
|
|
143
|
-
Adds: callbacks, auth, interceptors
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Why?** Add features (callbacks, auth) without modifying generated code.
|
|
147
|
-
|
|
148
|
-
**Read more**: [Architecture - Wrapper Pattern](./docs/ARCHITECTURE.md#2-wrapper-pattern)
|
|
149
|
-
|
|
150
|
-
### Runtime vs Build-time
|
|
151
|
-
|
|
152
|
-
| Type | Environment | Dependencies |
|
|
153
|
-
| ---------------- | ---------------------- | ----------------------- |
|
|
154
|
-
| **Build-time** | CLI tool (Node.js) | ts-morph, commander |
|
|
155
|
-
| **User runtime** | Nuxt project (browser) | Vue 3, Nuxt composables |
|
|
156
|
-
|
|
157
|
-
**Why separate?** Runtime files are **copied** to user's project, not imported from npm.
|
|
158
|
-
|
|
159
|
-
**Read more**: [Quick Start - Runtime vs Build-time](./docs/QUICK-START.md#2-runtime-vs-build-time)
|
|
160
|
-
|
|
161
|
-
### Global Callbacks System
|
|
162
|
-
|
|
163
|
-
Define callbacks **once** in a plugin, apply to **all** requests:
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
// plugins/api-callbacks.ts
|
|
167
|
-
export default defineNuxtPlugin(() => ({
|
|
168
|
-
provide: {
|
|
169
|
-
getGlobalApiCallbacks: () => ({
|
|
170
|
-
onRequest: (ctx) => {
|
|
171
|
-
/* Add auth */
|
|
172
|
-
},
|
|
173
|
-
onSuccess: (data) => {
|
|
174
|
-
/* Show toast */
|
|
175
|
-
},
|
|
176
|
-
onError: (error) => {
|
|
177
|
-
/* Handle errors */
|
|
178
|
-
},
|
|
179
|
-
}),
|
|
180
|
-
},
|
|
181
|
-
}));
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
**Control**: 3 ways to disable (skipGlobalCallbacks, return false, patterns)
|
|
185
|
-
|
|
186
|
-
**Read more**: [Architecture - Global Callbacks Deep Dive](./docs/ARCHITECTURE.md#global-callbacks-deep-dive)
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
## Project Structure Quick Overview
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
nuxt-generator/
|
|
194
|
-
├── docs/ # 📚 Documentation (START HERE)
|
|
195
|
-
│ ├── README.md # Documentation index
|
|
196
|
-
│ ├── QUICK-START.md # 5-minute overview
|
|
197
|
-
│ ├── ARCHITECTURE.md # Design patterns & ADRs
|
|
198
|
-
│ ├── API-REFERENCE.md # Complete technical reference
|
|
199
|
-
│ ├── DEVELOPMENT.md # How to contribute
|
|
200
|
-
│ └── TROUBLESHOOTING.md # Problem solving
|
|
201
|
-
│
|
|
202
|
-
├── src/ # Source code
|
|
203
|
-
│ ├── index.ts # ⭐ CLI entry point
|
|
204
|
-
│ ├── generate.ts # OpenAPI Generator wrapper
|
|
205
|
-
│ └── generators/
|
|
206
|
-
│ ├── shared/ # Common code
|
|
207
|
-
│ │ ├── types.ts # MethodInfo, ApiClassInfo
|
|
208
|
-
│ │ ├── runtime/ # Copied to output
|
|
209
|
-
│ │ │ └── apiHelpers.ts # Callbacks, auth, transforms
|
|
210
|
-
│ │ └── templates/
|
|
211
|
-
│ │ └── api-callbacks-plugin.ts # Global callbacks template
|
|
212
|
-
│ │
|
|
213
|
-
│ ├── use-fetch/ # ⭐ Main generator
|
|
214
|
-
│ │ ├── parser.ts # Extract API info (ts-morph)
|
|
215
|
-
│ │ ├── templates.ts # Generate composables
|
|
216
|
-
│ │ ├── generator.ts # Orchestration
|
|
217
|
-
│ │ └── runtime/
|
|
218
|
-
│ │ └── useApiRequest.ts # Wrapper (copied to user)
|
|
219
|
-
│ │
|
|
220
|
-
│ ├── use-async-data/ # useAsyncData generator
|
|
221
|
-
│ └── nuxt-server/ # Server routes generator
|
|
222
|
-
│
|
|
223
|
-
├── README.md # User-facing documentation
|
|
224
|
-
├── CONTRIBUTING.md # Contribution guidelines
|
|
225
|
-
├── INSTRUCTIONS.md # This file (documentation index)
|
|
226
|
-
└── package.json
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## Migration Guide (Old INSTRUCTIONS.md → New docs/)
|
|
232
|
-
|
|
233
|
-
If you're looking for content from the old `INSTRUCTIONS.md` file, here's where it moved:
|
|
234
|
-
|
|
235
|
-
| Old Section | New Location |
|
|
236
|
-
| ------------------------------ | ------------------------------------------------------------------------------------------ |
|
|
237
|
-
| Project Overview | [Quick Start - What is this?](./docs/QUICK-START.md#what-is-this) |
|
|
238
|
-
| Project Structure | [Quick Start - Project Structure](./docs/QUICK-START.md#project-structure-overview) |
|
|
239
|
-
| Technology Stack | [Quick Start - Technology Stack](./docs/QUICK-START.md#technology-stack-quick-ref) |
|
|
240
|
-
| Architecture & Design Patterns | [Architecture Documentation](./docs/ARCHITECTURE.md) |
|
|
241
|
-
| Two-Stage Generation | [Architecture - Two-Stage](./docs/ARCHITECTURE.md#1-two-stage-generation-pattern) |
|
|
242
|
-
| Wrapper Pattern | [Architecture - Wrapper](./docs/ARCHITECTURE.md#2-wrapper-pattern) |
|
|
243
|
-
| Parser Architecture | [Architecture - ADR-001](./docs/ARCHITECTURE.md#adr-001-use-ts-morph-instead-of-regex) |
|
|
244
|
-
| Template-Based Generation | [Architecture - Template Pattern](./docs/ARCHITECTURE.md#4-template-based-code-generation) |
|
|
245
|
-
| Runtime Design | [Quick Start - Runtime vs Build-time](./docs/QUICK-START.md#2-runtime-vs-build-time) |
|
|
246
|
-
| Global Callbacks System | [Architecture - Global Callbacks](./docs/ARCHITECTURE.md#global-callbacks-deep-dive) |
|
|
247
|
-
| Testing Strategy | [Development - Testing](./docs/DEVELOPMENT.md#testing-changes) |
|
|
248
|
-
| Common Pitfalls | [Troubleshooting Guide](./docs/TROUBLESHOOTING.md) |
|
|
249
|
-
| BFF Architecture | [Architecture - BFF](./docs/ARCHITECTURE.md) + [README - BFF](./README.md) |
|
|
250
|
-
| Code Style & Conventions | [Development - Code Style](./docs/DEVELOPMENT.md#code-style) |
|
|
251
|
-
| CLI Design Principles | [API Reference - CLI Commands](./docs/API-REFERENCE.md#cli-commands) |
|
|
252
|
-
| Interfaces & Types | [API Reference - Interfaces](./docs/API-REFERENCE.md#interfaces--types) |
|
|
253
|
-
| Parser API | [API Reference - Parser API](./docs/API-REFERENCE.md#parser-api) |
|
|
254
|
-
| Template API | [API Reference - Template API](./docs/API-REFERENCE.md#template-api) |
|
|
255
|
-
| Runtime APIs | [API Reference - Runtime APIs](./docs/API-REFERENCE.md#runtime-apis) |
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
## ⚠️ Important: Always Build Before Testing
|
|
260
|
-
|
|
261
|
-
After editing any file in `src/`, you **must** run the build before testing changes:
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
npm run build
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
This compiles TypeScript from `src/` to JavaScript in `dist/`. The CLI (`nxh` / `node dist/index.js`) runs from `dist/` — **without rebuilding, your changes have no effect**.
|
|
268
|
-
|
|
269
|
-
**Full cycle:**
|
|
270
|
-
|
|
271
|
-
```bash
|
|
272
|
-
# 1. Edit files in src/
|
|
273
|
-
# 2. Build
|
|
274
|
-
npm run build
|
|
275
|
-
# 3. Test
|
|
276
|
-
node dist/index.js generate -i swagger.yaml -o ./swagger
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
See [Development Workflow](./docs/DEVELOPMENT.md#development-workflow) for the full step-by-step guide.
|
|
280
|
-
|
|
281
|
-
---
|
|
282
|
-
|
|
283
|
-
## Glossary
|
|
284
|
-
|
|
285
|
-
Quick reference for technical terms used throughout the documentation:
|
|
286
|
-
|
|
287
|
-
- **Two-Stage Generation**: OpenAPI → TypeScript Fetch → Nuxt Composables
|
|
288
|
-
- **Wrapper Pattern**: Generated composables call runtime wrappers (useApiRequest, useApiAsyncData)
|
|
289
|
-
- **Runtime Files**: Code copied to user's project (not imported from npm package)
|
|
290
|
-
- **Build-time Runtime**: Environment where CLI tool runs (Node.js, ts-morph, commander)
|
|
291
|
-
- **User Runtime**: Environment where generated code runs (Vue 3, Nuxt composables, browser/SSR)
|
|
292
|
-
- **MethodInfo**: TypeScript interface containing all extracted data about an API endpoint
|
|
293
|
-
- **ApiClassInfo**: Interface grouping all methods from a single API class
|
|
294
|
-
- **Parser**: Code using ts-morph to extract API information from TypeScript files
|
|
295
|
-
- **Template**: Functions that generate composable code from MethodInfo
|
|
296
|
-
- **Generator**: Orchestrator that calls parser, templates, and writes files
|
|
297
|
-
- **Global Callbacks**: Callbacks defined once in a plugin that apply to all API requests
|
|
298
|
-
- **BFF**: Backend for Frontend - pattern separating routing from business logic
|
|
299
|
-
- **Raw Composables**: useAsyncData composables that return full response (data + headers + status)
|
|
300
|
-
- **Normal Composables**: Standard composables that return only data
|
|
301
|
-
- **ADR**: Architectural Decision Record - document explaining why a design choice was made
|
|
302
|
-
- **SSR**: Server-Side Rendering - Nuxt's ability to render pages on the server
|
|
303
|
-
- **AST**: Abstract Syntax Tree - tree representation of TypeScript code structure
|
|
304
|
-
- **Dual Composables**: Pattern where both normal and raw versions are generated
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
## Getting Help
|
|
309
|
-
|
|
310
|
-
### Documentation Issues
|
|
311
|
-
|
|
312
|
-
If you can't find what you're looking for or the documentation is unclear:
|
|
313
|
-
|
|
314
|
-
1. Check the [Documentation Index](./docs/README.md)
|
|
315
|
-
2. Use the "By Task" navigation table above
|
|
316
|
-
3. Search across all docs (GitHub search: `repo:username/nuxt-generator path:docs/ <your query>`)
|
|
317
|
-
4. [Open a documentation issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?labels=documentation)
|
|
318
|
-
|
|
319
|
-
### Technical Support
|
|
320
|
-
|
|
321
|
-
- **Bug Reports**: [Open an issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?template=bug_report.md)
|
|
322
|
-
- **Feature Requests**: [Open an issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?template=feature_request.md)
|
|
323
|
-
- **Questions**: [Start a discussion](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/discussions)
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
**Ready to dive in?** Start with the [Quick Start Guide](./docs/QUICK-START.md)!
|
|
1
|
+
# Nuxt Generator - Documentation Index
|
|
2
|
+
|
|
3
|
+
> **Note**: This project's documentation has been reorganized for better accessibility. All detailed technical documentation is now in the `docs/` directory.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📚 Documentation Structure
|
|
8
|
+
|
|
9
|
+
The documentation is organized to help different audiences find what they need quickly:
|
|
10
|
+
|
|
11
|
+
### 🚀 For New Developers & AI Assistants
|
|
12
|
+
|
|
13
|
+
**Start here if you're new to the project:**
|
|
14
|
+
|
|
15
|
+
👉 **[Quick Start Guide](./docs/QUICK-START.md)** - Understand the project in 5 minutes
|
|
16
|
+
|
|
17
|
+
- What is this project and how does it work?
|
|
18
|
+
- Core concepts you need to know (two-stage generation, wrapper pattern, runtime architecture)
|
|
19
|
+
- Key files to read first
|
|
20
|
+
- Most common development tasks
|
|
21
|
+
- Quick commands reference
|
|
22
|
+
|
|
23
|
+
### 🏗️ For Understanding Architecture
|
|
24
|
+
|
|
25
|
+
**Learn about design patterns and decisions:**
|
|
26
|
+
|
|
27
|
+
👉 **[Architecture & Design Documentation](./docs/ARCHITECTURE.md)** - Deep dive into patterns
|
|
28
|
+
|
|
29
|
+
- Architectural overview with diagrams
|
|
30
|
+
- Core patterns explained (two-stage generation, wrapper pattern, shared code, BFF)
|
|
31
|
+
- Design decisions (ADRs) with rationale and trade-offs
|
|
32
|
+
- Component dependency map
|
|
33
|
+
- Global callbacks system architecture
|
|
34
|
+
- Extension points for customization
|
|
35
|
+
|
|
36
|
+
### 📖 For Technical Reference
|
|
37
|
+
|
|
38
|
+
**Look up interfaces, functions, and APIs:**
|
|
39
|
+
|
|
40
|
+
👉 **[Complete API Reference](./docs/API-REFERENCE.md)** - Technical documentation
|
|
41
|
+
|
|
42
|
+
- CLI commands and options
|
|
43
|
+
- Configuration reference
|
|
44
|
+
- All TypeScript interfaces and types (MethodInfo, ApiRequestOptions, etc.)
|
|
45
|
+
- Parser API (extractMethodInfo, parseApiFile, scanApiFiles)
|
|
46
|
+
- Template API (generateComposableFile, generateFunctionBody)
|
|
47
|
+
- Runtime APIs (useApiRequest, useApiAsyncData, useApiAsyncDataRaw)
|
|
48
|
+
- Callback interfaces (RequestContext, SuccessContext, ErrorContext, FinishContext)
|
|
49
|
+
- Generated composables reference
|
|
50
|
+
|
|
51
|
+
### 🔧 For Development & Contributing
|
|
52
|
+
|
|
53
|
+
**Extend the generator or contribute code:**
|
|
54
|
+
|
|
55
|
+
👉 **[Development Guide](./docs/DEVELOPMENT.md)** - Practical development instructions
|
|
56
|
+
|
|
57
|
+
- Getting started with development
|
|
58
|
+
- Development workflow and best practices
|
|
59
|
+
- How to add new features:
|
|
60
|
+
- Adding a new callback type
|
|
61
|
+
- Adding a new generator
|
|
62
|
+
- Adding parser features
|
|
63
|
+
- Testing strategies
|
|
64
|
+
- Code style guidelines
|
|
65
|
+
- Common development tasks
|
|
66
|
+
- Debugging tips and tools
|
|
67
|
+
|
|
68
|
+
### 🐛 For Problem Solving
|
|
69
|
+
|
|
70
|
+
**When things go wrong:**
|
|
71
|
+
|
|
72
|
+
👉 **[Troubleshooting Guide](./docs/TROUBLESHOOTING.md)** - Solutions to common issues
|
|
73
|
+
|
|
74
|
+
- Installation problems
|
|
75
|
+
- Generation errors (APIs directory not found, found 0 methods, etc.)
|
|
76
|
+
- Runtime errors (module not found, useFetch not defined, etc.)
|
|
77
|
+
- Type errors
|
|
78
|
+
- Callback troubleshooting (callbacks not firing, global callbacks not working)
|
|
79
|
+
- Performance optimization
|
|
80
|
+
- OpenAPI spec issues
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Quick Navigation
|
|
85
|
+
|
|
86
|
+
### By Role
|
|
87
|
+
|
|
88
|
+
| I am a... | Start here... |
|
|
89
|
+
| ----------------------------- | ---------------------------------------------------- |
|
|
90
|
+
| New developer or AI assistant | [Quick Start Guide](./docs/QUICK-START.md) |
|
|
91
|
+
| Contributor adding features | [Development Guide](./docs/DEVELOPMENT.md) |
|
|
92
|
+
| Architect reviewing design | [Architecture Documentation](./docs/ARCHITECTURE.md) |
|
|
93
|
+
| Developer with an error | [Troubleshooting Guide](./docs/TROUBLESHOOTING.md) |
|
|
94
|
+
| Looking up an interface/type | [API Reference](./docs/API-REFERENCE.md) |
|
|
95
|
+
|
|
96
|
+
### By Task
|
|
97
|
+
|
|
98
|
+
| I want to... | See... |
|
|
99
|
+
| -------------------------------- | --------------------------------------------------------------------------------------- |
|
|
100
|
+
| Understand the project quickly | [Quick Start - What is this?](./docs/QUICK-START.md#what-is-this) |
|
|
101
|
+
| Know why it's built this way | [Architecture - Design Decisions](./docs/ARCHITECTURE.md#design-decisions-adrs) |
|
|
102
|
+
| Add a new callback type | [Development - Add Callback](./docs/DEVELOPMENT.md#add-a-new-callback-type) |
|
|
103
|
+
| Add a new generator | [Development - Add Generator](./docs/DEVELOPMENT.md#add-a-new-generator-type) |
|
|
104
|
+
| Understand global callbacks | [Architecture - Global Callbacks](./docs/ARCHITECTURE.md#global-callbacks-deep-dive) |
|
|
105
|
+
| Debug parser not finding methods | [Troubleshooting - Parser Issues](./docs/TROUBLESHOOTING.md#parser-not-finding-methods) |
|
|
106
|
+
| Look up MethodInfo interface | [API Reference - Interfaces](./docs/API-REFERENCE.md#methodinfo) |
|
|
107
|
+
| Understand execution order | [API Reference - Callback Interfaces](./docs/API-REFERENCE.md#callback-interfaces) |
|
|
108
|
+
| See all available CLI commands | [API Reference - CLI Commands](./docs/API-REFERENCE.md#cli-commands) |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Key Concepts (Quick Reference)
|
|
113
|
+
|
|
114
|
+
### Generator Backends
|
|
115
|
+
|
|
116
|
+
The CLI supports two backends for Stage 1 (OpenAPI → TypeScript Client):
|
|
117
|
+
|
|
118
|
+
| Backend | Flag | Requires | Notes |
|
|
119
|
+
|---|---|---|---|
|
|
120
|
+
| `official` | `--backend official` | Java 11+ | Uses `@openapitools/openapi-generator-cli` |
|
|
121
|
+
| `heyapi` | `--backend heyapi` | Node.js only | Uses `@hey-api/openapi-ts` |
|
|
122
|
+
|
|
123
|
+
Both backends feed into the same Stage 2 parsers (`src/generators/shared/parsers/`), producing identical `MethodInfo[]` so all templates are shared. The CLI checks for Java and aborts with an install link if `official` is selected without Java present.
|
|
124
|
+
|
|
125
|
+
**Read more**: [Quick Start - Generator Backends](./docs/QUICK-START.md#generator-backends)
|
|
126
|
+
|
|
127
|
+
### Two-Stage Generation
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
OpenAPI Spec → [Stage 1: official or heyapi backend] → TypeScript Client
|
|
131
|
+
TypeScript Client → [Stage 2: Our Parser + Templates] → Nuxt Composables
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Why?** Leverage the mature OpenAPI ecosystem instead of parsing YAML ourselves.
|
|
135
|
+
|
|
136
|
+
**Read more**: [Architecture - Two-Stage Generation Pattern](./docs/ARCHITECTURE.md#1-two-stage-generation-pattern)
|
|
137
|
+
|
|
138
|
+
### Wrapper Pattern
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
useFetchAddPet → useApiRequest → useFetch (Nuxt native)
|
|
142
|
+
↑
|
|
143
|
+
Adds: callbacks, auth, interceptors
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Why?** Add features (callbacks, auth) without modifying generated code.
|
|
147
|
+
|
|
148
|
+
**Read more**: [Architecture - Wrapper Pattern](./docs/ARCHITECTURE.md#2-wrapper-pattern)
|
|
149
|
+
|
|
150
|
+
### Runtime vs Build-time
|
|
151
|
+
|
|
152
|
+
| Type | Environment | Dependencies |
|
|
153
|
+
| ---------------- | ---------------------- | ----------------------- |
|
|
154
|
+
| **Build-time** | CLI tool (Node.js) | ts-morph, commander |
|
|
155
|
+
| **User runtime** | Nuxt project (browser) | Vue 3, Nuxt composables |
|
|
156
|
+
|
|
157
|
+
**Why separate?** Runtime files are **copied** to user's project, not imported from npm.
|
|
158
|
+
|
|
159
|
+
**Read more**: [Quick Start - Runtime vs Build-time](./docs/QUICK-START.md#2-runtime-vs-build-time)
|
|
160
|
+
|
|
161
|
+
### Global Callbacks System
|
|
162
|
+
|
|
163
|
+
Define callbacks **once** in a plugin, apply to **all** requests:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// plugins/api-callbacks.ts
|
|
167
|
+
export default defineNuxtPlugin(() => ({
|
|
168
|
+
provide: {
|
|
169
|
+
getGlobalApiCallbacks: () => ({
|
|
170
|
+
onRequest: (ctx) => {
|
|
171
|
+
/* Add auth */
|
|
172
|
+
},
|
|
173
|
+
onSuccess: (data) => {
|
|
174
|
+
/* Show toast */
|
|
175
|
+
},
|
|
176
|
+
onError: (error) => {
|
|
177
|
+
/* Handle errors */
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
}));
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Control**: 3 ways to disable (skipGlobalCallbacks, return false, patterns)
|
|
185
|
+
|
|
186
|
+
**Read more**: [Architecture - Global Callbacks Deep Dive](./docs/ARCHITECTURE.md#global-callbacks-deep-dive)
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Project Structure Quick Overview
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
nuxt-generator/
|
|
194
|
+
├── docs/ # 📚 Documentation (START HERE)
|
|
195
|
+
│ ├── README.md # Documentation index
|
|
196
|
+
│ ├── QUICK-START.md # 5-minute overview
|
|
197
|
+
│ ├── ARCHITECTURE.md # Design patterns & ADRs
|
|
198
|
+
│ ├── API-REFERENCE.md # Complete technical reference
|
|
199
|
+
│ ├── DEVELOPMENT.md # How to contribute
|
|
200
|
+
│ └── TROUBLESHOOTING.md # Problem solving
|
|
201
|
+
│
|
|
202
|
+
├── src/ # Source code
|
|
203
|
+
│ ├── index.ts # ⭐ CLI entry point
|
|
204
|
+
│ ├── generate.ts # OpenAPI Generator wrapper
|
|
205
|
+
│ └── generators/
|
|
206
|
+
│ ├── shared/ # Common code
|
|
207
|
+
│ │ ├── types.ts # MethodInfo, ApiClassInfo
|
|
208
|
+
│ │ ├── runtime/ # Copied to output
|
|
209
|
+
│ │ │ └── apiHelpers.ts # Callbacks, auth, transforms
|
|
210
|
+
│ │ └── templates/
|
|
211
|
+
│ │ └── api-callbacks-plugin.ts # Global callbacks template
|
|
212
|
+
│ │
|
|
213
|
+
│ ├── use-fetch/ # ⭐ Main generator
|
|
214
|
+
│ │ ├── parser.ts # Extract API info (ts-morph)
|
|
215
|
+
│ │ ├── templates.ts # Generate composables
|
|
216
|
+
│ │ ├── generator.ts # Orchestration
|
|
217
|
+
│ │ └── runtime/
|
|
218
|
+
│ │ └── useApiRequest.ts # Wrapper (copied to user)
|
|
219
|
+
│ │
|
|
220
|
+
│ ├── use-async-data/ # useAsyncData generator
|
|
221
|
+
│ └── nuxt-server/ # Server routes generator
|
|
222
|
+
│
|
|
223
|
+
├── README.md # User-facing documentation
|
|
224
|
+
├── CONTRIBUTING.md # Contribution guidelines
|
|
225
|
+
├── INSTRUCTIONS.md # This file (documentation index)
|
|
226
|
+
└── package.json
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Migration Guide (Old INSTRUCTIONS.md → New docs/)
|
|
232
|
+
|
|
233
|
+
If you're looking for content from the old `INSTRUCTIONS.md` file, here's where it moved:
|
|
234
|
+
|
|
235
|
+
| Old Section | New Location |
|
|
236
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------ |
|
|
237
|
+
| Project Overview | [Quick Start - What is this?](./docs/QUICK-START.md#what-is-this) |
|
|
238
|
+
| Project Structure | [Quick Start - Project Structure](./docs/QUICK-START.md#project-structure-overview) |
|
|
239
|
+
| Technology Stack | [Quick Start - Technology Stack](./docs/QUICK-START.md#technology-stack-quick-ref) |
|
|
240
|
+
| Architecture & Design Patterns | [Architecture Documentation](./docs/ARCHITECTURE.md) |
|
|
241
|
+
| Two-Stage Generation | [Architecture - Two-Stage](./docs/ARCHITECTURE.md#1-two-stage-generation-pattern) |
|
|
242
|
+
| Wrapper Pattern | [Architecture - Wrapper](./docs/ARCHITECTURE.md#2-wrapper-pattern) |
|
|
243
|
+
| Parser Architecture | [Architecture - ADR-001](./docs/ARCHITECTURE.md#adr-001-use-ts-morph-instead-of-regex) |
|
|
244
|
+
| Template-Based Generation | [Architecture - Template Pattern](./docs/ARCHITECTURE.md#4-template-based-code-generation) |
|
|
245
|
+
| Runtime Design | [Quick Start - Runtime vs Build-time](./docs/QUICK-START.md#2-runtime-vs-build-time) |
|
|
246
|
+
| Global Callbacks System | [Architecture - Global Callbacks](./docs/ARCHITECTURE.md#global-callbacks-deep-dive) |
|
|
247
|
+
| Testing Strategy | [Development - Testing](./docs/DEVELOPMENT.md#testing-changes) |
|
|
248
|
+
| Common Pitfalls | [Troubleshooting Guide](./docs/TROUBLESHOOTING.md) |
|
|
249
|
+
| BFF Architecture | [Architecture - BFF](./docs/ARCHITECTURE.md) + [README - BFF](./README.md) |
|
|
250
|
+
| Code Style & Conventions | [Development - Code Style](./docs/DEVELOPMENT.md#code-style) |
|
|
251
|
+
| CLI Design Principles | [API Reference - CLI Commands](./docs/API-REFERENCE.md#cli-commands) |
|
|
252
|
+
| Interfaces & Types | [API Reference - Interfaces](./docs/API-REFERENCE.md#interfaces--types) |
|
|
253
|
+
| Parser API | [API Reference - Parser API](./docs/API-REFERENCE.md#parser-api) |
|
|
254
|
+
| Template API | [API Reference - Template API](./docs/API-REFERENCE.md#template-api) |
|
|
255
|
+
| Runtime APIs | [API Reference - Runtime APIs](./docs/API-REFERENCE.md#runtime-apis) |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## ⚠️ Important: Always Build Before Testing
|
|
260
|
+
|
|
261
|
+
After editing any file in `src/`, you **must** run the build before testing changes:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npm run build
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
This compiles TypeScript from `src/` to JavaScript in `dist/`. The CLI (`nxh` / `node dist/index.js`) runs from `dist/` — **without rebuilding, your changes have no effect**.
|
|
268
|
+
|
|
269
|
+
**Full cycle:**
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# 1. Edit files in src/
|
|
273
|
+
# 2. Build
|
|
274
|
+
npm run build
|
|
275
|
+
# 3. Test
|
|
276
|
+
node dist/index.js generate -i swagger.yaml -o ./swagger
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
See [Development Workflow](./docs/DEVELOPMENT.md#development-workflow) for the full step-by-step guide.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Glossary
|
|
284
|
+
|
|
285
|
+
Quick reference for technical terms used throughout the documentation:
|
|
286
|
+
|
|
287
|
+
- **Two-Stage Generation**: OpenAPI → TypeScript Fetch → Nuxt Composables
|
|
288
|
+
- **Wrapper Pattern**: Generated composables call runtime wrappers (useApiRequest, useApiAsyncData)
|
|
289
|
+
- **Runtime Files**: Code copied to user's project (not imported from npm package)
|
|
290
|
+
- **Build-time Runtime**: Environment where CLI tool runs (Node.js, ts-morph, commander)
|
|
291
|
+
- **User Runtime**: Environment where generated code runs (Vue 3, Nuxt composables, browser/SSR)
|
|
292
|
+
- **MethodInfo**: TypeScript interface containing all extracted data about an API endpoint
|
|
293
|
+
- **ApiClassInfo**: Interface grouping all methods from a single API class
|
|
294
|
+
- **Parser**: Code using ts-morph to extract API information from TypeScript files
|
|
295
|
+
- **Template**: Functions that generate composable code from MethodInfo
|
|
296
|
+
- **Generator**: Orchestrator that calls parser, templates, and writes files
|
|
297
|
+
- **Global Callbacks**: Callbacks defined once in a plugin that apply to all API requests
|
|
298
|
+
- **BFF**: Backend for Frontend - pattern separating routing from business logic
|
|
299
|
+
- **Raw Composables**: useAsyncData composables that return full response (data + headers + status)
|
|
300
|
+
- **Normal Composables**: Standard composables that return only data
|
|
301
|
+
- **ADR**: Architectural Decision Record - document explaining why a design choice was made
|
|
302
|
+
- **SSR**: Server-Side Rendering - Nuxt's ability to render pages on the server
|
|
303
|
+
- **AST**: Abstract Syntax Tree - tree representation of TypeScript code structure
|
|
304
|
+
- **Dual Composables**: Pattern where both normal and raw versions are generated
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Getting Help
|
|
309
|
+
|
|
310
|
+
### Documentation Issues
|
|
311
|
+
|
|
312
|
+
If you can't find what you're looking for or the documentation is unclear:
|
|
313
|
+
|
|
314
|
+
1. Check the [Documentation Index](./docs/README.md)
|
|
315
|
+
2. Use the "By Task" navigation table above
|
|
316
|
+
3. Search across all docs (GitHub search: `repo:username/nuxt-generator path:docs/ <your query>`)
|
|
317
|
+
4. [Open a documentation issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?labels=documentation)
|
|
318
|
+
|
|
319
|
+
### Technical Support
|
|
320
|
+
|
|
321
|
+
- **Bug Reports**: [Open an issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?template=bug_report.md)
|
|
322
|
+
- **Feature Requests**: [Open an issue](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/issues/new?template=feature_request.md)
|
|
323
|
+
- **Questions**: [Start a discussion](https://github.com/dmartindiaz/nuxt-openapi-hyperfetch/discussions)
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
**Ready to dive in?** Start with the [Quick Start Guide](./docs/QUICK-START.md)!
|