public SchemaValidationResult Validate(object model) { var data = model as QueryRequest; var result = new SchemaValidationResult(); var location = "QueryRequest"; result.MissingCheck($"Issuer", data.Issuer, location); result.MissingCheck($"Issuer.Type", data.Issuer.Type, location); result.MaxRangeCheck($"Issuer.Type", data.Issuer.Type, location, SchemaValidationResult.DEFAULT_MAX_LENGTH); var identityValidator = _validatorFactory.GetIdentityValidator(data.Issuer); identityValidator.Validate("Issuer", data.Issuer, data, "QueryRequest", result); result.MaxRangeCheck($"Types", data.Types.Count, location, 127); var index = 0; foreach (var type in data.Types) { result.MaxRangeCheck($"Types[{index}]", type, location, 127); index++; } result.MaxRangeCheck($"Subjects", data.Subjects.Count, location, 1024); index = 0; foreach (var subject in data.Subjects) { result.MaxRangeCheck($"Subjects[{index}]", subject, location, 127); index++; } return(result); }
private void ValidateIdentity(string name, Identity identity, Claim claim, string location) { var missing = result.MissingCheck($"{name} Type", identity.Type, location); result.MaxRangeCheck($"{name} Type", identity.Type, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH); missing |= result.MissingCheck(name + " Id", identity.Id, location); if (missing) { return; } var validator = _validatorFactory.GetIdentityValidator(identity); if (validator == null) { result.Errors.Add(string.Format(SchemaValidationResult.NotSupportedErrorTemplate, location, $"{name} Type")); return; } validator.Validate(name, identity, claim, location, result); }