import json


def document_schema(schema, type, indent=0):
    """
    Document a schema for a JSON RPC object of the given type.

    :argument schema: a JSON Schema
    :argument type: the type of object that the schema validates
    :type type: "request", "response" or "notification"
    :argument indent: an indent level to move the schema string over
    :type indent: integer
    :rtype: a str in the Sphinx markup language

    """

    if type not in {"request", "response", "notification"}:
        raise ValueError(type)

    ind = (indent + 4) * " "
    schema = ind + json.dumps(schema, sort_keys=True, indent=4)
    schema = schema.replace("\n", "\n" + ind)
    return indent * " " + ".. {}::\n\n{}".format(type, schema)