@Override
    public Model onRemove(ModelTransformer transformer, Collection<Shape> shapes, Model model) {
        // Short circuit if the traits aren't applied.
        if (!model.isTraitApplied(ClientEndpointDiscoveryTrait.class)
                && !model.isTraitApplied(ClientDiscoveredEndpointTrait.class)) {
            return model;
        }

        Set<ShapeId> removedOperations = shapes.stream()
                .filter(Shape::isOperationShape)
                .map(Shape::getId)
                .collect(Collectors.toSet());

        Set<Shape> servicesToUpdate = getServicesToUpdate(model, removedOperations);
        Set<Shape> shapesToUpdate = new HashSet<>(servicesToUpdate);

        Set<Shape> operationsToUpdate = getOperationsToUpdate(
                model,
                servicesToUpdate.stream().map(Shape::getId).collect(Collectors.toSet()));
        shapesToUpdate.addAll(operationsToUpdate);

        Set<Shape> membersToUpdate = getMembersToUpdate(
                model,
                operationsToUpdate.stream().map(Shape::getId).collect(Collectors.toSet()));
        shapesToUpdate.addAll(membersToUpdate);
        return transformer.replaceShapes(model, shapesToUpdate);
    }
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