Skip to content

Format Validation does not Propagate Correctly #212

Description

@J0R0U

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions