@@ -104,6 +104,9 @@ class Openapi {
104
104
/// For use with [useNextGen] .
105
105
final String ? cachePath;
106
106
107
+ /// Use a custom pubspec when running the generator.
108
+ final String ? projectPubspecPath;
109
+
107
110
const Openapi ({
108
111
this .additionalProperties,
109
112
@deprecated this .overwriteExistingFiles,
@@ -123,10 +126,11 @@ class Openapi {
123
126
@deprecated this .alwaysRun = false ,
124
127
this .cachePath,
125
128
this .useNextGen = false ,
129
+ this .projectPubspecPath,
126
130
});
127
- // TODO: Enable assertion error
128
- // : assert(cachePath != null && !useNextGen,
129
- // 'useNextGen should be set when providing cachePath');
131
+ // TODO: Enable assertion error
132
+ // : assert(cachePath != null && !useNextGen,
133
+ // 'useNextGen should be set when providing cachePath');
130
134
}
131
135
132
136
class AdditionalProperties {
@@ -211,19 +215,40 @@ class AdditionalProperties {
211
215
allowUnicodeIdentifiers: map['allowUnicodeIdentifiers' ] ?? false ,
212
216
ensureUniqueParams: map['ensureUniqueParams' ] ?? true ,
213
217
useEnumExtension: map['useEnumExtension' ] ?? true ,
214
- prependFormOrBodyParameters: map['prependFormOrBodyParameters' ] ?? false ,
218
+ prependFormOrBodyParameters:
219
+ map['prependFormOrBodyParameters' ] ?? false ,
215
220
pubAuthor: map['pubAuthor' ],
216
221
pubAuthorEmail: map['pubAuthorEmail' ],
217
222
pubDescription: map['pubDescription' ],
218
223
pubHomepage: map['pubHomepage' ],
219
224
pubName: map['pubName' ],
220
225
pubVersion: map['pubVersion' ],
221
- legacyDiscriminatorBehavior: map['legacyDiscriminatorBehavior' ] ?? true ,
222
- sortModelPropertiesByRequiredFlag: map['sortModelPropertiesByRequiredFlag' ] ?? true ,
226
+ legacyDiscriminatorBehavior:
227
+ map['legacyDiscriminatorBehavior' ] ?? true ,
228
+ sortModelPropertiesByRequiredFlag:
229
+ map['sortModelPropertiesByRequiredFlag' ] ?? true ,
223
230
sortParamsByRequiredFlag: map['sortParamsByRequiredFlag' ] ?? true ,
224
231
sourceFolder: map['sourceFolder' ],
225
- wrapper: EnumTransformer .wrapper (map['wrapper' ]),
232
+ wrapper: EnumTransformer .wrapper (map['wrapper' ]),
226
233
);
234
+
235
+ Map <String , dynamic > toMap () => {
236
+ 'allowUnicodeIdentifiers' : allowUnicodeIdentifiers,
237
+ 'ensureUniqueParams' : ensureUniqueParams,
238
+ 'useEnumExtension' : useEnumExtension,
239
+ 'prependFormOrBodyParameters' : prependFormOrBodyParameters,
240
+ if (pubAuthor != null ) 'pubAuthor' : pubAuthor,
241
+ if (pubAuthorEmail != null ) 'pubAuthorEmail' : pubAuthorEmail,
242
+ if (pubDescription != null ) 'pubDescription' : pubDescription,
243
+ if (pubHomepage != null ) 'pubHomepage' : pubHomepage,
244
+ if (pubName != null ) 'pubName' : pubName,
245
+ if (pubVersion != null ) 'pubVersion' : pubVersion,
246
+ 'legacyDiscriminatorBehavior' : legacyDiscriminatorBehavior,
247
+ 'sortModelPropertiesByRequiredFlag' : sortModelPropertiesByRequiredFlag,
248
+ 'sortParamsByRequiredFlag' : sortParamsByRequiredFlag,
249
+ if (sourceFolder != null ) 'sourceFolder' : sourceFolder,
250
+ 'wrapper' : EnumTransformer .wrapperName (wrapper)
251
+ };
227
252
}
228
253
229
254
/// Allows you to customize how inline schemas are handled or named
@@ -260,6 +285,15 @@ class InlineSchemaOptions {
260
285
refactorAllofInlineSchemas: map['refactorAllofInlineSchemas' ] ?? true ,
261
286
resolveInlineEnums: map['resolveInlineEnums' ] ?? true ,
262
287
);
288
+
289
+ /// A convenience function that simplifies the output to the compiler.
290
+ Map <String , dynamic > toMap () => {
291
+ if (arrayItemSuffix != null ) 'arrayItemSuffix' : arrayItemSuffix! ,
292
+ if (mapItemSuffix != null ) 'mapItemSuffix' : mapItemSuffix! ,
293
+ 'skipSchemaReuse' : skipSchemaReuse,
294
+ 'refactorAllofInlineSchemas' : refactorAllofInlineSchemas,
295
+ 'resolveInlineEnums' : resolveInlineEnums,
296
+ };
263
297
}
264
298
265
299
class DioProperties extends AdditionalProperties {
@@ -304,10 +338,21 @@ class DioProperties extends AdditionalProperties {
304
338
useEnumExtension: useEnumExtension);
305
339
306
340
DioProperties .fromMap (Map <String , dynamic > map)
307
- : dateLibrary = map['dateLibrary' ],
341
+ : dateLibrary = EnumTransformer . dioDateLibrary ( map['dateLibrary' ]) ,
308
342
nullableFields = map['nullableFields' ] as bool ? ,
309
- serializationLibrary = map['serializationLibrary' ],
343
+ serializationLibrary = EnumTransformer .dioSerializationLibrary (
344
+ map['serializationLibrary' ]),
310
345
super .fromMap (map);
346
+
347
+ Map <String , dynamic > toMap () => Map .from (super .toMap ())
348
+ ..addAll ({
349
+ if (dateLibrary != null )
350
+ 'dateLibrary' : EnumTransformer .dioDateLibraryName (dateLibrary! ),
351
+ if (nullableFields != null ) 'nullableFields' : nullableFields,
352
+ if (serializationLibrary != null )
353
+ 'serializationLibrary' :
354
+ EnumTransformer .dioSerializationLibraryName (serializationLibrary! ),
355
+ });
311
356
}
312
357
313
358
class DioAltProperties extends AdditionalProperties {
@@ -372,6 +417,18 @@ class DioAltProperties extends AdditionalProperties {
372
417
pubspecDependencies = map['pubspecDependencies' ],
373
418
pubspecDevDependencies = map['pubspecDevDependencies' ],
374
419
super .fromMap (map);
420
+
421
+ Map <String , dynamic > toMap () => Map .from (super .toMap ())
422
+ ..addAll ({
423
+ if (nullSafe != null ) 'nullSafe' : nullSafe,
424
+ if (nullSafeArrayDefault != null )
425
+ 'nullSafeArrayDefault' : nullSafeArrayDefault,
426
+ if (listAnyOf != null ) 'listAnyOf' : listAnyOf,
427
+ if (pubspecDependencies != null )
428
+ 'pubspecDependencies' : pubspecDependencies,
429
+ if (pubspecDevDependencies != null )
430
+ 'pubspecDevDependencies' : pubspecDevDependencies,
431
+ });
375
432
}
376
433
377
434
enum DioDateLibrary {
@@ -387,7 +444,6 @@ enum DioSerializationLibrary { built_value, json_serializable }
387
444
388
445
enum SerializationFormat { JSON , PROTO }
389
446
390
-
391
447
/// The name of the generator to use
392
448
enum Generator {
393
449
/// This generator uses the default http package that comes with dart
@@ -412,12 +468,47 @@ enum Generator {
412
468
// remove this work around.
413
469
/// Transforms the enums used with the [Openapi] annotation.
414
470
class EnumTransformer {
471
+ static DioDateLibrary dioDateLibrary (String ? name) {
472
+ switch (name) {
473
+ case 'timemachine' :
474
+ return DioDateLibrary .timemachine;
475
+ default :
476
+ return DioDateLibrary .core;
477
+ }
478
+ }
479
+
480
+ static String dioDateLibraryName (DioDateLibrary lib) {
481
+ switch (lib) {
482
+ case DioDateLibrary .timemachine:
483
+ return 'timemachine' ;
484
+ default :
485
+ return 'core' ;
486
+ }
487
+ }
488
+
489
+ static DioSerializationLibrary dioSerializationLibrary (String ? name) {
490
+ switch (name) {
491
+ case 'json_serializable' :
492
+ return DioSerializationLibrary .json_serializable;
493
+ default :
494
+ return DioSerializationLibrary .built_value;
495
+ }
496
+ }
497
+
498
+ static String dioSerializationLibraryName (DioSerializationLibrary lib) {
499
+ switch (lib) {
500
+ case DioSerializationLibrary .json_serializable:
501
+ return 'json_serializable' ;
502
+ default :
503
+ return 'built_value' ;
504
+ }
505
+ }
506
+
415
507
/// Converts the given [name] to the matching [Generator] name.
416
508
///
417
509
/// Defaults to [Generator.dart] ;
418
510
static Generator generator (String ? name) {
419
- print (name);
420
- switch (name) {
511
+ switch (name) {
421
512
case 'dio' :
422
513
return Generator .dio;
423
514
case 'dioAlt' :
@@ -427,11 +518,22 @@ class EnumTransformer {
427
518
}
428
519
}
429
520
521
+ static String generatorName (Generator generator) {
522
+ switch (generator) {
523
+ case Generator .dio:
524
+ return 'dart-dio' ;
525
+ case Generator .dioAlt:
526
+ return 'dart2-api' ;
527
+ default :
528
+ return 'dart' ;
529
+ }
530
+ }
531
+
430
532
/// Converts the given [name] to the matching [Wrapper] name.
431
533
///
432
534
/// Defaults to [Wrapper.none] ;
433
535
static Wrapper wrapper (String ? name) {
434
- switch (name) {
536
+ switch (name) {
435
537
case 'fvm' :
436
538
return Wrapper .fvm;
437
539
case 'flutterw' :
@@ -440,6 +542,17 @@ class EnumTransformer {
440
542
return Wrapper .none;
441
543
}
442
544
}
545
+
546
+ static String wrapperName (Wrapper wrapper) {
547
+ switch (wrapper) {
548
+ case Wrapper .flutterw:
549
+ return 'flutterw' ;
550
+ case Wrapper .fvm:
551
+ return 'fvm' ;
552
+ default :
553
+ return 'none' ;
554
+ }
555
+ }
443
556
}
444
557
445
558
enum Wrapper { fvm, flutterw, none }
0 commit comments