private Pair<Shape, List<Shape>> synthesizeErrorUnion(
            String operationName,
            Integer statusCode,
            List<StructureShape> errors
    ) {
        List<Shape> replacementShapes = new ArrayList<>();
        StructureShape.Builder errorResponse = StructureShape.builder();
        ShapeId errorResponseId = ShapeId.fromParts(forService.getId().getNamespace(),
                operationName + statusCode + "Error");
        errorResponse.id(errorResponseId);
        errorResponse.addTraits(getErrorTraitsFromStatusCode(statusCode));
        Map<String, HttpHeaderTrait> headerTraitMap = new HashMap<>();
        UnionShape.Builder errorUnion = UnionShape.builder()
                .id(
                        ShapeId.fromParts(errorResponseId.getNamespace(), errorResponseId.getName() + "Content"));
        for (StructureShape error : errors) {
            StructureShape newError = createNewError(error, headerTraitMap);
            replacementShapes.add(newError);
            MemberShape newErrorMember = MemberShape.builder()
                    .id(errorUnion.getId().withMember(newError.getId().getName()))
                    .target(newError.getId())
                    .build();
            replacementShapes.add(newErrorMember);
            errorUnion.addMember(newErrorMember);
        }
        UnionShape union = errorUnion.build();
        replacementShapes.add(union);
        errorResponse.addMember(MemberShape.builder()
                .id(errorResponseId.withMember("errorUnion"))
                .target(union.getId())
                .build());
        // Add members with hoisted HttpHeader traits.
        for (Map.Entry<String, HttpHeaderTrait> entry : headerTraitMap.entrySet()) {
            errorResponse.addMember(MemberShape.builder()
                    .id(errorResponseId.withMember(entry.getKey()))
                    .addTrait(entry.getValue())
                    .target("smithy.api#String")
                    .build());
        }
        StructureShape built = errorResponse.build();
        return Pair.of(built, replacementShapes);
    }
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