Model transform(ModelTransformer transformer, Model model) {
        // Remove any no-op pairs to avoid renaming shapes unnecessarily.
        renamed.keySet().removeIf(fromId -> fromId.equals(renamed.get(fromId)));
        if (renamed.isEmpty()) {
            return model;
        }

        // Creates a set that will be used for checking if a string value needs to be renamed or not.
        Set<String> toRename = renamed.keySet()
                .stream()
                .map(ShapeId::toString)
                .collect(Collectors.toSet());

        // TODO: this transform serializes the model, then deserializes it. Because of this, if the model
        //  contained sets via loading a 1.0 model, then the set will be serialized in a 2.0 as a list.
        //  To restore them to sets, this track the sets, then change the types after renaming. We should
        //  update this to eventually not need to serialize an intermediate model.
        Set<SetShape> sets = model.getSetShapes();

        // This transformer converts the model into an ObjectNode. This approach was chosen because the
        // JSON AST format includes fully qualified shape ID values, making it possible rename shapes across
        // the model by only needing to compare and replace StringNode values.
        ModelSerializer serializer = ModelSerializer.builder().build();
        ObjectNode node = serializer.serialize(model);

        // Use visitor to traverse node and rebuild model.
        Node newModel = node.accept(new RenameShapeVisitor(toRename, renamed));

        ValidatedResult<Model> result = assembler.addDocumentNode(newModel).assemble();

        // Transformers shouldn't perform validation ideally. They should only throw errors if the model
        // can't be transformed.
        Model modelResult = result.getResult().orElseGet(result::unwrap);

        return retypeListsBackToSets(transformer, modelResult, sets, renamed);
    }
Renames shapes using ShapeId pairs while ensuring that the
 transformed model is in a consistent state.

 <p>Member shapes are updated when their containing shape is updated.

 <p>Trait references to ShapeId values are also updated.
smithy-model/src/main/java/software/amazon/smithy/model/transform/RenameShapes.java