Model transform(ModelTransformer transformer, Model model) {
        // Copy any service errors to the operations to find all potential conflicts.
        model = transformer.copyServiceErrorsToOperations(model, forService);
        TopDownIndex topDownIndex = TopDownIndex.of(model);
        List<Shape> shapesToReplace = new ArrayList<>();

        for (OperationShape operation : topDownIndex.getContainedOperations(forService)) {
            OperationShape.Builder replacementOperation = operation.toBuilder();
            boolean replaceOperation = false;

            // Collect errors that share the same status code.
            Map<Integer, List<StructureShape>> statusCodesToErrors = new HashMap<>();
            for (ShapeId errorId : operation.getErrors()) {
                StructureShape error = model.expectShape(errorId, StructureShape.class);
                Integer statusCode = error.hasTrait(HttpErrorTrait.ID)
                        ? error.getTrait(HttpErrorTrait.class).get().getCode()
                        : error.getTrait(ErrorTrait.class).get().getDefaultHttpStatusCode();
                statusCodesToErrors.computeIfAbsent(statusCode, k -> new ArrayList<>()).add(error);
            }

            // Create union error for errors with same status code.
            for (Map.Entry<Integer, List<StructureShape>> statusCodeToErrors : statusCodesToErrors.entrySet()) {
                if (statusCodeToErrors.getValue().size() > 1) {
                    replaceOperation = true;
                    List<StructureShape> errors = statusCodeToErrors.getValue();
                    // Create a new top-level synthetic error and all the shapes that need replaced for it.
                    Pair<Shape, List<Shape>> syntheticErrorPair = synthesizeErrorUnion(operation.getId().getName(),
                            statusCodeToErrors.getKey(),
                            errors);
                    for (StructureShape error : errors) {
                        replacementOperation.removeError(error.getId());
                    }
                    replacementOperation.addError(syntheticErrorPair.getLeft());
                    shapesToReplace.add(syntheticErrorPair.getLeft());
                    shapesToReplace.addAll(syntheticErrorPair.getRight());
                }
            }
            // Replace the operation if it has been updated with a synthetic error.
            if (replaceOperation) {
                replacementOperation.build();
                shapesToReplace.add(replacementOperation.build());
            }
        }

        return transformer.replaceShapes(model, shapesToReplace);
    }
Deconflicts errors on operations that share the same status code by replacing
the conflicting errors with a synthetic error structure that contains hoisted
members that were bound to HTTP headers. The conflicting errors are added to
a union on the synthetic error.
smithy-model/src/main/java/software/amazon/smithy/model/transform/DeconflictErrorsWithSharedStatusCode.java