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
I'd like to expose metadata on function parameters through reflection, which can later be used for things like code generators. An example could be defining HTTP APIs using abstract functions which could look like this:
I tried to see if there are other approaches such as defining this in constraints, but those aren't accessible through pkl:reflect.
Solution
Make it possible to add annotations to function parameters.
Alternatives
Add the annotation to the function itself with something like @http.FromPath("location"). Makes it repetitive and moves the annotation away from its target.
Make the function arguments a class and define the annotations on properties. It becomes much more verbose to define things.
The text was updated successfully, but these errors were encountered:
Using a class here actually seems idiomatic to me as a means of declaratively defining inputs and outputs. Functions in Pkl are limited (intentionally). It's actually common to use classes as functions, so much so that there's a named pattern for doing so: Class-as-a-function. I get that it's a good deal more verbose, but I'd argue that's a good thing: in this example it seems like you'd want to be able to add a doc comment to each parameter explaining its purpose/functionality.
I see. And you have guessed correctly that being able to add documentation to parameters was my next problem. Then we will stick with a pattern similar to Class-as-a-function for the input. Thanks!
Problem Definition
I'd like to expose metadata on function parameters through reflection, which can later be used for things like code generators. An example could be defining HTTP APIs using
abstract function
s which could look like this:I tried to see if there are other approaches such as defining this in constraints, but those aren't accessible through
pkl:reflect
.Solution
Make it possible to add annotations to function parameters.
Alternatives
@http.FromPath("location")
. Makes it repetitive and moves the annotation away from its target.The text was updated successfully, but these errors were encountered: