def get_schema_path(schema, resolved=False):
    def _strip_first_path_elem(path):
        stripped_path = path.split(os.path.sep, 1)[1:]
        return ''.join(stripped_path)
    def _schema_to_normalized_path(schema):
        path = os.path.normpath(os.path.sep + urlsplit(schema).path)
        if path.startswith(os.path.sep):
            path = path[1:]
        if not path.endswith('.json'):
            path += '.json'
        return path
    path = _schema_to_normalized_path(schema)
    while path:
        if resolved:
            schema_path = os.path.abspath(os.path.join(_resolved_schema_root_path, path))
        else:
            schema_path = os.path.abspath(os.path.join(_schema_root_path, path))
        if os.path.exists(schema_path):
            return os.path.abspath(schema_path)
        path = _strip_first_path_elem(path)
    raise SchemaNotFound(schema=schema)