Skip to content

Commit

Permalink
fix namespace collision detection on member varibles
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Nov 9, 2023
1 parent 0655398 commit cad65b2
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.WordUtils;

import java.util.*;
Expand Down Expand Up @@ -99,6 +100,16 @@ public class C2jModelToGeneratorModelTransformer {
LEGACY_SERVICE_IDS.add("dynamodbstreams");
}

/**
* There was a bug with namespace collision detection where customers
* renamed their models instead of this bug being fixed. This list exists
* only to capture these old APIs. This list should never be added to
* under any circumstances and only exists to preserve backwards compat.
*/
private static List<String> LEGACY_RENAMED_APIS = ImmutableList.of(
"GeneratedPolicyResult"
);

public C2jModelToGeneratorModelTransformer(C2jServiceModel c2jServiceModel, boolean standalone) {
this.c2jServiceModel = c2jServiceModel;
this.standalone = standalone;
Expand Down Expand Up @@ -646,9 +657,11 @@ Shape renameShape(Shape shape, String name) {
}

// Detect any conflicts with shape name defined by service team, need to rename it if so.
Optional<String> conflicted = shapes.keySet().stream().filter(shapeName ->
name.equals(shapeName) || shape.getMembers().values().stream().anyMatch(shapeMember ->
shapeMember.getShape().getName().equals(shapeName) && (name.equals("Get" + shapeName) || name.equals("Set" + shapeName)))).findFirst();
Optional<String> conflicted = shapes.keySet().stream()
.filter(shapeName -> name.equals(shapeName) ||
(shape.getMembers().keySet().stream().anyMatch(memberName -> memberName.equals(shapeName) ||
shape.getMembers().values().stream().anyMatch(shapeMember -> LEGACY_RENAMED_APIS.contains(shapeMember.getShape().getName()))) &&
(name.equals("Get" + shapeName) || name.equals("Set" + shapeName)))).findFirst();
if (conflicted.isPresent()) {
String originalShapeName = conflicted.get();
String newShapeName = "";
Expand Down

0 comments on commit cad65b2

Please sign in to comment.