Support parameter descriptions & validation
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
We should support declaring descriptions and validation for parameter values. These would be hooked up to the prompt for parameter values on the dashboard and integrated into the publish/deploy experience. All current locations where parameter values are manually validated and an exception is thrown if the value is invalid would instead be handled centrally via the parameter system itself (i.e. parameter values would be validated during initialization and accessing `GetValueAsync()` or `Value` on a parameter would auto-throw an exception with the validation issue details).
We should consider simply using the `System.ComponentModel.DataAnnotations.ValidationAttribute` types in the BCL (along with the `Validator.TryValidateValue` method). Open question as to whether we wrap this with an interface and adapter to enable other kinds of validation to be used (similar to MVC). It might be nice to allow custom validation to be implemented as an inline lambda passed to builder methods but we could still support that via a custom `ValidationAttribute` (or just directly, e.g. `Func`) rather than introduce a new abstraction.
How it might look:
```csharp
builder.AddParameter("service-url")
.WithDescription("The URL for the service.")
.WithValidation(new StringLengthAttribute(255) { MinimumLength = 5 })
.WithValidation(value =>
{
if (!Uri.TryCreate(value, UriKind.Absolute, our var uri)
|| !string.Equals(uri.PathAndQuery, "/", StringComparison.OrdinalIgnoreCase)
|| !string.IsNullOrEmpty(uri.Fragment)
|| !string.Equals(uri.Scheme, "https", StringComparison.OrdinalIgnoreCase) {
return new ValidationResult("Value for parameter {0} must be an absolute root HTTPS URL.");
}
return ValidationResult.Success;
});
```
Contributor guide
Assessment
This issue has not been assessed yet.