Model transform(ModelTransformer transformer, Model model) {
        Set<Shape> toReplace = new HashSet<>();

        model.shapes(StructureShape.class).forEach(structure -> {
            if (!structure.getAllMembers().isEmpty()) {
                Set<MemberShape> members = new TreeSet<>(comparator);
                members.addAll(structure.getAllMembers().values());
                toReplace.add(structure.toBuilder().members(members).build());
            }
        });

        model.shapes(UnionShape.class).forEach(structure -> {
            if (!structure.getAllMembers().isEmpty()) {
                Set<MemberShape> members = new TreeSet<>(comparator);
                members.addAll(structure.getAllMembers().values());
                toReplace.add(structure.toBuilder().members(members).build());
            }
        });

        return transformer.replaceShapes(model, toReplace);
    }
Reorders members of structure and union shapes using a {@link Comparator}.
smithy-model/src/main/java/software/amazon/smithy/model/transform/SortMembers.java