def generate_raml_docs(module, fields, shared_types, user=None, title="My API", version="v1", api_root="api", base_uri="http://mysite.com/{version}"):
    """Return a RAML file of a Pale module's documentation as a string.

    The user argument is optional. If included, it expects the user to be an object with an "is_admin"
    boolean attribute. Any endpoint protected with a "@requires_permission" decorator will require
    user.is_admin == True to display documentation on that endpoint.

    The arguments for 'title', 'version', and 'base_uri' are added to the RAML header info.
    """
    output = StringIO()

    # Add the RAML header info
    output.write('#%RAML 1.0 \n')
    output.write('title: ' + title + ' \n')
    output.write('baseUri: ' + base_uri + ' \n')
    output.write('version: ' + version + '\n')
    output.write('mediaType: application/json\n\n')
    output.write('documentation:\n')
    output.write('  - title: Welcome\n')
    output.write('    content: |\n')
    output.write("""\
        Welcome to the Loudr API Docs.\n
        You'll find comprehensive documentation on our endpoints and resources here.
        """)
    output.write("\n###############\n# Resource Types:\n###############\n\n")
    output.write('types:\n')

    basic_fields = []

    for field_module in inspect.getmembers(fields, inspect.ismodule):
        for field_class in inspect.getmembers(field_module[1], inspect.isclass):
            basic_fields.append(field_class[1])

    pale_basic_types = generate_basic_type_docs(basic_fields, {})

    output.write("\n# Pale Basic Types:\n\n")
    output.write(pale_basic_types[0])


    shared_fields = []

    for shared_type in shared_types:

        for field_class in inspect.getmembers(shared_type, inspect.isclass):
            shared_fields.append(field_class[1])

    pale_shared_types = generate_basic_type_docs(shared_fields, pale_basic_types[1])
    output.write("\n# Pale Shared Types:\n\n")
    output.write(pale_shared_types[0])


    raml_resource_types = generate_raml_resource_types(module)
    output.write("\n# API Resource Types:\n\n")
    output.write(raml_resource_types)

    raml_resources = generate_raml_resources(module, api_root, user)
    output.write("\n\n###############\n# API Endpoints:\n###############\n\n")
    output.write(raml_resources)

    raml_docs = output.getvalue()
    output.close()

    return raml_docs
Return a RAML file of a Pale module's documentation as a string.

    The user argument is optional. If included, it expects the user to be an object with an "is_admin"
    boolean attribute. Any endpoint protected with a "@requires_permission" decorator will require
    user.is_admin == True to display documentation on that endpoint.

    The arguments for 'title', 'version', and 'base_uri' are added to the RAML header info.