Skip to content

Commit

Permalink
Use spread operator for Command endpoint params when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Sep 10, 2024
1 parent f95b9c3 commit 5ed78b5
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,28 +270,38 @@ private void generateEndpointParameterInstructionProvider() {
if (!service.hasTrait(EndpointRuleSetTrait.class)) {
return;
}

writer.addImport(
"commonParams", null,
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "endpoint/EndpointParameters").toString()
);

RuleSetParameterFinder parameterFinder = new RuleSetParameterFinder(service);
Map<String, String> staticContextParamValues = parameterFinder.getStaticContextParamValues(operation);
Map<String, String> contextParams = parameterFinder.getContextParams(
model.getShape(operation.getInputShape()).get()
);
Map<String, String> operationContextParamValues = parameterFinder.getOperationContextParamValues(operation);

if (staticContextParamValues.isEmpty() && contextParams.isEmpty() && operationContextParamValues.isEmpty()) {
writer.write(".ep(commonParams)");
return;
}

writer.write(".ep({")
.indent();
{
writer.addImport(
"commonParams", null,
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "endpoint/EndpointParameters").toString()
);

writer.write("...commonParams,");

RuleSetParameterFinder parameterFinder = new RuleSetParameterFinder(service);
Set<String> paramNames = new HashSet<>();

parameterFinder.getStaticContextParamValues(operation).forEach((name, value) -> {
staticContextParamValues.forEach((name, value) -> {
paramNames.add(name);
writer.write(
"$L: { type: \"staticContextParams\", value: $L },",
name, value);
});

Shape operationInput = model.getShape(operation.getInputShape()).get();
parameterFinder.getContextParams(operationInput).forEach((name, memberName) -> {
contextParams.forEach((name, memberName) -> {
if (!paramNames.contains(name)) {
writer.write(
"$L: { type: \"contextParams\", name: \"$L\" },",
Expand All @@ -300,7 +310,7 @@ private void generateEndpointParameterInstructionProvider() {
paramNames.add(name);
});

parameterFinder.getOperationContextParamValues(operation).forEach((name, jmesPathForInputInJs) -> {
operationContextParamValues.forEach((name, jmesPathForInputInJs) -> {
writer.write(
"""
$L: { type: \"operationContextParams\", name: $L },
Expand Down

0 comments on commit 5ed78b5

Please sign in to comment.