77import java .util .Collection ;
88import java .util .HashSet ;
99import java .util .List ;
10+ import java .util .Optional ;
1011import java .util .Set ;
12+ import java .util .logging .Logger ;
1113import software .amazon .smithy .model .Model ;
14+ import software .amazon .smithy .model .shapes .MemberShape ;
1215import software .amazon .smithy .model .shapes .Shape ;
16+ import software .amazon .smithy .model .shapes .ShapeId ;
17+
18+ import static java .lang .String .format ;
1319
1420/**
1521 * Removes shapes from a model while ensuring that relationships to/from
@@ -27,6 +33,8 @@ final class RemoveShapes {
2733 private final Collection <? extends Shape > toRemove ;
2834 private final List <ModelTransformerPlugin > plugins ;
2935
36+ private static final Logger LOGGER = Logger .getLogger (RemoveShapes .class .getName ());
37+
3038 RemoveShapes (Collection <? extends Shape > toRemove , List <ModelTransformerPlugin > plugins ) {
3139 this .toRemove = toRemove ;
3240 this .plugins = plugins ;
@@ -37,6 +45,7 @@ Model transform(ModelTransformer transformer, Model model) {
3745
3846 // Iteratively add each shape that needs to be removed from the index using multiple rounds.
3947 Set <Shape > removed = new HashSet <>(toRemove );
48+ validateMembersFromMixin (model , removed );
4049 for (Shape removedShape : toRemove ) {
4150 builder .removeShape (removedShape .getId ());
4251 // We don't need to remove members from the builder since
@@ -52,4 +61,27 @@ Model transform(ModelTransformer transformer, Model model) {
5261
5362 return result ;
5463 }
64+
65+ private void validateMembersFromMixin (Model model , Collection <? extends Shape > shapesToExclude ) {
66+ for (Shape shape : shapesToExclude ) {
67+ // Only validate MemberShapes
68+ if (!shape .isMemberShape ()) {
69+ continue ;
70+ }
71+ MemberShape memberShape = shape .asMemberShape ().get ();
72+ Optional <Shape > container = model .getShape (memberShape .getContainer ());
73+ if (container .isPresent ()) {
74+ for (ShapeId mixinId : container .get ().getMixins ()) {
75+ Shape mixinShape = model .expectShape (mixinId );
76+ if (mixinShape .getMemberNames ().contains (shape .getId ().getMember ().get ())) {
77+ LOGGER .warning (format ("Removing mixed in member `%s` from mixin shape `%s` "
78+ + "in `%s` will result in an inconsistent model." ,
79+ memberShape .getMemberName (),
80+ mixinShape .getId (),
81+ container .get ().getId ().getName ()));
82+ }
83+ }
84+ }
85+ }
86+ }
5587}
0 commit comments