You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<% template "mytemplate", { "name" : "string", "age": "integer" }, { "optional": "boolean" } %>
<% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>
parameters could be described as shown above. if we are lazy, and just want to validate data is present:
<% template "mytemplate", ["name", "age"], ["optional"] %>
<% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>
in the above , the types are missing and could be anything. code generation may not appreciate this form.
This complements the 'requires' statement. Require is mainly ensuring that the input type to a template is of a given type.
expect is mainly to ensure that fields are present. if requires and expect is used together, expect validates that the fields are present on the given type. there are two forms of usage of expect above... the first checks the types, the second doesn't care.
this will help with the native code generation when validating templates are correctly constructed. for code generation, the 'type' checking version should be used.
The text was updated successfully, but these errors were encountered:
darnocian
changed the title
Add an expect statement to validate certain fields are implemented
Add an expect statement to validate certain fields are provided
Nov 16, 2023
Maybe the above is too complex... could implement:
<% template "mytemplate", validate %>
<% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>
validate can use the 'variable extractor' to identify variables referenced and ensure that they are passed in on the stack. actually, may want to store the metadata when parsing is done. when a new template is parsed that references the template with validation meta, it is able to validate immediately without waiting for the evaluation phase.
parameters could be described as shown above. if we are lazy, and just want to validate data is present:
in the above , the types are missing and could be anything. code generation may not appreciate this form.
This complements the 'requires' statement. Require is mainly ensuring that the input type to a template is of a given type.
expect is mainly to ensure that fields are present. if requires and expect is used together, expect validates that the fields are present on the given type. there are two forms of usage of expect above... the first checks the types, the second doesn't care.
this will help with the native code generation when validating templates are correctly constructed. for code generation, the 'type' checking version should be used.
The text was updated successfully, but these errors were encountered: