Skip to content

Commit

Permalink
feat(luthor_generator): remove need for validate method
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Jun 25, 2024
1 parent 64010a1 commit 629cc45
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions packages/luthor_generator/lib/generators/luthor_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {
);
}

final validateMethod = element.getMethod('validate');
final isInvalidMethod = validateMethod == null ||
!validateMethod.isStatic ||
validateMethod.parameters.length != 1 ||
validateMethod.parameters.first.type.toString() !=
'Map<String, dynamic>' ||
validateMethod.returnType.toString() != 'SchemaValidationResult<$name>';
if (isInvalidMethod) {
throw InvalidGenerationSourceError(
'Luthor can only be applied to classes with a static validate method. '
'Add the following code to your class:\n'
'static SchemaValidationResult<$name> validate(Map<String, dynamic> json) => _\$${name}Validate(json);',
element: element,
);
}

final params = constructor.parameters;
final buffer = StringBuffer();
buffer.write('Validator \$${name}Schema = l.schema({\n');
Expand Down Expand Up @@ -84,7 +68,7 @@ class LuthorGenerator extends GeneratorForAnnotation<Luthor> {

void _writeValidateMethod(StringBuffer buffer, String name) {
buffer.write(
'SchemaValidationResult<$name> _\$${name}Validate(Map<String, dynamic> json) => '
'SchemaValidationResult<$name> \$${name}Validate(Map<String, dynamic> json) => '
'\$${name}Schema.validateSchema(json, fromJson: $name.fromJson);',
);
}
Expand Down

0 comments on commit 629cc45

Please sign in to comment.