private Set<Shape> getMembersToUpdate(Model model, Set<ShapeId> updatedOperations) {
        Set<ShapeId> stillBoundMembers = model.shapes(OperationShape.class)
                // Get all endpoint discovery operations
                .filter(operation -> operation.hasTrait(ClientDiscoveredEndpointTrait.ID))
                // Filter out the ones which are having their endpoint discovery traits removed
                .filter(operation -> !updatedOperations.contains(operation.getId()))
                // Get the input shapes of those operations
                .map(operation -> model.getShape(operation.getInputShape()).flatMap(Shape::asStructureShape))
                .filter(Optional::isPresent)
                // Get the input members
                .flatMap(input -> input.get().getAllMembers().values().stream())
                .map(Shape::getId)
                .collect(Collectors.toSet());

        return model.shapes(MemberShape.class)
                // Get all members which have the endpoint discovery id trait
                .filter(member -> member.hasTrait(ClientEndpointDiscoveryIdTrait.ID))
                // Get those which are on structures that aren't still bound to endpoint discovery operations
                .filter(member -> !stillBoundMembers.contains(member.getId()))
                // Remove the trait
                .map(member -> member.toBuilder().removeTrait(ClientEndpointDiscoveryIdTrait.ID).build())
                .collect(Collectors.toSet());
    }
Removes the endpoint discovery trait from a service if the referenced operation or error are removed.
smithy-aws-traits/src/main/java/software/amazon/smithy/aws/traits/clientendpointdiscovery/CleanClientDiscoveryTraitTransformer.java