isValidSchema function

bool isValidSchema(
  1. Json? schema, [
  2. Json? root
])

isValidSchema checks whether some Schema is correct, according to the syntax rules of JSON Typedef. In particular, isValidSchema verifies that:

  1. The schema does not have any non-root definitions,
  2. All references point to actually-existing definitions,
  3. All enums are non-empty, and do not contain duplicates,
  4. The properties and optionalProperties of a schema never share properties,
  5. All schemas in mapping are of the properties form,
  6. Schemas in mapping never re-specify the discriminator property If a Map<String,dynamic> passes isValidSchema} then it is a correct JSON Typedef schema. schema The schema to validate root The schema to consider as the "root" schema. If undefined, schema will be used as the root. This is usually what you want to do.

Implementation

bool isValidSchema(Json? schema, [Json? root]) {
  if (schema == null) return false;
  root = root ?? schema;

  if (!_hasValidKeys(schema)) {
    return false;
  }
  if (hasNullable(schema)) {
    if (schema["nullable"] is! bool) {
      return false;
    }
  }
  if (!_isValidSchemaForm(schema, root)) {
    return false;
  }

  return true;
}