question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support one-time configuration of expression parameters

See original GitHub issue

Problem

Let’s say I have a request template that looks like this:

@RequestLine("GET /{env}/{resource}")
void getResource(@Param("env") String env, @Param("resource") String resource);

In the application that defines this template, env is configured at startup and will only ever have 1 value (e.g. "production" or "qa") during the application’s lifespan. It would make sense to not have to pass this same value into each call of getResource().

Default methods are of no help here because env still needs to be dynamically set.

Proposal

Support on-time configuration of expression parameters via configuration methods on the client interface:

@Configuration
void setEnv(@Param("env") String env);

@RequestLine("GET /{env}/{resource}")
void getResource(@Param("resource") String resource);

Implementing this is pretty easy (~150 lines).

N.B. this proposal is somewhat similar to https://github.com/OpenFeign/feign/issues/1359.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
kdavisk6commented, May 25, 2021

The more I think about this, the more I like the idea of expanding @Param to be used at the method and class level. Here’s an example:

@Param(value = "tenant", expander = TenantExpander.class)
interface MultiTenantResourceApi {

   @Param(value = "env", expander = EnvironmentExpander.class)
   @RequestLine("GET /{tenant}/{env}/{resource}")
   void getResource(@Param("resource") String resource);
}

This approach meets the initial request, can be included by Contract extensions already out in the ecosystem without modification, and provides full control over how the parameter is resolved.

Changes to make this possible would be limited refactoring the current @Param annotation processor into a dual purpose process that can be registered on the class, method, and parameter:

class ParamAnnotationProcessor implements ParameterAnnotationProcessor, AnnotationProcessor {

   public void process(E annotation, MethodMetadata metadata, int paramIndex) {
   
   }

   public void process(E annotation, MethodMetadata metadata) {

   }
}

@hellproxy does this meet your needs? @velo any feedback?

0reactions
kdavisk6commented, Jun 9, 2021

I don’t see any point on having the @Param if we include this on the builder.

Am I missing something?

I’m looking towards the annotation processor, but we can figure that out later. Let’s move forward with your suggestions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional General Server Parameters - Genesys
For PureConnect Cloud customers only. This parameter determines whether the system provides usage-based billing data for Speech (ASR/TTS). If this parameter is ...
Read more >
Framework Types Supporting Expression Trees
Learn about framework types supporting expression trees, creating expression trees, and techniques for working with expression tree APIs.
Read more >
How to specify the commandline parameter expression to ...
1 of the plugin: $ mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version [INFO] ...
Read more >
16.4. Run-time Configuration - PostgreSQL
One parameter is specified per line. The equal sign between name and value is optional. Whitespace is insignificant and blank lines are ignored....
Read more >
Creating an Amazon EventBridge rule that runs on a schedule
EventBridge supports cron expressions and rate expressions. Rate expressions are simpler to define and cron expressions offer the detailed schedule control.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found