private Set<Shape> getOperationsToUpdate(
            Model model,
            Set<ShapeId> updatedServices
    ) {
        ClientEndpointDiscoveryIndex discoveryIndex = ClientEndpointDiscoveryIndex.of(model);
        Set<ShapeId> stillBoundOperations = model.shapes(ServiceShape.class)
                // Get all endpoint discovery services
                .filter(service -> service.hasTrait(ClientEndpointDiscoveryTrait.ID))
                .map(Shape::getId)
                // Get those services who aren't having their discovery traits removed
                .filter(service -> !updatedServices.contains(service))
                // Get all the discovery operations bound to those services
                .flatMap(service -> discoveryIndex.getEndpointDiscoveryOperations(service).stream())
                .collect(Collectors.toSet());

        // Get all endpoint discovery operations
        Set<Shape> result = new HashSet<>();
        for (OperationShape operation : model.getOperationShapesWithTrait(ClientDiscoveredEndpointTrait.class)) {
            ClientDiscoveredEndpointTrait trait = operation.expectTrait(ClientDiscoveredEndpointTrait.class);
            // Only get the ones where discovery is optional, as it is safe to remove in that case.
            // Only get the ones that aren't still bound to a service that requires endpoint discovery.
            if (!trait.isRequired() && !stillBoundOperations.contains(operation.getId())) {
                result.add(operation.toBuilder().removeTrait(ClientDiscoveredEndpointTrait.ID).build());
            }
        }
        return result;
    }
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