validateRequestedSchema static method

bool validateRequestedSchema(
  1. ObjectSchema schema
)

Validates the schema to make sure that it conforms to the limitations of the spec.

See also: requestedSchema for a description of the spec limitations.

Implementation

static bool validateRequestedSchema(ObjectSchema schema) {
  if (schema.type != JsonType.object) {
    return false;
  }

  final properties = schema.properties;
  if (properties == null) {
    return true; // No properties to validate.
  }

  for (final propertySchema in properties.values) {
    // Combinators would mean it's not a simple primitive type.
    if (propertySchema.allOf != null ||
        propertySchema.anyOf != null ||
        propertySchema.oneOf != null ||
        propertySchema.not != null) {
      return false;
    }

    switch (propertySchema.type) {
      case JsonType.string:
      case JsonType.num:
      case JsonType.int:
      case JsonType.bool:
      case JsonType
          .enumeration: // ignore: deprecated_member_use_from_same_package
        break;
      case JsonType.object:
      case JsonType.list:
      case JsonType.nil:
      case null:
        // Disallowed, or no type specified.
        return false;
    }
  }

  return true;
}