Skip to content

Commit

Permalink
Merge pull request #197 from jonasfj/avoid-nullable-paths
Browse files Browse the repository at this point in the history
Avoid nullable `schemaPath` and `instancePath`
  • Loading branch information
rm-astro-wf authored Oct 17, 2024
2 parents c172a12 + f24d597 commit 2f8c56e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/src/json_schema/validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ class ValidationError {
ValidationError._(this.instancePath, this.schemaPath, this.message);

/// Path in the instance data to the key where this error occurred
String? instancePath;
String instancePath;

/// Path to the key in the schema containing the rule that produced this error
String? schemaPath;
String schemaPath;

/// A human-readable message explaining why validation failed
String message;

@override
toString() => '${instancePath!.isEmpty ? '# (root)' : instancePath}: $message';
toString() => '${instancePath.isEmpty ? '# (root)' : instancePath}: $message';
}

/// Initialized with schema, validates instances against it
Expand Down Expand Up @@ -855,14 +855,14 @@ class Validator {
return oldParent;
}

void _err(String msg, String? instancePath, String schemaPath) {
void _err(String msg, String instancePath, String schemaPath) {
schemaPath = schemaPath.replaceFirst('#', '');
_errors.add(ValidationError._(instancePath, schemaPath, msg));
if (!_reportMultipleErrors) throw FormatException(msg);
}

void _warn(String msg, String? instancePath, String? schemaPath) {
schemaPath = schemaPath?.replaceFirst('#', '');
void _warn(String msg, String instancePath, String schemaPath) {
schemaPath = schemaPath.replaceFirst('#', '');
_warnings.add(ValidationError._(instancePath, schemaPath, msg));
}

Expand Down

0 comments on commit 2f8c56e

Please sign in to comment.