I think I've encountered a bug where the Validator.validate parameter validateFormats is not correctly passed to subschema validations.
Example
import 'package:json_schema/json_schema.dart';
void main() {
final workingSchema = JsonSchema.create({
'type': 'string',
'format': 'uri',
}, schemaVersion: SchemaVersion.draft2020_12);
final notWorkingSchema = JsonSchema.create({
'allOf': [
{'type': 'string', 'format': 'uri'},
],
}, schemaVersion: SchemaVersion.draft2020_12);
print(workingSchema.validate('://invalid-uri', validateFormats: true)); // prints 'INVALID, Errors: [# (root): "uri" format not accepted ://invalid-uri]'
print(notWorkingSchema.validate('://invalid-uri', validateFormats: true)); // prints 'VALID'
}
I would expect both of them to print invalid and if I remove the schemaVersion: SchemaVersion.draft2020_12 parameter from the creation of notWorkingSchema the output is as expected.
Solution Idea
Looking at the code I found that in the function _validateAndCaptureEvaluations the validate function is called without passing _validateFormats. By locally changing
final isValid = v.validate(instance).isValid;
to
final isValid = v.validate(instance, validateFormats: _validateFormats).isValid;
the expected output is generated, i.e., both validate invocations in the example report that the instance is invalid.
I have not taken a great deal of time to look into the solution, so I am not aware of any possible side effects and if this is the only place were it is not passed to validate function calls. E.g. possibly _validateNot should also pass validateFormats: _validateFormats too.
Thank you for your help and have a great day!
I think I've encountered a bug where the
Validator.validateparametervalidateFormatsis not correctly passed to subschema validations.Example
I would expect both of them to print invalid and if I remove the
schemaVersion: SchemaVersion.draft2020_12parameter from the creation ofnotWorkingSchemathe output is as expected.Solution Idea
Looking at the code I found that in the function
_validateAndCaptureEvaluationsthevalidatefunction is called without passing_validateFormats. By locally changingto
the expected output is generated, i.e., both
validateinvocations in the example report that the instance is invalid.I have not taken a great deal of time to look into the solution, so I am not aware of any possible side effects and if this is the only place were it is not passed to
validatefunction calls. E.g. possibly_validateNotshould also passvalidateFormats: _validateFormatstoo.Thank you for your help and have a great day!