Skip to content

Commit bae5f11

Browse files
committed
add documentation
1 parent ffee32f commit bae5f11

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pkgs/hook/tool/generate_syntax.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ ${classes.join('\n\n')}
9999
print('Generated $outputUri');
100100
}
101101

102+
/// Generates the a class that can serialize/deserialize from a JSON object.
103+
///
104+
/// The sub classes are identified by a `type` property.
102105
List<String> generateSubClasses(JsonSchemas schemas) {
103106
final classes = <String>[];
104107
final typeName = schemas.className;
@@ -149,6 +152,10 @@ extension ${subTypeName}Extension on $typeName {
149152
return classes;
150153
}
151154

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].
152159
String generateClass(
153160
JsonSchemas schemas, {
154161
String? name,
@@ -184,7 +191,7 @@ String generateClass(
184191

185192
if (parentPropertySchemas == null) {
186193
accessors.add(
187-
generateAccessor(
194+
generateGetterAndSetter(
188195
propertyKey,
189196
propertySchemas,
190197
required,
@@ -208,7 +215,7 @@ String generateClass(
208215
parentPropertySchemas?.type != null ||
209216
propertySchemas.className != null;
210217
accessors.add(
211-
generateAccessor(
218+
generateGetterAndSetter(
212219
propertyKey,
213220
propertySchemas,
214221
required,
@@ -309,6 +316,10 @@ ${classes.join('\n\n')}
309316
''';
310317
}
311318

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.
312323
String generateEnumClass(JsonSchemas schemas, {String? name}) {
313324
if (schemas.type != SchemaType.string) {
314325
throw UnimplementedError(schemas.type.toString());
@@ -363,6 +374,9 @@ static const $valueName = $typeName._('$value');
363374
''';
364375
}
365376

377+
/// Generates the Dart type representing the type for a property.
378+
///
379+
/// Used for generating field types, getters, and setters.
366380
String generateDartType(
367381
String propertyKey,
368382
JsonSchemas schemas,
@@ -449,7 +463,8 @@ String generateDartType(
449463
return '$dartTypeNonNullable?';
450464
}
451465

452-
String generateAccessor(
466+
/// Generate getter and setter pairs for a property.
467+
String generateGetterAndSetter(
453468
String propertyKey,
454469
JsonSchemas schemas,
455470
bool required, {

0 commit comments

Comments
 (0)