Skip to content
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

Qute: support named parameters #31830

Open
FroMage opened this issue Mar 14, 2023 · 1 comment
Open

Qute: support named parameters #31830

FroMage opened this issue Mar 14, 2023 · 1 comment
Labels
area/qute The template engine kind/enhancement New feature or request

Comments

@FroMage
Copy link
Member

FroMage commented Mar 14, 2023

Description

I'd like to be able to pass parameters by name on function calls.

This may not be very useful for Java methods, who don't support optional parameters, but for "virtual" functions, it can be very useful.

For example, the uri:Class.method() functions in Renarde, for obtaining a URI from a method name, would benefit greatly from named parameters. Consider the following JAX-RS method:

static class Container {
 @RestForm
 String userName;
 @RestHeader
 String authorization;
}

@Path("/something/{id}")
@POST
public void endpoint(@RestPath String id, @RestForm String name, @BeanParam Container otherParams){}

The "Java-like" syntax for invoking that method would be: {uri:Class.endpoint(id, null, null), given that form parameters and headers don't participate in URI, so we could even shorten it to {uri:Class.endpoint(id)} but that forces us to declare all parameters that participate in URI to the start of the method signature.

Now consider this declaration form:

static class Container {
 @RestForm
 String userName;
 @RestHeader
 String authorization;
 @RestQuery
 boolean nice;
}

@Path("/something/{id}")
@POST
public void endpoint(@RestPath String id, @RestForm String name, @BeanParam Container otherParams){}

With an optional query param in the container. One way of passing it could be:

{#let container=new Container(null, null, true)}
 {uri:Class.endpoint(id, null, container)}
{/let}

(forgetting a minute we can't call new in Qute). But this is not nice. We could also come back to the idea of moving every parameter that participates in URI up and call {uri:Class.endpoint(id, true)} but this not very obvious.

Perhaps the most intuitive way to solve this would be to support named parameters:

{uri:Class.endpoint(id: id, nice: true)}
// or
{uri:Class.endpoint(id=id, nice=true)}

Implementation ideas

No response

@FroMage FroMage added the kind/enhancement New feature or request label Mar 14, 2023
@quarkus-bot quarkus-bot bot added the area/qute The template engine label Mar 14, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 14, 2023

/cc @mkouba (qute)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant