@@ -54,7 +54,6 @@ class Openapi {
54
54
/// --reserved-words-mappings
55
55
final Map <String , String >? reservedWordsMappings;
56
56
57
-
58
57
/// Tells openapi-generator to always run during the build process
59
58
/// if set to false (the default), openapi-generator will skip processing if the [outputDirectory] already exists
60
59
final bool ? alwaysRun;
@@ -105,27 +104,29 @@ class Openapi {
105
104
/// For use with [useNextGen] .
106
105
final String ? cachePath;
107
106
108
- const Openapi (
109
- {this .additionalProperties,
110
- @deprecated
111
- this .overwriteExistingFiles,
112
- this .skipSpecValidation = false ,
113
- required this .inputSpecFile,
114
- this .templateDirectory,
115
- required this .generatorName,
116
- this .outputDirectory,
117
- this .typeMappings,
118
- this .importMappings,
119
- this .reservedWordsMappings,
120
- this .inlineSchemaNameMappings,
121
- // this.inlineSchemaOptions,
122
- this .apiPackage,
123
- this .fetchDependencies = true ,
124
- this .runSourceGenOnOutput = true ,
125
- @deprecated
126
- this .alwaysRun = false ,
127
- this .cachePath,
128
- this .useNextGen = false ,}): assert (cachePath != null && ! useNextGen, 'useNextGen should be set when providing cachePath' );
107
+ const Openapi ({
108
+ this .additionalProperties,
109
+ @deprecated this .overwriteExistingFiles,
110
+ this .skipSpecValidation = false ,
111
+ required this .inputSpecFile,
112
+ this .templateDirectory,
113
+ required this .generatorName,
114
+ this .outputDirectory,
115
+ this .typeMappings,
116
+ this .importMappings,
117
+ this .reservedWordsMappings,
118
+ this .inlineSchemaNameMappings,
119
+ // this.inlineSchemaOptions,
120
+ this .apiPackage,
121
+ this .fetchDependencies = true ,
122
+ this .runSourceGenOnOutput = true ,
123
+ @deprecated this .alwaysRun = false ,
124
+ this .cachePath,
125
+ this .useNextGen = false ,
126
+ });
127
+ // TODO: Enable assertion error
128
+ // : assert(cachePath != null && !useNextGen,
129
+ // 'useNextGen should be set when providing cachePath');
129
130
}
130
131
131
132
class AdditionalProperties {
@@ -186,22 +187,43 @@ class AdditionalProperties {
186
187
/// an error if the discriminator is missing.
187
188
final bool legacyDiscriminatorBehavior;
188
189
189
- const AdditionalProperties (
190
- {this .allowUnicodeIdentifiers = false ,
191
- this .ensureUniqueParams = true ,
192
- this .useEnumExtension = false ,
193
- this .prependFormOrBodyParameters = false ,
194
- this .pubAuthor,
195
- this .pubAuthorEmail,
196
- this .pubDescription,
197
- this .pubHomepage,
198
- this .legacyDiscriminatorBehavior = true ,
199
- this .pubName,
200
- this .pubVersion,
201
- this .sortModelPropertiesByRequiredFlag = true ,
202
- this .sortParamsByRequiredFlag = true ,
203
- this .sourceFolder,
204
- this .wrapper = Wrapper .none});
190
+ const AdditionalProperties ({
191
+ this .allowUnicodeIdentifiers = false ,
192
+ this .ensureUniqueParams = true ,
193
+ this .useEnumExtension = false ,
194
+ this .prependFormOrBodyParameters = false ,
195
+ this .pubAuthor,
196
+ this .pubAuthorEmail,
197
+ this .pubDescription,
198
+ this .pubHomepage,
199
+ this .legacyDiscriminatorBehavior = true ,
200
+ this .pubName,
201
+ this .pubVersion,
202
+ this .sortModelPropertiesByRequiredFlag = true ,
203
+ this .sortParamsByRequiredFlag = true ,
204
+ this .sourceFolder,
205
+ this .wrapper = Wrapper .none,
206
+ });
207
+
208
+ /// Produces an [AdditionalProperties] object from the [ConstantReader] [map] .
209
+ AdditionalProperties .fromMap (Map <String , dynamic > map)
210
+ : this (
211
+ allowUnicodeIdentifiers: map['allowUnicodeIdentifiers' ] ?? false ,
212
+ ensureUniqueParams: map['ensureUniqueParams' ] ?? true ,
213
+ useEnumExtension: map['useEnumExtension' ] ?? true ,
214
+ prependFormOrBodyParameters: map['prependFormOrBodyParameters' ] ?? false ,
215
+ pubAuthor: map['pubAuthor' ],
216
+ pubAuthorEmail: map['pubAuthorEmail' ],
217
+ pubDescription: map['pubDescription' ],
218
+ pubHomepage: map['pubHomepage' ],
219
+ pubName: map['pubName' ],
220
+ pubVersion: map['pubVersion' ],
221
+ legacyDiscriminatorBehavior: map['legacyDiscriminatorBehavior' ] ?? true ,
222
+ sortModelPropertiesByRequiredFlag: map['sortModelPropertiesByRequiredFlag' ] ?? true ,
223
+ sortParamsByRequiredFlag: map['sortParamsByRequiredFlag' ] ?? true ,
224
+ sourceFolder: map['sourceFolder' ],
225
+ wrapper: EnumTransformer .wrapper (map['wrapper' ]),
226
+ );
205
227
}
206
228
207
229
/// Allows you to customize how inline schemas are handled or named
@@ -216,10 +238,10 @@ class InlineSchemaOptions {
216
238
final bool skipSchemaReuse;
217
239
218
240
/// will restore the 6.x (or below) behaviour to refactor allOf inline schemas
219
- ///into $ref. (v7.0.0 will skip the refactoring of these allOf inline schmeas by default)
241
+ ///into $ref. (v7.0.0 will skip the refactoring of these allOf inline schemas by default)
220
242
final bool refactorAllofInlineSchemas;
221
243
222
- /// Email address of the author in generated pubspec
244
+ /// Email address of the author in generated pubspec
223
245
final bool resolveInlineEnums;
224
246
225
247
const InlineSchemaOptions (
@@ -228,6 +250,16 @@ class InlineSchemaOptions {
228
250
this .skipSchemaReuse = true ,
229
251
this .refactorAllofInlineSchemas = true ,
230
252
this .resolveInlineEnums = true });
253
+
254
+ /// Produces an [InlineSchemaOptions] that is easily consumable from the [ConstantReader] .
255
+ InlineSchemaOptions .fromMap (Map <String , dynamic > map)
256
+ : this (
257
+ arrayItemSuffix: map['arrayItemSuffix' ],
258
+ mapItemSuffix: map['mapItemSuffix' ],
259
+ skipSchemaReuse: map['skipSchemaReuse' ] ?? true ,
260
+ refactorAllofInlineSchemas: map['refactorAllofInlineSchemas' ] ?? true ,
261
+ resolveInlineEnums: map['resolveInlineEnums' ] ?? true ,
262
+ );
231
263
}
232
264
233
265
class DioProperties extends AdditionalProperties {
@@ -270,6 +302,12 @@ class DioProperties extends AdditionalProperties {
270
302
sortParamsByRequiredFlag: sortParamsByRequiredFlag,
271
303
sourceFolder: sourceFolder,
272
304
useEnumExtension: useEnumExtension);
305
+
306
+ DioProperties .fromMap (Map <String , dynamic > map)
307
+ : dateLibrary = map['dateLibrary' ],
308
+ nullableFields = map['nullableFields' ] as bool ? ,
309
+ serializationLibrary = map['serializationLibrary' ],
310
+ super .fromMap (map);
273
311
}
274
312
275
313
class DioAltProperties extends AdditionalProperties {
@@ -326,6 +364,14 @@ class DioAltProperties extends AdditionalProperties {
326
364
sortParamsByRequiredFlag: sortParamsByRequiredFlag,
327
365
sourceFolder: sourceFolder,
328
366
useEnumExtension: useEnumExtension);
367
+
368
+ DioAltProperties .fromMap (Map <String , dynamic > map)
369
+ : nullSafe = map['nullSafe' ] as bool ? ,
370
+ nullSafeArrayDefault = map['nullSafeArrayDefault' ] as bool ? ,
371
+ listAnyOf = map['listAnyOf' ] as bool ? ,
372
+ pubspecDependencies = map['pubspecDependencies' ],
373
+ pubspecDevDependencies = map['pubspecDevDependencies' ],
374
+ super .fromMap (map);
329
375
}
330
376
331
377
enum DioDateLibrary {
@@ -341,6 +387,7 @@ enum DioSerializationLibrary { built_value, json_serializable }
341
387
342
388
enum SerializationFormat { JSON , PROTO }
343
389
390
+
344
391
/// The name of the generator to use
345
392
enum Generator {
346
393
/// This generator uses the default http package that comes with dart
@@ -361,4 +408,38 @@ enum Generator {
361
408
dioAlt,
362
409
}
363
410
411
+ // TODO: Upon release of NextGen as default migrate to sdk 2.17 for enhanced enums
412
+ // remove this work around.
413
+ /// Transforms the enums used with the [Openapi] annotation.
414
+ class EnumTransformer {
415
+ /// Converts the given [name] to the matching [Generator] name.
416
+ ///
417
+ /// Defaults to [Generator.dart] ;
418
+ static Generator generator (String ? name) {
419
+ print (name);
420
+ switch (name) {
421
+ case 'dio' :
422
+ return Generator .dio;
423
+ case 'dioAlt' :
424
+ return Generator .dioAlt;
425
+ default :
426
+ return Generator .dart;
427
+ }
428
+ }
429
+
430
+ /// Converts the given [name] to the matching [Wrapper] name.
431
+ ///
432
+ /// Defaults to [Wrapper.none] ;
433
+ static Wrapper wrapper (String ? name) {
434
+ switch (name) {
435
+ case 'fvm' :
436
+ return Wrapper .fvm;
437
+ case 'flutterw' :
438
+ return Wrapper .flutterw;
439
+ default :
440
+ return Wrapper .none;
441
+ }
442
+ }
443
+ }
444
+
364
445
enum Wrapper { fvm, flutterw, none }
0 commit comments