Skip to content

Commit d9c547c

Browse files
committed
Deep copy the new event shape
1 parent 17a0463 commit d9c547c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/customization/processors/EventStreamSharedEventProcessor.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
package software.amazon.awssdk.codegen.customization.processors;
1717

18+
import java.io.IOException;
19+
import java.io.StringWriter;
1820
import java.util.HashMap;
1921
import java.util.Map;
2022
import org.slf4j.Logger;
2123
import org.slf4j.LoggerFactory;
2224
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor;
25+
import software.amazon.awssdk.codegen.internal.Jackson;
2326
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
2427
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
2528
import software.amazon.awssdk.codegen.model.service.Member;
@@ -80,14 +83,26 @@ public void preprocess(ServiceModel serviceModel) {
8083
+ "customization config duplicateAndRenameSharedEvents.%s",
8184
newShapeName, eventStreamName));
8285
}
83-
serviceModel.getShapes().put(newShapeName, eventMemberShape);
86+
serviceModel.getShapes().put(newShapeName, duplicateShape(eventMemberShape));
8487
eventMemberToModify.setShape(newShapeName);
8588
log.info("Duplicated and renamed event member on {} from {} -> {}",
8689
eventStreamName, shapeToDuplicate, newShapeName);
8790
}
8891
}
8992
}
9093

94+
private Shape duplicateShape(Shape shape) {
95+
StringWriter writer = new StringWriter();
96+
try {
97+
Jackson.writeWithObjectMapper(shape, writer);
98+
Shape duplicated = Jackson.load(Shape.class, writer.toString());
99+
duplicated.setSynthetic(true);
100+
return duplicated;
101+
} catch (IOException e) {
102+
throw new RuntimeException(e);
103+
}
104+
}
105+
91106
private static void validateIsEventStream(Shape shape, String name) {
92107
if (shape == null) {
93108
throw new IllegalStateException(

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Shape.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.codegen.model.service;
1717

18+
import com.fasterxml.jackson.annotation.JsonIgnore;
1819
import java.util.Collections;
1920
import java.util.List;
2021
import java.util.Map;
@@ -352,10 +353,12 @@ public void setRetryable(RetryableTrait retryable) {
352353
this.retryable = retryable;
353354
}
354355

356+
@JsonIgnore
355357
public boolean isRetryable() {
356358
return retryable != null;
357359
}
358360

361+
@JsonIgnore
359362
public boolean isThrottling() {
360363
return retryable != null && retryable.isThrottling();
361364
}

codegen/src/test/java/software/amazon/awssdk/codegen/customization/processors/EventStreamSharedEventProcessorTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package software.amazon.awssdk.codegen.customization.processors;
1717

1818
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
import static org.junit.Assert.assertNotEquals;
20+
import static org.junit.Assert.assertTrue;
1921
import static org.junit.jupiter.api.Assertions.assertEquals;
2022
import static org.junit.jupiter.api.Assertions.assertNotNull;
2123

@@ -56,7 +58,10 @@ public void duplicatesAndRenamesSharedEvent() {
5658

5759
Shape newEventShape = serviceModel.getShape("PayloadB");
5860
assertNotNull(newEventShape);
59-
assertEquals(serviceModel.getShape("Payload"), newEventShape);
61+
assertNotEquals(serviceModel.getShape("Payload"), newEventShape); // shape is duplicated/deep copied
62+
assertTrue(newEventShape.isSynthetic());
63+
assertEquals(serviceModel.getShape("Payload").getType(), newEventShape.getType());
64+
assertEquals(serviceModel.getShape("Payload").getMembers().keySet(), newEventShape.getMembers().keySet());
6065

6166
Shape streamB = serviceModel.getShape("StreamB");
6267
assertEquals("PayloadB", streamB.getMembers().get("Payload").getShape());

0 commit comments

Comments
 (0)