15
15
16
16
package software .amazon .smithy .typescript .codegen .integration ;
17
17
18
+ import java .util .ArrayList ;
19
+ import java .util .List ;
18
20
import java .util .Objects ;
19
21
import java .util .Optional ;
20
22
import java .util .Set ;
26
28
import software .amazon .smithy .model .shapes .OperationShape ;
27
29
import software .amazon .smithy .model .shapes .ServiceShape ;
28
30
import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
31
+ import software .amazon .smithy .utils .ListUtils ;
29
32
import software .amazon .smithy .utils .SmithyBuilder ;
30
33
import software .amazon .smithy .utils .StringUtils ;
31
34
import software .amazon .smithy .utils .ToSmithyBuilder ;
@@ -44,6 +47,7 @@ public final class RuntimeClientPlugin implements ToSmithyBuilder<RuntimeClientP
44
47
private final SymbolReference inputConfig ;
45
48
private final SymbolReference resolvedConfig ;
46
49
private final SymbolReference resolveFunction ;
50
+ private final List <String > additionalResolveFunctionParameters ;
47
51
private final SymbolReference pluginFunction ;
48
52
private final SymbolReference destroyFunction ;
49
53
private final BiPredicate <Model , ServiceShape > servicePredicate ;
@@ -53,11 +57,16 @@ private RuntimeClientPlugin(Builder builder) {
53
57
inputConfig = builder .inputConfig ;
54
58
resolvedConfig = builder .resolvedConfig ;
55
59
resolveFunction = builder .resolveFunction ;
60
+ additionalResolveFunctionParameters = ListUtils .copyOf (builder .additionalResolveFunctionParameters );
56
61
pluginFunction = builder .pluginFunction ;
57
62
destroyFunction = builder .destroyFunction ;
58
63
operationPredicate = builder .operationPredicate ;
59
64
servicePredicate = builder .servicePredicate ;
60
65
66
+ if (!additionalResolveFunctionParameters .isEmpty () && resolveFunction == null ) {
67
+ throw new IllegalStateException ("Additional parameters can only be set if a resolve function is set." );
68
+ }
69
+
61
70
boolean allNull = (inputConfig == null ) && (resolvedConfig == null ) && (resolveFunction == null );
62
71
boolean allSet = (inputConfig != null ) && (resolvedConfig != null ) && (resolveFunction != null );
63
72
if (!(allNull || allSet )) {
@@ -140,17 +149,32 @@ public Optional<SymbolReference> getResolvedConfig() {
140
149
* <p>If the plugin has a resolve function, then it also must define a
141
150
* <em>resolved interface</em> and a <em>resolve function</em>.
142
151
* The referenced function must accept the input type of the plugin
143
- * as the first positional argument and return the resolved interface
144
- * as the return value.
152
+ * as the first positional argument and optional parameters as additional
153
+ * positional arguments, and return the resolved interface as the return
154
+ * value.
145
155
*
146
156
* @return Returns the optionally present resolve function.
147
157
* @see #getInputConfig()
158
+ * @see #getAdditionalResolveFunctionParameters()
148
159
* @see #getResolvedConfig()
149
160
*/
150
161
public Optional <SymbolReference > getResolveFunction () {
151
162
return Optional .ofNullable (resolveFunction );
152
163
}
153
164
165
+ /**
166
+ * Gets a list of additional parameters to be supplied to the
167
+ * resolve function. These parameters are to be supplied to resolve
168
+ * function as Nth(N > 1) positional arguments. The list is empty if
169
+ * there are no additional parameters.
170
+ *
171
+ * @return Returns the optionally present list of parameters.
172
+ * @see #getResolveFunction()
173
+ */
174
+ public List <String > getAdditionalResolveFunctionParameters () {
175
+ return additionalResolveFunctionParameters ;
176
+ }
177
+
154
178
/**
155
179
* Gets the optionally present symbol reference that points to the
156
180
* function that injects plugin middleware into the middleware stack
@@ -255,6 +279,7 @@ public String toString() {
255
279
+ "inputConfig=" + inputConfig
256
280
+ ", resolvedConfig=" + resolvedConfig
257
281
+ ", resolveFunction=" + resolveFunction
282
+ + ", additionalResolveFunctionParameters=" + additionalResolveFunctionParameters
258
283
+ ", pluginFunction=" + pluginFunction
259
284
+ ", destroyFunction=" + destroyFunction
260
285
+ '}' ;
@@ -272,6 +297,7 @@ public boolean equals(Object o) {
272
297
return Objects .equals (inputConfig , that .inputConfig )
273
298
&& Objects .equals (resolvedConfig , that .resolvedConfig )
274
299
&& Objects .equals (resolveFunction , that .resolveFunction )
300
+ && Objects .equals (additionalResolveFunctionParameters , that .additionalResolveFunctionParameters )
275
301
&& Objects .equals (pluginFunction , that .pluginFunction )
276
302
&& Objects .equals (destroyFunction , that .destroyFunction )
277
303
&& servicePredicate .equals (that .servicePredicate )
@@ -290,6 +316,7 @@ public static final class Builder implements SmithyBuilder<RuntimeClientPlugin>
290
316
private SymbolReference inputConfig ;
291
317
private SymbolReference resolvedConfig ;
292
318
private SymbolReference resolveFunction ;
319
+ private List <String > additionalResolveFunctionParameters = new ArrayList <>();
293
320
private SymbolReference pluginFunction ;
294
321
private SymbolReference destroyFunction ;
295
322
private BiPredicate <Model , ServiceShape > servicePredicate = (model , service ) -> true ;
@@ -374,6 +401,24 @@ public Builder resolveFunction(SymbolReference resolveFunction) {
374
401
return this ;
375
402
}
376
403
404
+ /**
405
+ * Sets the symbol reference that is invoked in order to convert the
406
+ * input symbol type to a resolved symbol type.
407
+ *
408
+ * <p>If this is set, then both {@link #resolvedConfig} and
409
+ * {@link #inputConfig} must also be set.
410
+ *
411
+ * @param resolveFunction Function used to convert input to resolved.
412
+ * @param additionalParameters Additional parameters to be generated as resolve function input.
413
+ * @return Returns the builder.
414
+ * @see #getResolveFunction()
415
+ */
416
+ public Builder resolveFunction (SymbolReference resolveFunction , String ... additionalParameters ) {
417
+ this .resolveFunction = resolveFunction ;
418
+ this .additionalResolveFunctionParameters = ListUtils .of (additionalParameters );
419
+ return this ;
420
+ }
421
+
377
422
/**
378
423
* Sets the symbol that is invoked in order to convert the
379
424
* input symbol type to a resolved symbol type.
@@ -389,6 +434,38 @@ public Builder resolveFunction(Symbol resolveFunction) {
389
434
return resolveFunction (SymbolReference .builder ().symbol (resolveFunction ).build ());
390
435
}
391
436
437
+ /**
438
+ * Sets the symbol that is invoked in order to convert the
439
+ * input symbol type to a resolved symbol type.
440
+ *
441
+ * <p>If this is set, then both {@link #resolvedConfig} and
442
+ * {@link #inputConfig} must also be set.
443
+ *
444
+ * @param resolveFunction Function used to convert input to resolved.
445
+ * @param additionalParameters Additional parameters to be generated as resolve function input.
446
+ * @return Returns the builder.
447
+ * @see #getResolveFunction()
448
+ */
449
+ public Builder resolveFunction (Symbol resolveFunction , String ... additionalParameters ) {
450
+ return resolveFunction (SymbolReference .builder ().symbol (resolveFunction ).build (), additionalParameters );
451
+ }
452
+
453
+ /**
454
+ * Set additional positional input parameters to resolve function. Set
455
+ * this with no arguments to remove the current parameters.
456
+ *
457
+ * <p>If this is set, then all of {@link #resolveFunction},
458
+ * {@link #resolvedConfig} and {@link #inputConfig} must also be set.
459
+ *
460
+ * @param additionalParameters Additional parameters to be generated as resolve function input.
461
+ * @return Returns the builder.
462
+ * @see #getResolveFunction()
463
+ */
464
+ public Builder additionalResolveFunctionParameters (String ... additionalParameters ) {
465
+ this .additionalResolveFunctionParameters = ListUtils .of (additionalParameters );
466
+ return this ;
467
+ }
468
+
392
469
/**
393
470
* Sets a function symbol reference used to configure clients and
394
471
* commands to use a specific middleware function.
0 commit comments