-
Notifications
You must be signed in to change notification settings - Fork 786
Add @validate()
decorator for custom validation
#17804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Test this change out locally with the following install scripts (Action run 17043723403) VSCode
Azure CLI
|
Dotnet Test Results 90 files - 45 90 suites - 45 37m 42s ⏱️ - 20m 5s Results for commit 648354d. ± Comparison against base commit d5a9da2. This pull request removes 1905 and adds 651 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
User defined constraints are added in this PR as a runtime-only feature; they will be checked by the ARM engine when the template is deployed, but they are not checked by Bicep at compile time. This was done because we don't have a good way to eval a lambda, and adding such a mechanism (which would also make type inference on |
A second limitation is that while user-defined constraints in ARM support multiple predicates, I couldn't find a way to define a decorator that:
The ARM function will accept a single argument or an even number of arguments, where the even numbered arguments (0-indexed) must be lambdas and the odd numbered arguments must be strings. We don't currently support overloads for decorator functions, which thwarted my plan to fake this by defining three overloads:
and then just adding more overloads in the future as requested. This limitation also seems fine in an experimental feature. |
# Conflicts: # src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
@@ -1056,6 +1050,18 @@ private void ValidateDecorators(IEnumerable<DecoratorSyntax> decoratorSyntaxes, | |||
|
|||
if (decorator is not null) | |||
{ | |||
for (int i = 0; i < decoratorSyntax.Arguments.Length; i++) | |||
{ | |||
var parameterFlags = decorator.Overload.FixedParameters.Length < i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be >
?
Resolves #2922 and resolves #16988
Microsoft Reviewers: Open in CodeFlow