private static Node sortNode(Node node, Comparator<StringNode> keyComparator) {
        return node.accept(new NodeVisitor.Default<Node>() {
            @Override
            protected Node getDefault(Node node) {
                return node;
            }

            @Override
            public Node objectNode(ObjectNode node) {
                Map<StringNode, Node> members = new TreeMap<>(keyComparator);
                node.getMembers().forEach((k, v) -> members.put(k, sortNode(v, keyComparator)));
                return new ObjectNode(members, node.getSourceLocation());
            }

            @Override
            public Node arrayNode(ArrayNode node) {
                return node.getElements()
                        .stream()
                        .map(element -> sortNode(element, keyComparator))
                        .collect(ArrayNode.collect(node.getSourceLocation()));
            }
        });
    }
Returns a node with sorted keys and sorted keys of all nested object
nodes using a custom comparator.

@param keyComparator Compares keys.
@return Returns the node in which all object nodes have sorted keys.
smithy-model/src/main/java/software/amazon/smithy/model/node/Node.java