@Override
    public Node toNode() {
        ObjectNode definitionNode = Node.objectNode();

        if (!definitions.isEmpty()) {
            // Merge in each definition using a JSON Patch style "add" operation
            // that creates missing intermediate objects.
            for (Map.Entry<String, Schema> entry : definitions.entrySet()) {
                if (entry.getKey().startsWith("http")) {
                    LOGGER.info(() -> "Skipping the serialization of a remote schema reference: " + entry.getKey());
                } else {
                    NodePointer pointer = parseCheckedPointer(entry.getKey());
                    definitionNode = pointer
                            .addWithIntermediateValues(definitionNode, entry.getValue().toNode())
                            .expectObjectNode();
                }
            }
        }

        return Node.objectNodeBuilder()
                .withOptionalMember("$id", getIdKeyword().map(Node::from))
                .withOptionalMember("$schema", getSchemaKeyword().map(Node::from))
                .merge(rootSchema.toNode().expectObjectNode())
                .merge(extensions)
                .merge(definitionNode)
                .build()
                .withDeepSortedKeys(new SchemaComparator());
    }
Returns a builder used to create a {@link SchemaDocument}.

@return Returns the created builder.
smithy-jsonschema/src/main/java/software/amazon/smithy/jsonschema/SchemaDocument.java