fix: Fix validation regression for base_url and api_key

Fixes #221
spectre-console-remove-di-hacks
Robert Dailey 5 months ago
parent 1fc041253e
commit a341c9f173

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Print more useful diagnostics when there's a connectivity problem to a service (e.g. incorrect
`base_url`).
- Regression that prevented basic validation of `base_url` & `api_key`.
## [6.0.2] - 2023-10-20

@ -4,5 +4,5 @@ namespace Recyclarr.Common.FluentValidation;
public interface IRuntimeValidationService
{
ValidationResult Validate(object instance, params string[] ruleSets);
ValidationResult Validate(object instance, params string[] additionalRuleSets);
}

@ -22,17 +22,15 @@ public class RuntimeValidationService : IRuntimeValidationService
.ToDictionary(x => x.Item2!.GetGenericArguments()[0], x => x.Item1);
}
public ValidationResult Validate(object instance, params string[] ruleSets)
public ValidationResult Validate(object instance, params string[] additionalRuleSets)
{
if (!_validators.TryGetValue(instance.GetType(), out var validator))
{
throw new ValidationException($"No validator is available for type: {instance.GetType().FullName}");
}
IValidatorSelector validatorSelector = ruleSets.Length != 0
? new RulesetValidatorSelector(ruleSets)
: new DefaultValidatorSelector();
var validatorSelector =
new RulesetValidatorSelector([RulesetValidatorSelector.DefaultRuleSetName, ..additionalRuleSets]);
return validator.Validate(new ValidationContext<object>(instance, new PropertyChain(), validatorSelector));
}
}

@ -45,7 +45,7 @@ public class ConfigurationLoader(
log.Warning("Configuration is empty");
}
if (!validator.Validate(config))
if (!validator.Validate(config, YamlValidatorRuleSets.RootConfig))
{
return Array.Empty<IServiceConfiguration>();
}

Loading…
Cancel
Save