Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid nullable schemaPath and instancePath #197

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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