private static void ValidateTopLevel(JToken content)
{
var isObject = content.Type == JTokenType.Object;
if (!isObject)
{
throw new JsonApiException(ErrorType.Client, "Invalid JSON API request content.");
}
var objContent = (JObject)content;
var properties = objContent.Properties().Select(p => p.Name).ToList();
var hasData = properties.Contains("data");
var hasErrors = properties.Contains("errors");
var hasMeta = properties.Contains("meta");
var hasIncluded = properties.Contains("included");
if (!(hasData || hasErrors || hasMeta))
{
throw new JsonApiException(ErrorType.Client, "Invalid JSON API request content.");
}
if (hasData && hasErrors)
{
throw new JsonApiException(ErrorType.Client, "Invalid JSON API request content.");
}
if (!hasData && hasIncluded)
{
throw new JsonApiException(ErrorType.Client, "Invalid JSON API request content.");
}
if (!properties.All(p => _allowedTopLevelMembers.Contains(p)))
{
throw new JsonApiException(ErrorType.Client, "Invalid JSON API request content.");
}
}