@@ -99,6 +99,9 @@ ${classes.join('\n\n')}
99
99
print ('Generated $outputUri ' );
100
100
}
101
101
102
+ /// Generates the a class that can serialize/deserialize from a JSON object.
103
+ ///
104
+ /// The sub classes are identified by a `type` property.
102
105
List <String > generateSubClasses (JsonSchemas schemas) {
103
106
final classes = < String > [];
104
107
final typeName = schemas.className;
@@ -149,6 +152,10 @@ extension ${subTypeName}Extension on $typeName {
149
152
return classes;
150
153
}
151
154
155
+ /// Generates the a class that can serialize/deserialize from a JSON object.
156
+ ///
157
+ /// May have a super class, but it not distinguishable by a `type` property.
158
+ /// For that case see [generateSubClasses] .
152
159
String generateClass (
153
160
JsonSchemas schemas, {
154
161
String ? name,
@@ -184,7 +191,7 @@ String generateClass(
184
191
185
192
if (parentPropertySchemas == null ) {
186
193
accessors.add (
187
- generateAccessor (
194
+ generateGetterAndSetter (
188
195
propertyKey,
189
196
propertySchemas,
190
197
required ,
@@ -208,7 +215,7 @@ String generateClass(
208
215
parentPropertySchemas? .type != null ||
209
216
propertySchemas.className != null ;
210
217
accessors.add (
211
- generateAccessor (
218
+ generateGetterAndSetter (
212
219
propertyKey,
213
220
propertySchemas,
214
221
required ,
@@ -309,6 +316,10 @@ ${classes.join('\n\n')}
309
316
''' ;
310
317
}
311
318
319
+ /// Generates an open enum class.
320
+ ///
321
+ /// The 'name' or 'type' is an open enum. Static consts are generated for all
322
+ /// known values. Parsing an unknown value doesn't fail.
312
323
String generateEnumClass (JsonSchemas schemas, {String ? name}) {
313
324
if (schemas.type != SchemaType .string) {
314
325
throw UnimplementedError (schemas.type.toString ());
@@ -363,6 +374,9 @@ static const $valueName = $typeName._('$value');
363
374
''' ;
364
375
}
365
376
377
+ /// Generates the Dart type representing the type for a property.
378
+ ///
379
+ /// Used for generating field types, getters, and setters.
366
380
String generateDartType (
367
381
String propertyKey,
368
382
JsonSchemas schemas,
@@ -449,7 +463,8 @@ String generateDartType(
449
463
return '$dartTypeNonNullable ?' ;
450
464
}
451
465
452
- String generateAccessor (
466
+ /// Generate getter and setter pairs for a property.
467
+ String generateGetterAndSetter (
453
468
String propertyKey,
454
469
JsonSchemas schemas,
455
470
bool required , {
0 commit comments