nuxt-openapi-hyperfetch 0.1.0-alpha.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.
Files changed (109) hide show
  1. package/.editorconfig +26 -0
  2. package/.prettierignore +17 -0
  3. package/.prettierrc.json +12 -0
  4. package/CONTRIBUTING.md +292 -0
  5. package/INSTRUCTIONS.md +327 -0
  6. package/LICENSE +202 -0
  7. package/README.md +202 -0
  8. package/dist/cli/config.d.ts +57 -0
  9. package/dist/cli/config.js +85 -0
  10. package/dist/cli/logger.d.ts +44 -0
  11. package/dist/cli/logger.js +58 -0
  12. package/dist/cli/logo.d.ts +6 -0
  13. package/dist/cli/logo.js +21 -0
  14. package/dist/cli/messages.d.ts +65 -0
  15. package/dist/cli/messages.js +86 -0
  16. package/dist/cli/prompts.d.ts +30 -0
  17. package/dist/cli/prompts.js +118 -0
  18. package/dist/cli/types.d.ts +43 -0
  19. package/dist/cli/types.js +4 -0
  20. package/dist/cli/utils.d.ts +26 -0
  21. package/dist/cli/utils.js +45 -0
  22. package/dist/generate.d.ts +6 -0
  23. package/dist/generate.js +48 -0
  24. package/dist/generators/nuxt-server/bff-templates.d.ts +25 -0
  25. package/dist/generators/nuxt-server/bff-templates.js +737 -0
  26. package/dist/generators/nuxt-server/generator.d.ts +7 -0
  27. package/dist/generators/nuxt-server/generator.js +206 -0
  28. package/dist/generators/nuxt-server/parser.d.ts +5 -0
  29. package/dist/generators/nuxt-server/parser.js +5 -0
  30. package/dist/generators/nuxt-server/templates.d.ts +35 -0
  31. package/dist/generators/nuxt-server/templates.js +412 -0
  32. package/dist/generators/nuxt-server/types.d.ts +5 -0
  33. package/dist/generators/nuxt-server/types.js +5 -0
  34. package/dist/generators/shared/parsers/heyapi-parser.d.ts +11 -0
  35. package/dist/generators/shared/parsers/heyapi-parser.js +248 -0
  36. package/dist/generators/shared/parsers/official-parser.d.ts +5 -0
  37. package/dist/generators/shared/parsers/official-parser.js +5 -0
  38. package/dist/generators/shared/runtime/apiHelpers.d.ts +183 -0
  39. package/dist/generators/shared/runtime/apiHelpers.js +268 -0
  40. package/dist/generators/shared/templates/api-callbacks-plugin.d.ts +178 -0
  41. package/dist/generators/shared/templates/api-callbacks-plugin.js +338 -0
  42. package/dist/generators/shared/types.d.ts +25 -0
  43. package/dist/generators/shared/types.js +4 -0
  44. package/dist/generators/tanstack-query/generator.d.ts +5 -0
  45. package/dist/generators/tanstack-query/generator.js +11 -0
  46. package/dist/generators/use-async-data/generator.d.ts +5 -0
  47. package/dist/generators/use-async-data/generator.js +156 -0
  48. package/dist/generators/use-async-data/parser.d.ts +5 -0
  49. package/dist/generators/use-async-data/parser.js +5 -0
  50. package/dist/generators/use-async-data/runtime/useApiAsyncData.d.ts +38 -0
  51. package/dist/generators/use-async-data/runtime/useApiAsyncData.js +122 -0
  52. package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.d.ts +54 -0
  53. package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +126 -0
  54. package/dist/generators/use-async-data/templates.d.ts +20 -0
  55. package/dist/generators/use-async-data/templates.js +191 -0
  56. package/dist/generators/use-async-data/types.d.ts +4 -0
  57. package/dist/generators/use-async-data/types.js +4 -0
  58. package/dist/generators/use-fetch/generator.d.ts +5 -0
  59. package/dist/generators/use-fetch/generator.js +131 -0
  60. package/dist/generators/use-fetch/parser.d.ts +9 -0
  61. package/dist/generators/use-fetch/parser.js +282 -0
  62. package/dist/generators/use-fetch/runtime/useApiRequest.d.ts +46 -0
  63. package/dist/generators/use-fetch/runtime/useApiRequest.js +158 -0
  64. package/dist/generators/use-fetch/templates.d.ts +16 -0
  65. package/dist/generators/use-fetch/templates.js +169 -0
  66. package/dist/generators/use-fetch/types.d.ts +5 -0
  67. package/dist/generators/use-fetch/types.js +5 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +213 -0
  70. package/docs/API-REFERENCE.md +887 -0
  71. package/docs/ARCHITECTURE.md +649 -0
  72. package/docs/DEVELOPMENT.md +918 -0
  73. package/docs/QUICK-START.md +323 -0
  74. package/docs/README.md +155 -0
  75. package/docs/TROUBLESHOOTING.md +881 -0
  76. package/eslint.config.js +72 -0
  77. package/package.json +65 -0
  78. package/src/cli/config.ts +140 -0
  79. package/src/cli/logger.ts +66 -0
  80. package/src/cli/logo.ts +25 -0
  81. package/src/cli/messages.ts +97 -0
  82. package/src/cli/prompts.ts +143 -0
  83. package/src/cli/types.ts +50 -0
  84. package/src/cli/utils.ts +49 -0
  85. package/src/generate.ts +57 -0
  86. package/src/generators/nuxt-server/bff-templates.ts +754 -0
  87. package/src/generators/nuxt-server/generator.ts +270 -0
  88. package/src/generators/nuxt-server/parser.ts +5 -0
  89. package/src/generators/nuxt-server/templates.ts +483 -0
  90. package/src/generators/nuxt-server/types.ts +5 -0
  91. package/src/generators/shared/parsers/heyapi-parser.ts +307 -0
  92. package/src/generators/shared/parsers/official-parser.ts +5 -0
  93. package/src/generators/shared/runtime/apiHelpers.ts +466 -0
  94. package/src/generators/shared/templates/api-callbacks-plugin.ts +352 -0
  95. package/src/generators/shared/types.ts +27 -0
  96. package/src/generators/tanstack-query/generator.ts +11 -0
  97. package/src/generators/use-async-data/generator.ts +204 -0
  98. package/src/generators/use-async-data/parser.ts +5 -0
  99. package/src/generators/use-async-data/runtime/useApiAsyncData.ts +220 -0
  100. package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +236 -0
  101. package/src/generators/use-async-data/templates.ts +250 -0
  102. package/src/generators/use-async-data/types.ts +4 -0
  103. package/src/generators/use-fetch/generator.ts +169 -0
  104. package/src/generators/use-fetch/parser.ts +341 -0
  105. package/src/generators/use-fetch/runtime/useApiRequest.ts +223 -0
  106. package/src/generators/use-fetch/templates.ts +214 -0
  107. package/src/generators/use-fetch/types.ts +5 -0
  108. package/src/index.ts +265 -0
  109. package/tsconfig.json +15 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 - Daniel Martín Díaz
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # 🚀 Nuxt OpenAPI Generator
2
+
3
+ **Generate type-safe, SSR-compatible Nuxt composables from OpenAPI/Swagger specifications.**
4
+
5
+ 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. No third-party runtime, no wrappers: just Nuxt.
6
+
7
+ ---
8
+
9
+ ## ✨ Features
10
+
11
+ - 🔒 **Type-Safe**: Full TypeScript support derived from your OpenAPI schema
12
+ - ⚡ **SSR Compatible**: Works seamlessly with Nuxt server-side rendering
13
+ - 🔄 **Lifecycle Callbacks**: `onRequest`, `onSuccess`, `onError`, `onFinish`
14
+ - 🌐 **Global Callbacks Plugin**: Define callbacks once, apply to all requests
15
+ - 🛡️ **Request Interception**: Modify headers, body, and query params before sending
16
+ - 🎯 **Smart Data Selection**: Pick specific fields with dot notation for nested paths
17
+ - 🤖 **Auto Type Inference**: Transform response data with automatic TypeScript type inference
18
+ - ⚡ **Automatic Generation**: Single command generates all composables and server routes
19
+ - 💚 **100% Nuxt Native**: Generated composables use `useFetch` / `useAsyncData`; server routes use `defineEventHandler` — no third-party runtime required
20
+ - 📦 **Zero Runtime Dependencies**: Generated code only uses Nuxt built-ins
21
+ - 💡 **Developer Experience**: Interactive CLI with smart defaults
22
+
23
+ ---
24
+
25
+ ## 🔧 Generator Engines
26
+
27
+ Two generation engines are available. The CLI will ask you to choose one when running `nxh generate`:
28
+
29
+ | Engine | Tool | Node Native | Best for |
30
+ |--------|------|:---:|----------|
31
+ | **official** | [@openapitools/openapi-generator-cli](https://openapi-generator.tech/) | ❌ Requires Java 11+ | Maximum spec compatibility, enterprise projects |
32
+ | **heyapi** | [@hey-api/openapi-ts](https://heyapi.dev/) | ✅ Yes | Quick setup, CI/CD pipelines, Node-only environments |
33
+
34
+ > 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).
35
+
36
+ You can also pre-select the engine in your `nxh.config.js` — the CLI will skip the prompt entirely:
37
+
38
+ ```js
39
+ // nxh.config.js
40
+ export default {
41
+ generator: 'openapi', // 'openapi' | 'heyapi'
42
+ input: './swagger.yaml',
43
+ output: './api',
44
+ };
45
+ ```
46
+
47
+ ---
48
+
49
+ ## 📦 Installation
50
+
51
+ ```bash
52
+ npm install -g nuxt-openapi-hyperfetch
53
+ # or
54
+ yarn global add nuxt-openapi-hyperfetch
55
+ # or
56
+ pnpm add -g nuxt-openapi-hyperfetch
57
+ ```
58
+
59
+ Or use directly with npx:
60
+
61
+ ```bash
62
+ npx nuxt-openapi-hyperfetch generate
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🚀 Quick Start
68
+
69
+ ### 1. Run the generator
70
+
71
+ ```bash
72
+ nxh generate
73
+ ```
74
+
75
+ The CLI will ask you for:
76
+
77
+ - 📂 Path to your OpenAPI/Swagger file (`.yaml` or `.json`)
78
+ - 📁 Output directory for generated files
79
+ - 🔧 Which generation engine to use (`official` or `heyapi`)
80
+ - ✅ Which composables to generate (`useFetch`, `useAsyncData`, `TanStack Query`, or Nuxt Server Routes)
81
+
82
+ Or pass arguments directly:
83
+
84
+ ```bash
85
+ nxh generate -i ./swagger.yaml -o ./api
86
+ ```
87
+
88
+ ### 2. Generated output
89
+
90
+ ```
91
+ api/
92
+ +-- runtime.ts
93
+ +-- apis/
94
+ │ +-- PetApi.ts
95
+ │ +-- StoreApi.ts
96
+ +-- models/
97
+ │ +-- Pet.ts
98
+ │ +-- Order.ts
99
+ +-- composables/
100
+ +-- use-fetch/
101
+ +-- runtime/
102
+ │ +-- useApiRequest.ts
103
+ +-- composables/
104
+ │ +-- useFetchGetPetById.ts
105
+ │ +-- useFetchAddPet.ts
106
+ +-- index.ts
107
+ ```
108
+
109
+ ### 3. Use in your Nuxt app
110
+
111
+ ```vue
112
+ <script setup lang="ts">
113
+ import { useFetchGetPetById } from '@/api/composables/use-fetch';
114
+
115
+ const { data: pet, pending, error } = useFetchGetPetById(
116
+ { petId: 123 },
117
+ {
118
+ onSuccess: (pet) => console.log('Loaded:', pet.name),
119
+ onError: (err) => console.error('Failed:', err),
120
+ }
121
+ );
122
+ </script>
123
+
124
+ <template>
125
+ <div>
126
+ <div v-if="pending">Loading...</div>
127
+ <div v-else-if="error">Error: {{ error }}</div>
128
+ <div v-else-if="pet">{{ pet.name }} — {{ pet.status }}</div>
129
+ </div>
130
+ </template>
131
+ ```
132
+
133
+ ---
134
+
135
+ ## 🖥️ Nuxt Server Routes Generator
136
+
137
+ 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.
138
+
139
+ ```
140
+ Client → Nuxt Server Route (generated) → External API
141
+ ```
142
+
143
+ After generation, configure your backend URL in `.env`:
144
+
145
+ ```env
146
+ API_BASE_URL=https://your-backend-api.com/api
147
+ API_SECRET=your-secret-token
148
+ ```
149
+
150
+ And add it to `nuxt.config.ts`:
151
+
152
+ ```typescript
153
+ export default defineNuxtConfig({
154
+ runtimeConfig: {
155
+ apiBaseUrl: process.env.API_BASE_URL || '',
156
+ apiSecret: process.env.API_SECRET || '',
157
+ },
158
+ });
159
+ ```
160
+
161
+ Then use standard `useFetch` against your Nuxt routes:
162
+
163
+ ```typescript
164
+ const { data: pet } = useFetch('/api/pet/123');
165
+ ```
166
+
167
+ > **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.
168
+
169
+ ---
170
+
171
+ ## 📚 Documentation
172
+
173
+ | Guide | Description |
174
+ |-------|-------------|
175
+ | [Quick Start Guide](./docs/QUICK-START.md) | Understand the project in 5 minutes |
176
+ | [Architecture](./docs/ARCHITECTURE.md) | Design patterns, two-stage generation, shared code |
177
+ | [API Reference](./docs/API-REFERENCE.md) | All CLI options, TypeScript types, composable APIs |
178
+ | [Development Guide](./docs/DEVELOPMENT.md) | Contributing, adding generators, code style |
179
+ | [Troubleshooting](./docs/TROUBLESHOOTING.md) | Common errors and solutions |
180
+
181
+ ---
182
+
183
+ ## 🤝 Contributing
184
+
185
+ Contributions are welcome! Please read the [Contributing Guidelines](./CONTRIBUTING.md) before submitting a PR.
186
+
187
+ ```bash
188
+ # Development setup
189
+ npm install
190
+ npm run build
191
+ npm run validate # lint + type check
192
+ ```
193
+
194
+ ---
195
+
196
+ ## 📄 License
197
+
198
+ Apache-2.0 — see [LICENSE](./LICENSE) for details.
199
+
200
+ ---
201
+
202
+ **Made with ❤️ for Nuxt developers**
@@ -0,0 +1,57 @@
1
+ import type { GeneratorBackend, ConfigGenerator } from './types.js';
2
+ /**
3
+ * Configuration options for the generator
4
+ */
5
+ export interface GeneratorConfig {
6
+ /** Path or URL to OpenAPI specification */
7
+ input?: string;
8
+ /** Output directory for generated files */
9
+ output?: string;
10
+ /** Base URL for API requests */
11
+ baseUrl?: string;
12
+ /** Generation mode: client or server */
13
+ mode?: 'client' | 'server';
14
+ /** Generate only specific tags */
15
+ tags?: string[];
16
+ /** Exclude specific tags */
17
+ excludeTags?: string[];
18
+ /** Overwrite existing files without prompting */
19
+ overwrite?: boolean;
20
+ /** Preview changes without writing files */
21
+ dryRun?: boolean;
22
+ /** Enable verbose logging */
23
+ verbose?: boolean;
24
+ /** Watch mode - regenerate on file changes */
25
+ watch?: boolean;
26
+ /** Generator types to use */
27
+ generators?: ('useFetch' | 'useAsyncData' | 'nuxtServer')[];
28
+ /** Server route path (for nuxtServer mode) */
29
+ serverRoutePath?: string;
30
+ /** Enable BFF pattern (for nuxtServer mode) */
31
+ enableBff?: boolean;
32
+ /** Generator backend: official (Java) or heyapi (Node.js) */
33
+ backend?: GeneratorBackend;
34
+ /**
35
+ * Generation engine to use.
36
+ * - 'openapi': @openapitools/openapi-generator-cli (requires Java 11+)
37
+ * - 'heyapi': @hey-api/openapi-ts (Node.js native, no Java required)
38
+ * When set, the CLI will not ask which engine to use.
39
+ */
40
+ generator?: ConfigGenerator;
41
+ }
42
+ /**
43
+ * Load configuration from nxh.config.js, nuxt-openapi-generator.config.js, or package.json
44
+ */
45
+ export declare function loadConfig(cwd?: string): Promise<GeneratorConfig | null>;
46
+ /**
47
+ * Merge CLI options with config file, CLI takes precedence
48
+ */
49
+ export declare function mergeConfig(fileConfig: GeneratorConfig | null, cliOptions: Partial<GeneratorConfig>): GeneratorConfig;
50
+ /**
51
+ * Parse comma-separated tags string into array
52
+ */
53
+ export declare function parseTags(tagsString?: string): string[] | undefined;
54
+ /**
55
+ * Parse generators string into array
56
+ */
57
+ export declare function parseGenerators(generatorsString?: string): ('useFetch' | 'useAsyncData' | 'nuxtServer')[] | undefined;
@@ -0,0 +1,85 @@
1
+ import fs from 'fs-extra';
2
+ import { join } from 'path';
3
+ import * as p from '@clack/prompts';
4
+ const { existsSync } = fs;
5
+ /**
6
+ * Load configuration from nxh.config.js, nuxt-openapi-generator.config.js, or package.json
7
+ */
8
+ export async function loadConfig(cwd = process.cwd()) {
9
+ // Try different config file names
10
+ const configFiles = [
11
+ 'nxh.config.js',
12
+ 'nxh.config.mjs',
13
+ 'nuxt-openapi-hyperfetch.js',
14
+ 'nuxt-openapi-hyperfetch.mjs',
15
+ ];
16
+ for (const configFile of configFiles) {
17
+ const configPath = join(cwd, configFile);
18
+ if (existsSync(configPath)) {
19
+ try {
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
21
+ const config = await import(`file://${configPath}`);
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
23
+ const exportedConfig = config.default || config;
24
+ return exportedConfig;
25
+ }
26
+ catch (error) {
27
+ p.log.warn(`Failed to load config from ${configFile}: ${String(error)}`);
28
+ }
29
+ }
30
+ }
31
+ // Try package.json
32
+ const packageJsonPath = join(cwd, 'package.json');
33
+ if (existsSync(packageJsonPath)) {
34
+ try {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
+ const packageJson = await import(`file://${packageJsonPath}`, {
37
+ assert: { type: 'json' },
38
+ });
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
40
+ if (packageJson.default?.['nuxt-openapi-hyperfetch']) {
41
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
42
+ return packageJson.default['nuxt-openapi-hyperfetch'];
43
+ }
44
+ }
45
+ catch {
46
+ // Silently ignore package.json errors
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ /**
52
+ * Merge CLI options with config file, CLI takes precedence
53
+ */
54
+ export function mergeConfig(fileConfig, cliOptions) {
55
+ return {
56
+ ...fileConfig,
57
+ ...cliOptions,
58
+ // Handle arrays specially - CLI should override completely
59
+ tags: cliOptions.tags || fileConfig?.tags,
60
+ excludeTags: cliOptions.excludeTags || fileConfig?.excludeTags,
61
+ generators: cliOptions.generators || fileConfig?.generators,
62
+ };
63
+ }
64
+ /**
65
+ * Parse comma-separated tags string into array
66
+ */
67
+ export function parseTags(tagsString) {
68
+ if (!tagsString) {
69
+ return undefined;
70
+ }
71
+ return tagsString
72
+ .split(',')
73
+ .map((t) => t.trim())
74
+ .filter(Boolean);
75
+ }
76
+ /**
77
+ * Parse generators string into array
78
+ */
79
+ export function parseGenerators(generatorsString) {
80
+ if (!generatorsString) {
81
+ return undefined;
82
+ }
83
+ const parts = generatorsString.split(',').map((g) => g.trim());
84
+ return parts.filter((g) => ['useFetch', 'useAsyncData', 'nuxtServer'].includes(g));
85
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Centralized logging utilities using @clack/prompts
3
+ * Re-exports @clack for easy use across the project
4
+ */
5
+ import * as p from '@clack/prompts';
6
+ /**
7
+ * Re-export @clack/prompts for consistent usage
8
+ */
9
+ export { p };
10
+ /**
11
+ * Create and manage a spinner for long operations
12
+ *
13
+ * @example
14
+ * const spinner = createSpinner();
15
+ * spinner.start('Processing files');
16
+ * // do work
17
+ * spinner.stop('Files processed');
18
+ */
19
+ export declare function createSpinner(): p.SpinnerResult;
20
+ /**
21
+ * Log a success message (replaces console.log with ✓)
22
+ */
23
+ export declare function logSuccess(message: string): void;
24
+ /**
25
+ * Log an error message
26
+ */
27
+ export declare function logError(message: string): void;
28
+ /**
29
+ * Log a warning message
30
+ */
31
+ export declare function logWarning(message: string): void;
32
+ /**
33
+ * Log an info message
34
+ */
35
+ export declare function logInfo(message: string): void;
36
+ /**
37
+ * Display a note/box with multiple lines of information
38
+ * Great for "Next steps" sections
39
+ */
40
+ export declare function logNote(message: string, title?: string): void;
41
+ /**
42
+ * Display section separator
43
+ */
44
+ export declare function logStep(message: string): void;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Centralized logging utilities using @clack/prompts
3
+ * Re-exports @clack for easy use across the project
4
+ */
5
+ import * as p from '@clack/prompts';
6
+ /**
7
+ * Re-export @clack/prompts for consistent usage
8
+ */
9
+ export { p };
10
+ /**
11
+ * Create and manage a spinner for long operations
12
+ *
13
+ * @example
14
+ * const spinner = createSpinner();
15
+ * spinner.start('Processing files');
16
+ * // do work
17
+ * spinner.stop('Files processed');
18
+ */
19
+ export function createSpinner() {
20
+ return p.spinner();
21
+ }
22
+ /**
23
+ * Log a success message (replaces console.log with ✓)
24
+ */
25
+ export function logSuccess(message) {
26
+ p.log.success(message);
27
+ }
28
+ /**
29
+ * Log an error message
30
+ */
31
+ export function logError(message) {
32
+ p.log.error(message);
33
+ }
34
+ /**
35
+ * Log a warning message
36
+ */
37
+ export function logWarning(message) {
38
+ p.log.warn(message);
39
+ }
40
+ /**
41
+ * Log an info message
42
+ */
43
+ export function logInfo(message) {
44
+ p.log.info(message);
45
+ }
46
+ /**
47
+ * Display a note/box with multiple lines of information
48
+ * Great for "Next steps" sections
49
+ */
50
+ export function logNote(message, title) {
51
+ p.note(message, title);
52
+ }
53
+ /**
54
+ * Display section separator
55
+ */
56
+ export function logStep(message) {
57
+ p.log.step(message);
58
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Display the Nuxt logo with gradient colors
3
+ * - Green gradient for Nuxt logo (official Nuxt color #00DC82)
4
+ * - Blue gradient for Swagger subtitle
5
+ */
6
+ export declare function displayLogo(): void;
@@ -0,0 +1,21 @@
1
+ import gradient from 'gradient-string';
2
+ const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
3
+ ████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
4
+ ██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
5
+ ██║╚██╗██║██║ ██║ ██╔██╗ ██║
6
+ ██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
7
+ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
8
+ const SUBTITLE = ' Swagger OpenAPI Generator v1.0';
9
+ /**
10
+ * Display the Nuxt logo with gradient colors
11
+ * - Green gradient for Nuxt logo (official Nuxt color #00DC82)
12
+ * - Blue gradient for Swagger subtitle
13
+ */
14
+ export function displayLogo() {
15
+ const nuxtGradient = gradient('#00DC82', '#00E090');
16
+ const swaggerGradient = gradient('#3B82F6', '#0EA5E9');
17
+ console.log('\n');
18
+ console.log(nuxtGradient(NUXT_LOGO));
19
+ console.log(swaggerGradient(SUBTITLE));
20
+ console.log('\n');
21
+ }