Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/bugfix-waiter-result-getter-collision.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "smithy-cpp-codegen",
"contributor": "sbiscigl",
"description": "Fix generated waiters to call the renamed getter when an output member's getter name matches its result class name."
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@
import software.amazon.smithy.jmespath.ast.FlattenExpression;
import software.amazon.smithy.jmespath.ast.Subexpression;

import java.util.Optional;

/**
* Emits a getter chain for non-projection field access (e.g. ".GetCluster().GetStatus()").
*/
public class GetterChainEmitter extends UnsupportedExpressionVisitor<String> {
private final Optional<String> resultClassName;

public GetterChainEmitter() {
this(Optional.empty());
}

public GetterChainEmitter(Optional<String> resultClassName) {
this.resultClassName = resultClassName;
}

@Override public String visitField(FieldExpression e) {
return ".Get" + ServiceNameUtil.capitalize(e.getName()) + "()";
String getter = "Get" + ServiceNameUtil.capitalize(e.getName());
return "." + resultClassName.filter(getter::equals).map(name -> "Get" + name).orElse(getter) + "()";
}
@Override public String visitSubexpression(Subexpression e) {
return e.getLeft().accept(this) + e.getRight().accept(this);
return e.getLeft().accept(this) + e.getRight().accept(new GetterChainEmitter());
}
@Override public String visitFlatten(FlattenExpression e) {
return e.getExpression().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.amazonaws.util.awsclientsmithygenerator.generators.waiters.jmespath;

import com.amazonaws.util.awsclientsmithygenerator.generators.ShapeUtil;
import software.amazon.smithy.jmespath.JmespathExpression;
import software.amazon.smithy.jmespath.ast.AndExpression;
import software.amazon.smithy.jmespath.ast.ComparatorExpression;
Expand All @@ -20,6 +21,7 @@
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.waiters.PathComparator;

import java.util.Optional;
import java.util.Set;

/**
Expand Down Expand Up @@ -196,7 +198,9 @@ private String emitPathCode(JmespathExpression expr) {
EnumInfo enumInfo = EnumResolver.resolveEnumInfo(expr, model, operation);

if (projectionLevels == 0) {
String access = "result" + expr.accept(new GetterChainEmitter());
Optional<String> resultClassName = Optional.ofNullable(operation)
.map(op -> op.getId().getName() + ShapeUtil.getResultSuffix(model, op, smithyServiceName));
String access = "result" + expr.accept(new GetterChainEmitter(resultClassName));
if (enumInfo != null) {
access = enumInfo.wrapAccess(access);
enumIncludes.add(enumInfo.shapeName);
Expand Down
Loading