isValidSchema function
isValidSchema checks whether some Schema is correct, according to the syntax rules of JSON Typedef. In particular, isValidSchema verifies that:
- The schema does not have any non-root definitions,
- All references point to actually-existing definitions,
- All enums are non-empty, and do not contain duplicates,
- The
properties
andoptionalProperties
of a schema never share properties, - All schemas in
mapping
are of the properties form, - Schemas in
mapping
never re-specify thediscriminator
property If a Map<String,dynamic> passes isValidSchema} then it is a correct JSON Typedef schema.schema
The schema to validateroot
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;
}