@devlearning/swagger-generator 1.1.16 โ 1.1.18
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/.vscode/launch.json +28 -28
- package/README-OLD.md +209 -209
- package/README.md +277 -277
- package/dist/api.constants.js +22 -22
- package/dist/generator.d.ts +4 -0
- package/dist/generator.js +118 -4
- package/dist/generators-writers/angular/api-angular-writer.js +38 -38
- package/dist/generators-writers/angular/constants.js +24 -24
- package/dist/generators-writers/angular/model-angular-writer.js +6 -6
- package/dist/generators-writers/dart/model-dart-writer.d.ts +1 -0
- package/dist/generators-writers/dart/model-dart-writer.js +15 -14
- package/dist/generators-writers/dart/templates/api.mustache +143 -143
- package/dist/generators-writers/dart/templates/enum.mustache +14 -14
- package/dist/generators-writers/dart/templates/model.mustache +20 -23
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +12 -12
- package/dist/generators-writers/nextjs/constants.js +4 -4
- package/dist/generators-writers/nextjs/model-nextjs-writer.js +6 -6
- package/dist/models/swagger/swagger-component.d.ts +2 -2
- package/dist/models/swagger/swagger-schema.d.ts +1 -0
- package/package.json +49 -49
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +752 -625
- package/src/generators-writers/angular/api-angular-writer.ts +187 -187
- package/src/generators-writers/angular/constants.ts +36 -36
- package/src/generators-writers/angular/model-angular-writer.ts +65 -65
- package/src/generators-writers/angular/normalizator.ts +41 -41
- package/src/generators-writers/dart/api-dart-writer.ts +303 -303
- package/src/generators-writers/dart/model-dart-writer.ts +212 -209
- package/src/generators-writers/dart/models/import-definition-dart.ts +5 -5
- package/src/generators-writers/dart/normalizator.ts +72 -72
- package/src/generators-writers/dart/templates/api.mustache +143 -143
- package/src/generators-writers/dart/templates/enum.mustache +14 -14
- package/src/generators-writers/dart/templates/model.mustache +20 -23
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +157 -157
- package/src/generators-writers/nextjs/constants.ts +5 -5
- package/src/generators-writers/nextjs/model-nextjs-writer.ts +61 -61
- package/src/generators-writers/utils.ts +93 -93
- package/src/index.ts +103 -103
- package/src/models/api-dto.ts +17 -17
- package/src/models/enum-value-dto.ts +3 -3
- package/src/models/model-dto.ts +9 -9
- package/src/models/parameter-dto.ts +7 -7
- package/src/models/property-dto.ts +4 -4
- package/src/models/swagger/swagger-component-property.ts +11 -11
- package/src/models/swagger/swagger-component.ts +17 -17
- package/src/models/swagger/swagger-content.ts +4 -4
- package/src/models/swagger/swagger-info.ts +3 -3
- package/src/models/swagger/swagger-method.ts +7 -7
- package/src/models/swagger/swagger-schema.ts +21 -20
- package/src/models/swagger/swagger.ts +38 -38
- package/src/models/type-dto.ts +7 -7
- package/src/swagger-downloader.ts +46 -46
- package/src/utils/logger.ts +73 -73
- package/src/utils/swagger-validator.ts +89 -89
- package/tsconfig.json +33 -33
- package/dist/templates/api.mustache +0 -29
- package/dist/templates/model.mustache +0 -18
package/README.md
CHANGED
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
# Swagger API Generator
|
|
2
|
-
|
|
3
|
-
Generatore automatico di client API e modelli per **Angular**, **Next.js** e **Flutter/Dart** da specifiche Swagger/OpenAPI.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@devlearning/swagger-generator)
|
|
6
|
-
[](https://opensource.org/licenses/ISC)
|
|
7
|
-
|
|
8
|
-
## ๐ฏ Caratteristiche
|
|
9
|
-
|
|
10
|
-
- โ
**Generazione automatica** di modelli e API da Swagger JSON
|
|
11
|
-
- ๐จ **Multi-framework**: Angular, Next.js, Flutter/Dart
|
|
12
|
-
- ๐ **Type-safe**: Tipizzazione forte per TypeScript e Dart
|
|
13
|
-
- ๐ฆ **Zero dipendenze** nei file generati (configurabile)
|
|
14
|
-
- ๐ **CLI semplice** da usare
|
|
15
|
-
- ๐ **Validazione** del documento Swagger prima della generazione
|
|
16
|
-
- ๐ **Logging strutturato** per debugging
|
|
17
|
-
|
|
18
|
-
## ๐ฆ Installazione
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @devlearning/swagger-generator --save-dev
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## ๐ Utilizzo
|
|
25
|
-
|
|
26
|
-
### Da linea di comando
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx swgen --url <swagger-url> --output <output-dir> --target <angular|next|flutter> [opzioni]
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Esempi
|
|
33
|
-
|
|
34
|
-
#### Angular
|
|
35
|
-
```bash
|
|
36
|
-
npx swgen \
|
|
37
|
-
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
38
|
-
--output src/app/core/autogen \
|
|
39
|
-
--target angular \
|
|
40
|
-
--dateTimeLibrary moment
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
#### Next.js
|
|
44
|
-
```bash
|
|
45
|
-
npx swgen \
|
|
46
|
-
--url https://api.example.com/swagger.json \
|
|
47
|
-
--output src/lib/api \
|
|
48
|
-
--target next \
|
|
49
|
-
--dateTimeLibrary date-fns
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
#### Flutter/Dart
|
|
53
|
-
```bash
|
|
54
|
-
npx swgen \
|
|
55
|
-
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
56
|
-
--output lib/core/api \
|
|
57
|
-
--target flutter \
|
|
58
|
-
--package my_app_name
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Opzioni
|
|
62
|
-
|
|
63
|
-
| Opzione | Alias | Descrizione | Obbligatorio | Default |
|
|
64
|
-
|---------|-------|-------------|--------------|---------|
|
|
65
|
-
| `--url` | `-u` | URL del file swagger.json | โ
| - |
|
|
66
|
-
| `--output` | `-o` | Directory di output | โ
| - |
|
|
67
|
-
| `--target` | `-t` | Framework target (`angular`, `next`, `flutter`) | โ
| - |
|
|
68
|
-
| `--dateTimeLibrary` | `-d` | Libreria date (`moment`, `date-fns`) | โ | `date-fns` |
|
|
69
|
-
| `--package` | `-p` | Nome package (solo Dart/Flutter) | โ | - |
|
|
70
|
-
| `--api-client-name` | `-a` | Nome classe API unificata | โ | - |
|
|
71
|
-
|
|
72
|
-
### ๐ API Client Unificata
|
|
73
|
-
|
|
74
|
-
Di default, il generatore crea classi API separate raggruppate per tag Swagger. Con l'opzione `--api-client-name`, puoi generare una **singola classe unificata** contenente tutti i metodi API.
|
|
75
|
-
|
|
76
|
-
#### Esempio: Flutter con classe unificata
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
npx swgen \
|
|
80
|
-
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
81
|
-
--output lib/core/api \
|
|
82
|
-
--target flutter \
|
|
83
|
-
--package my_app \
|
|
84
|
-
--api-client-name ApiClient
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Genera:
|
|
88
|
-
```dart
|
|
89
|
-
// lib/core/api/api_client.dart
|
|
90
|
-
class ApiClient {
|
|
91
|
-
// Tutti i metodi API in una singola classe
|
|
92
|
-
Future<User> getUser(String id) async { ... }
|
|
93
|
-
Future<List<Product>> getProducts() async { ... }
|
|
94
|
-
Future<void> createOrder(Order order) async { ... }
|
|
95
|
-
// ...
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
#### Senza --api-client-name (comportamento predefinito)
|
|
100
|
-
|
|
101
|
-
Genera classi separate per tag:
|
|
102
|
-
```dart
|
|
103
|
-
// lib/core/api/users_api.dart
|
|
104
|
-
class UsersApi { ... }
|
|
105
|
-
|
|
106
|
-
// lib/core/api/products_api.dart
|
|
107
|
-
class ProductsApi { ... }
|
|
108
|
-
|
|
109
|
-
// lib/core/api/orders_api.dart
|
|
110
|
-
class OrdersApi { ... }
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### Quando usare la classe unificata?
|
|
114
|
-
|
|
115
|
-
- โ
Progetti piccoli/medi con pochi endpoint
|
|
116
|
-
- โ
Quando preferisci un singolo punto di accesso alle API
|
|
117
|
-
- โ
Per semplificare la dependency injection
|
|
118
|
-
|
|
119
|
-
#### Quando usare classi separate?
|
|
120
|
-
|
|
121
|
-
- โ
Progetti grandi con molti endpoint
|
|
122
|
-
- โ
Quando vuoi separare le responsabilitร per dominio
|
|
123
|
-
- โ
Per team diversi che lavorano su moduli diversi
|
|
124
|
-
|
|
125
|
-
## ๐ Struttura File Generati
|
|
126
|
-
|
|
127
|
-
### Angular
|
|
128
|
-
```
|
|
129
|
-
output/
|
|
130
|
-
โโโ models/
|
|
131
|
-
โ โโโ user.model.ts
|
|
132
|
-
โ โโโ product.model.ts
|
|
133
|
-
โ โโโ ...
|
|
134
|
-
โโโ api/
|
|
135
|
-
โโโ user.api.ts
|
|
136
|
-
โโโ product.api.ts
|
|
137
|
-
โโโ ...
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Next.js
|
|
141
|
-
```
|
|
142
|
-
output/
|
|
143
|
-
โโโ models/
|
|
144
|
-
โ โโโ user.ts
|
|
145
|
-
โ โโโ product.ts
|
|
146
|
-
โ โโโ ...
|
|
147
|
-
โโโ api/
|
|
148
|
-
โโโ user-api.ts
|
|
149
|
-
โโโ product-api.ts
|
|
150
|
-
โโโ ...
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Flutter/Dart
|
|
154
|
-
```
|
|
155
|
-
lib/output/
|
|
156
|
-
โโโ user/
|
|
157
|
-
โ โโโ models/
|
|
158
|
-
โ โ โโโ user.dart
|
|
159
|
-
โ โโโ api/
|
|
160
|
-
โ โโโ user_api.dart
|
|
161
|
-
โโโ product/
|
|
162
|
-
โโโ models/
|
|
163
|
-
โ โโโ product.dart
|
|
164
|
-
โโโ api/
|
|
165
|
-
โโโ product_api.dart
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## ๐ง Integrazione nel Progetto
|
|
169
|
-
|
|
170
|
-
### Angular
|
|
171
|
-
|
|
172
|
-
1. Crea un service wrapper:
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
import { Injectable } from '@angular/core';
|
|
176
|
-
import { HttpClient } from '@angular/common/http';
|
|
177
|
-
import { environment } from '@env/environment';
|
|
178
|
-
|
|
179
|
-
@Injectable({ providedIn: 'root' })
|
|
180
|
-
export class ApiService {
|
|
181
|
-
constructor(private http: HttpClient) {}
|
|
182
|
-
|
|
183
|
-
// I tuoi metodi personalizzati qui
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
2. Usa i modelli generati:
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
import { User } from './autogen/models/user.model';
|
|
191
|
-
import { UserApi } from './autogen/api/user.api';
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Next.js
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
import { getUsers } from '@/lib/api/user-api';
|
|
198
|
-
import { User } from '@/lib/api/models/user';
|
|
199
|
-
|
|
200
|
-
export async function UsersPage() {
|
|
201
|
-
const users = await getUsers();
|
|
202
|
-
// ...
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Flutter/Dart
|
|
207
|
-
|
|
208
|
-
```dart
|
|
209
|
-
import 'package:my_app/core/api/user/api/user_api.dart';
|
|
210
|
-
import 'package:my_app/core/api/user/models/user.dart';
|
|
211
|
-
|
|
212
|
-
final userApi = UserApi();
|
|
213
|
-
final users = await userApi.getUsers();
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## ๐ Risoluzione Problemi
|
|
217
|
-
|
|
218
|
-
### Errore: "Swagger validation failed"
|
|
219
|
-
Il documento Swagger non รจ valido. Verifica:
|
|
220
|
-
- Presenza di `openApi` version
|
|
221
|
-
- Presenza di `paths` object
|
|
222
|
-
- Struttura corretta delle definizioni
|
|
223
|
-
|
|
224
|
-
### Errore: "Cannot parse null data"
|
|
225
|
-
L'API restituisce null per un tipo primitivo. Verifica che il backend ritorni sempre un valore valido.
|
|
226
|
-
|
|
227
|
-
### Tipi primitivi non funzionano (Dart)
|
|
228
|
-
โ
**RISOLTO** - Ora il generatore gestisce correttamente String, int, bool, double con conversioni automatiche.
|
|
229
|
-
|
|
230
|
-
## ๐ ๏ธ Sviluppo
|
|
231
|
-
|
|
232
|
-
```bash
|
|
233
|
-
# Clone repository
|
|
234
|
-
git clone <repo-url>
|
|
235
|
-
|
|
236
|
-
# Install dependencies
|
|
237
|
-
npm install
|
|
238
|
-
|
|
239
|
-
# Build
|
|
240
|
-
npm run build
|
|
241
|
-
|
|
242
|
-
# Test local
|
|
243
|
-
npm run debug-angular
|
|
244
|
-
npm run debug-nextjs
|
|
245
|
-
npm run debug-flutter
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## ๐ Script NPM
|
|
249
|
-
|
|
250
|
-
| Script | Descrizione |
|
|
251
|
-
|--------|-------------|
|
|
252
|
-
| `npm run build` | Compila TypeScript e copia templates |
|
|
253
|
-
| `npm run debug-angular` | Test con target Angular |
|
|
254
|
-
| `npm run debug-nextjs` | Test con target Next.js |
|
|
255
|
-
| `npm run debug-flutter` | Test con target Flutter |
|
|
256
|
-
| `npm run deploy` | Pubblica su npm |
|
|
257
|
-
|
|
258
|
-
## ๐ค Contribuire
|
|
259
|
-
|
|
260
|
-
Contributi benvenuti! Per favore:
|
|
261
|
-
1. Fai fork del progetto
|
|
262
|
-
2. Crea un branch per la tua feature (`git checkout -b feature/amazing-feature`)
|
|
263
|
-
3. Commit dei cambiamenti (`git commit -m 'Add amazing feature'`)
|
|
264
|
-
4. Push del branch (`git push origin feature/amazing-feature`)
|
|
265
|
-
5. Apri una Pull Request
|
|
266
|
-
|
|
267
|
-
## ๐ Licenza
|
|
268
|
-
|
|
269
|
-
ISC License - vedi file LICENSE per dettagli
|
|
270
|
-
|
|
271
|
-
## ๐ Crediti
|
|
272
|
-
|
|
273
|
-
Sviluppato da DeVLearninG Team
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
**Note**: Questo tool รจ in sviluppo attivo. Per bug o feature request, apri una issue su GitHub.
|
|
1
|
+
# Swagger API Generator
|
|
2
|
+
|
|
3
|
+
Generatore automatico di client API e modelli per **Angular**, **Next.js** e **Flutter/Dart** da specifiche Swagger/OpenAPI.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@devlearning/swagger-generator)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
|
|
8
|
+
## ๐ฏ Caratteristiche
|
|
9
|
+
|
|
10
|
+
- โ
**Generazione automatica** di modelli e API da Swagger JSON
|
|
11
|
+
- ๐จ **Multi-framework**: Angular, Next.js, Flutter/Dart
|
|
12
|
+
- ๐ **Type-safe**: Tipizzazione forte per TypeScript e Dart
|
|
13
|
+
- ๐ฆ **Zero dipendenze** nei file generati (configurabile)
|
|
14
|
+
- ๐ **CLI semplice** da usare
|
|
15
|
+
- ๐ **Validazione** del documento Swagger prima della generazione
|
|
16
|
+
- ๐ **Logging strutturato** per debugging
|
|
17
|
+
|
|
18
|
+
## ๐ฆ Installazione
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @devlearning/swagger-generator --save-dev
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## ๐ Utilizzo
|
|
25
|
+
|
|
26
|
+
### Da linea di comando
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx swgen --url <swagger-url> --output <output-dir> --target <angular|next|flutter> [opzioni]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Esempi
|
|
33
|
+
|
|
34
|
+
#### Angular
|
|
35
|
+
```bash
|
|
36
|
+
npx swgen \
|
|
37
|
+
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
38
|
+
--output src/app/core/autogen \
|
|
39
|
+
--target angular \
|
|
40
|
+
--dateTimeLibrary moment
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Next.js
|
|
44
|
+
```bash
|
|
45
|
+
npx swgen \
|
|
46
|
+
--url https://api.example.com/swagger.json \
|
|
47
|
+
--output src/lib/api \
|
|
48
|
+
--target next \
|
|
49
|
+
--dateTimeLibrary date-fns
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Flutter/Dart
|
|
53
|
+
```bash
|
|
54
|
+
npx swgen \
|
|
55
|
+
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
56
|
+
--output lib/core/api \
|
|
57
|
+
--target flutter \
|
|
58
|
+
--package my_app_name
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Opzioni
|
|
62
|
+
|
|
63
|
+
| Opzione | Alias | Descrizione | Obbligatorio | Default |
|
|
64
|
+
|---------|-------|-------------|--------------|---------|
|
|
65
|
+
| `--url` | `-u` | URL del file swagger.json | โ
| - |
|
|
66
|
+
| `--output` | `-o` | Directory di output | โ
| - |
|
|
67
|
+
| `--target` | `-t` | Framework target (`angular`, `next`, `flutter`) | โ
| - |
|
|
68
|
+
| `--dateTimeLibrary` | `-d` | Libreria date (`moment`, `date-fns`) | โ | `date-fns` |
|
|
69
|
+
| `--package` | `-p` | Nome package (solo Dart/Flutter) | โ | - |
|
|
70
|
+
| `--api-client-name` | `-a` | Nome classe API unificata | โ | - |
|
|
71
|
+
|
|
72
|
+
### ๐ API Client Unificata
|
|
73
|
+
|
|
74
|
+
Di default, il generatore crea classi API separate raggruppate per tag Swagger. Con l'opzione `--api-client-name`, puoi generare una **singola classe unificata** contenente tutti i metodi API.
|
|
75
|
+
|
|
76
|
+
#### Esempio: Flutter con classe unificata
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx swgen \
|
|
80
|
+
--url http://localhost:5000/swagger/v1/swagger.json \
|
|
81
|
+
--output lib/core/api \
|
|
82
|
+
--target flutter \
|
|
83
|
+
--package my_app \
|
|
84
|
+
--api-client-name ApiClient
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Genera:
|
|
88
|
+
```dart
|
|
89
|
+
// lib/core/api/api_client.dart
|
|
90
|
+
class ApiClient {
|
|
91
|
+
// Tutti i metodi API in una singola classe
|
|
92
|
+
Future<User> getUser(String id) async { ... }
|
|
93
|
+
Future<List<Product>> getProducts() async { ... }
|
|
94
|
+
Future<void> createOrder(Order order) async { ... }
|
|
95
|
+
// ...
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Senza --api-client-name (comportamento predefinito)
|
|
100
|
+
|
|
101
|
+
Genera classi separate per tag:
|
|
102
|
+
```dart
|
|
103
|
+
// lib/core/api/users_api.dart
|
|
104
|
+
class UsersApi { ... }
|
|
105
|
+
|
|
106
|
+
// lib/core/api/products_api.dart
|
|
107
|
+
class ProductsApi { ... }
|
|
108
|
+
|
|
109
|
+
// lib/core/api/orders_api.dart
|
|
110
|
+
class OrdersApi { ... }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Quando usare la classe unificata?
|
|
114
|
+
|
|
115
|
+
- โ
Progetti piccoli/medi con pochi endpoint
|
|
116
|
+
- โ
Quando preferisci un singolo punto di accesso alle API
|
|
117
|
+
- โ
Per semplificare la dependency injection
|
|
118
|
+
|
|
119
|
+
#### Quando usare classi separate?
|
|
120
|
+
|
|
121
|
+
- โ
Progetti grandi con molti endpoint
|
|
122
|
+
- โ
Quando vuoi separare le responsabilitร per dominio
|
|
123
|
+
- โ
Per team diversi che lavorano su moduli diversi
|
|
124
|
+
|
|
125
|
+
## ๐ Struttura File Generati
|
|
126
|
+
|
|
127
|
+
### Angular
|
|
128
|
+
```
|
|
129
|
+
output/
|
|
130
|
+
โโโ models/
|
|
131
|
+
โ โโโ user.model.ts
|
|
132
|
+
โ โโโ product.model.ts
|
|
133
|
+
โ โโโ ...
|
|
134
|
+
โโโ api/
|
|
135
|
+
โโโ user.api.ts
|
|
136
|
+
โโโ product.api.ts
|
|
137
|
+
โโโ ...
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Next.js
|
|
141
|
+
```
|
|
142
|
+
output/
|
|
143
|
+
โโโ models/
|
|
144
|
+
โ โโโ user.ts
|
|
145
|
+
โ โโโ product.ts
|
|
146
|
+
โ โโโ ...
|
|
147
|
+
โโโ api/
|
|
148
|
+
โโโ user-api.ts
|
|
149
|
+
โโโ product-api.ts
|
|
150
|
+
โโโ ...
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Flutter/Dart
|
|
154
|
+
```
|
|
155
|
+
lib/output/
|
|
156
|
+
โโโ user/
|
|
157
|
+
โ โโโ models/
|
|
158
|
+
โ โ โโโ user.dart
|
|
159
|
+
โ โโโ api/
|
|
160
|
+
โ โโโ user_api.dart
|
|
161
|
+
โโโ product/
|
|
162
|
+
โโโ models/
|
|
163
|
+
โ โโโ product.dart
|
|
164
|
+
โโโ api/
|
|
165
|
+
โโโ product_api.dart
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## ๐ง Integrazione nel Progetto
|
|
169
|
+
|
|
170
|
+
### Angular
|
|
171
|
+
|
|
172
|
+
1. Crea un service wrapper:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { Injectable } from '@angular/core';
|
|
176
|
+
import { HttpClient } from '@angular/common/http';
|
|
177
|
+
import { environment } from '@env/environment';
|
|
178
|
+
|
|
179
|
+
@Injectable({ providedIn: 'root' })
|
|
180
|
+
export class ApiService {
|
|
181
|
+
constructor(private http: HttpClient) {}
|
|
182
|
+
|
|
183
|
+
// I tuoi metodi personalizzati qui
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
2. Usa i modelli generati:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { User } from './autogen/models/user.model';
|
|
191
|
+
import { UserApi } from './autogen/api/user.api';
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Next.js
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { getUsers } from '@/lib/api/user-api';
|
|
198
|
+
import { User } from '@/lib/api/models/user';
|
|
199
|
+
|
|
200
|
+
export async function UsersPage() {
|
|
201
|
+
const users = await getUsers();
|
|
202
|
+
// ...
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Flutter/Dart
|
|
207
|
+
|
|
208
|
+
```dart
|
|
209
|
+
import 'package:my_app/core/api/user/api/user_api.dart';
|
|
210
|
+
import 'package:my_app/core/api/user/models/user.dart';
|
|
211
|
+
|
|
212
|
+
final userApi = UserApi();
|
|
213
|
+
final users = await userApi.getUsers();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## ๐ Risoluzione Problemi
|
|
217
|
+
|
|
218
|
+
### Errore: "Swagger validation failed"
|
|
219
|
+
Il documento Swagger non รจ valido. Verifica:
|
|
220
|
+
- Presenza di `openApi` version
|
|
221
|
+
- Presenza di `paths` object
|
|
222
|
+
- Struttura corretta delle definizioni
|
|
223
|
+
|
|
224
|
+
### Errore: "Cannot parse null data"
|
|
225
|
+
L'API restituisce null per un tipo primitivo. Verifica che il backend ritorni sempre un valore valido.
|
|
226
|
+
|
|
227
|
+
### Tipi primitivi non funzionano (Dart)
|
|
228
|
+
โ
**RISOLTO** - Ora il generatore gestisce correttamente String, int, bool, double con conversioni automatiche.
|
|
229
|
+
|
|
230
|
+
## ๐ ๏ธ Sviluppo
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Clone repository
|
|
234
|
+
git clone <repo-url>
|
|
235
|
+
|
|
236
|
+
# Install dependencies
|
|
237
|
+
npm install
|
|
238
|
+
|
|
239
|
+
# Build
|
|
240
|
+
npm run build
|
|
241
|
+
|
|
242
|
+
# Test local
|
|
243
|
+
npm run debug-angular
|
|
244
|
+
npm run debug-nextjs
|
|
245
|
+
npm run debug-flutter
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## ๐ Script NPM
|
|
249
|
+
|
|
250
|
+
| Script | Descrizione |
|
|
251
|
+
|--------|-------------|
|
|
252
|
+
| `npm run build` | Compila TypeScript e copia templates |
|
|
253
|
+
| `npm run debug-angular` | Test con target Angular |
|
|
254
|
+
| `npm run debug-nextjs` | Test con target Next.js |
|
|
255
|
+
| `npm run debug-flutter` | Test con target Flutter |
|
|
256
|
+
| `npm run deploy` | Pubblica su npm |
|
|
257
|
+
|
|
258
|
+
## ๐ค Contribuire
|
|
259
|
+
|
|
260
|
+
Contributi benvenuti! Per favore:
|
|
261
|
+
1. Fai fork del progetto
|
|
262
|
+
2. Crea un branch per la tua feature (`git checkout -b feature/amazing-feature`)
|
|
263
|
+
3. Commit dei cambiamenti (`git commit -m 'Add amazing feature'`)
|
|
264
|
+
4. Push del branch (`git push origin feature/amazing-feature`)
|
|
265
|
+
5. Apri una Pull Request
|
|
266
|
+
|
|
267
|
+
## ๐ Licenza
|
|
268
|
+
|
|
269
|
+
ISC License - vedi file LICENSE per dettagli
|
|
270
|
+
|
|
271
|
+
## ๐ Crediti
|
|
272
|
+
|
|
273
|
+
Sviluppato da DeVLearninG Team
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
**Note**: Questo tool รจ in sviluppo attivo. Per bug o feature request, apri una issue su GitHub.
|
package/dist/api.constants.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
-
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
-
import * as Models from './model.autogenerated';
|
|
4
|
-
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
-
|
|
6
|
-
export const httpOptions = {
|
|
7
|
-
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const httpOptionsMultipart = {};
|
|
11
|
-
|
|
12
|
-
export abstract class ApiAutogeneratedService {
|
|
13
|
-
constructor(
|
|
14
|
-
public _http: HttpClient,
|
|
15
|
-
public _baseUrl: string,
|
|
16
|
-
) { }
|
|
17
|
-
|
|
18
|
-
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
-
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
-
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
-
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
-
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
1
|
+
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
+
import * as Models from './model.autogenerated';
|
|
4
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
+
|
|
6
|
+
export const httpOptions = {
|
|
7
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const httpOptionsMultipart = {};
|
|
11
|
+
|
|
12
|
+
export abstract class ApiAutogeneratedService {
|
|
13
|
+
constructor(
|
|
14
|
+
public _http: HttpClient,
|
|
15
|
+
public _baseUrl: string,
|
|
16
|
+
) { }
|
|
17
|
+
|
|
18
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
23
23
|
`;
|
|
24
24
|
export const API_POST = `}`;
|
package/dist/generator.d.ts
CHANGED
|
@@ -31,6 +31,10 @@ export declare class Generator {
|
|
|
31
31
|
isDate(schema: SwaggerSchema): boolean;
|
|
32
32
|
getObjectName(ref: string): string;
|
|
33
33
|
retrieveComponentProperties(swaggerComponent: SwaggerComponent): PropertyDto[];
|
|
34
|
+
private retrieveComponentPropertiesFlutter;
|
|
35
|
+
private ensureEnumModel;
|
|
36
|
+
private retrieveEnumValuesFlexible;
|
|
37
|
+
private sanitizeEnumCaseName;
|
|
34
38
|
retrieveSchemaProperties(schema: SwaggerSchema): PropertyDto[];
|
|
35
39
|
retrieveEnumValues(name: string, swaggerCopmponent: SwaggerComponent): EnumValueDto[];
|
|
36
40
|
retrieveNestedObjects(usedTypes: TypeDto[]): void;
|