def schema(query_params):
    context_name = query_params['context_name']
    href = build_href(query_params)

    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": context_name,
        "type": "object",
        "required": ["items"],
        "properties": {
            "do_item_count": {
                "type": "integer"
            },
            "item_count": {
                "type": "integer"
            },
            "@id": {
                "type": "string",
                "format": "uri"
            },
            "items": {
                "type": "array",
                "items": {
                    "type":
                    "object",
                    "required": ["title", "@id", "resource_id"],
                    "properties": {
                        "title": {
                            "type": "string"
                        },
                        "@id": {
                            "type": "string"
                        },
                        "resource_id": {
                            "type": "string"
                        }
                    },
                    "links": [{
                        "href": href,
                        "method": "GET",
                        "rel": "list"
                    }, {
                        "href": href,
                        "method": "GET",
                        "rel": "collection"
                    }]
                }
            },
        },
        "links": [{
            "href": "{+_base_url}",
            "method": "GET",
            "rel": "self"
        }]
    }

    merge_schemas(base, pagination_schema(u'/{0}/'.format(context_name)))
    return base
def schema(query_params):
    context_name = query_params['context_name']
    href = build_href(query_params)

    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": context_name,
        "type": "object",
        "required": ["items"],
        "properties": {
            "do_item_count": {"type": "integer"},
            "item_count": {"type": "integer"},
            "@id": {"type": "string", "format": "uri"},
            "items": {
                "type": "array",
                "items": {
                    "type": "object",
                    "required": ["title", "@id", "resource_id"],
                    "properties": {
                        "title": {"type": "string"},
                        "@id": {"type": "string"},
                        "resource_id": {"type": "string"}
                    },
                    "links": [
                        {
                            "href": href,
                            "method": "GET",
                            "rel": "list"
                        },
                        {
                            "href": href,
                            "method": "GET",
                            "rel": "collection"
                        }
                    ]
                }
            },
        },
        "links": [
            {
                "href": "{+_base_url}",
                "method": "GET",
                "rel": "self"
            }
        ]
    }

    merge_schemas(base, pagination_schema(u'/{0}/'.format(context_name)))
    return base
示例#3
0
def schema():
    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "Suggest Result List Schema",
        "type": "object",
        "required": ["items"],
        "properties": {
            #"do_item_count": {"type": "integer"},
            #"item_count": {"type": "integer"},
            "base_url": {"type": "string", "format": "uri"},
            "items": {
                "type": "array",
                "items": {
                    "type": "object",
                    "required": ["@id", "title", "@type", "type_title"],
                    "properties": {
                        "@id": {"type": "string"},
                        "title": {"type": "string"},
                        "@type": {"type": "string"},
                        "type_title": {"type": "string"},
                        "class_fields": {"type": "object"},
                        "instance_fields": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "additionalProperties": False,
                                "required": ["predicate_id", "predicate_title", "object_title", "required"],
                                "properties": {
                                    "predicate_id": {"type": "string"},
                                    "predicate_title": {"type": "string"},
                                    "object_id": {"type": "string"},
                                    "object_title": {"type": "string"},
                                    "required": {"type": "boolean"}
                                }
                            }
                        }
                    },
                    "links": [
                        {
                            "href": "/{resource_id}",
                            "method": "GET",
                            "rel": "list"
                        },
                        {
                            "href": "/{resource_id}",
                            "method": "GET",
                            "rel": "context"
                        }
                    ]
                }
            },
        },
        "links": [
            {
                "href": "{+_base_url}",
                "method": "GET",
                "rel": "self"
            },
            {
                "href": "/_suggest",
                "method": "POST",
                "rel": "suggest",
                "schema": SUGGEST_PARAM_SCHEMA
            },
            {
                "href": "/{context_id}/{collection_id}",
                "method": "GET",
                "rel": "collection",
                "schema": {
                    "type": "object",
                    "properties": {
                        "class_prefix": {
                            "type": "string"
                        }
                    },
                }
            },
            {
                "href": "/{context_id}/{collection_id}/{resource_id}",
                "method": "GET",
                "rel": "instance",
                "schema": {
                    "type": "object",
                    "properties": {
                        "class_prefix": {
                            "type": "string"
                        },
                        "instance_prefix": {
                            "type": "string"
                        },
                    },
                }

            }
        ]
    }

    merge_schemas(base, pagination_schema('/', method="POST"))
    return base
def schema(query_params):
    context_name = query_params['context_name']
    class_name = query_params['class_name']
    class_prefix = query_params.get('class_prefix', None)

    if (class_prefix is not None) and query_params.get('expand_uri') == '0':
        class_prefix = shorten_uri(class_prefix)

    args = (context_name, class_name, class_prefix)

    class_schema = get_cached_schema(query_params)

    if class_prefix is not None:
        schema_ref = u"/{0}/{1}/_schema?class_prefix={2}".format(*args)
        href = u"/{0}/{1}?class_prefix={2}".format(*args)
    else:
        schema_ref = u'/{0}/{1}/_schema'.format(*args)
        href = u'/{0}/{1}'.format(*args)

    if 'expand_uri' in query_params:
        expand_uri_param = 'expand_uri={0}'.format(query_params['expand_uri'])
        schema_ref = append_param(schema_ref, expand_uri_param)
        href = append_param(href, expand_uri_param)

    link = build_link(query_params)

    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": class_schema.get('title', ''),
        "type": "object",
        "required": ["items", "_class_prefix", "@id"],
        "properties": {
            "_class_prefix": {"type": "string"},
            "pattern": {"type": "string"},  # used in _search service responses
            "do_item_count": {"type": "integer"},
            "item_count": {"type": "integer"},
            "@id": {"type": "string", "format": "uri"},
            "items": {
                "type": "array",
                "items": {
                    "type": "object",
                    "title": class_schema.get('title', ''),
                    "required": ["title", "@id", "resource_id", "instance_prefix"],
                    "properties": {
                        "title": {"type": "string"},
                        "@id": {"type": "string"},
                        "resource_id": {"type": "string"},
                        "instance_prefix": {"type": "string", "format": "uri"},
                    },
                    "links": [
                        {
                            "href": link,
                            "method": "GET",
                            "rel": "item"
                        },
                        {
                            "href": link,
                            "method": "GET",
                            "rel": "instance"
                        }
                    ]
                }
            },
        },
        "links": [
            {
                "href": "{+_base_url}",
                "method": "GET",
                "rel": "self"
            },
            {
                "href": "{+_schema_url}",
                "method": "GET",
                "rel": "class"
            },
            {
                "href": u"/{0}".format(context_name),
                "method": "GET",
                "rel": "context"
            },
            {
                "href": href,
                "method": "POST",
                "rel": "add",
                "schema": {"$ref": schema_ref}
            },
            {
                "href": "/{0}/{1}/_search?graph_uri={2}&class_uri={3}&pattern={{pattern}}".format(
                        context_name,
                        class_name,
                        query_params['graph_uri'],
                        query_params['class_uri']),
                "method": "GET",
                "rel": "search",
                "schema": SEARCH_PARAM_SCHEMA
            }
        ]
    }

    base_pagination_url = u'/{0}/{1}'.format(context_name, class_name)
    extra_url_params = '&class_prefix={_class_prefix}'
    pagination_dict = pagination_schema(base_pagination_url, extra_url_params)
    merge_schemas(base, pagination_dict)
    return base
示例#5
0
def schema():
    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "Contexts",
        "type": "object",
        "required": ["items"],
        "properties": {
            "do_item_count": {"type": "integer"},
            "item_count": {"type": "integer"},
            "base_url": {"type": "string", "format": "uri"},
            "items": {
                "type": "array",
                "items": {
                    "type": "object",
                    "required": ["title", "@id", "resource_id"],
                    "properties": {
                        "title": {"type": "string"},
                        "@id": {"type": "string"},
                        "resource_id": {"type": "string"}
                    },
                    "links": [
                        {
                            "href": "/{resource_id}",
                            "method": "GET",
                            "rel": "list"
                        },
                        {
                            "href": "/{resource_id}",
                            "method": "GET",
                            "rel": "context"
                        }
                    ]
                }
            },
        },
        "links": [
            {
                "href": "{+_base_url}",
                "method": "GET",
                "rel": "self"
            },
            {
                "href": "/_suggest",
                "method": "POST",
                "rel": "suggest",
                "schema": SUGGEST_PARAM_SCHEMA
            },
            {
                "href": "/{{context_id}}/{{collection_id}}",
                "method": "GET",
                "rel": "collection",
                "schema": {
                    "type": "object",
                    "properties": {
                        "class_prefix": {
                            "type": "string"
                        }
                    },
                }
            },
            {
                "href": "/{{context_id}}/{{collection_id}}/{{resource_id}}",
                "method": "GET",
                "rel": "instance",
                "schema": {
                    "type": "object",
                    "properties": {
                        "class_prefix": {
                            "type": "string"
                        },
                        "instance_prefix": {
                            "type": "string"
                        },
                    },
                }

            }
        ]
    }

    merge_schemas(base, pagination_schema('/'))
    return base
示例#6
0
def schema(query_params):
    context_name = query_params['context_name']
    class_name = query_params['class_name']
    class_prefix = query_params.get('class_prefix', None)
    args = (context_name, class_name, class_prefix)

    class_schema = get_cached_schema(query_params)

    if class_prefix is not None:
        schema_ref = u"/{0}/{1}/_schema?class_prefix={2}".format(*args)
        href = u"/{0}/{1}?class_prefix={2}".format(*args)
        link = u"/{0}/{1}/{{resource_id}}?class_prefix={{class_prefix}}&instance_prefix={{instance_prefix}}".format(
            *args)
    else:
        schema_ref = u'/{0}/{1}/_schema'.format(*args)
        href = u'/{0}/{1}'.format(*args)
        link = u"/{0}/{1}/{{resource_id}}?class_prefix={{class_prefix}}&instance_prefix={{instance_prefix}}".format(
            *args)

    base = {
        "$schema":
        "http://json-schema.org/draft-04/schema#",
        "title":
        class_schema.get('title', ''),
        "type":
        "object",
        "required": ["items", "_class_prefix", "@id"],
        "properties": {
            "_class_prefix": {
                "type": "string"
            },
            "pattern": {
                "type": "string"
            },  # used in _search service responses
            "do_item_count": {
                "type": "integer"
            },
            "item_count": {
                "type": "integer"
            },
            "@id": {
                "type": "string",
                "format": "uri"
            },
            "items": {
                "type": "array",
                "items": {
                    "type":
                    "object",
                    "title":
                    class_schema.get('title', ''),
                    "required":
                    ["title", "@id", "resource_id", "instance_prefix"],
                    "properties": {
                        "title": {
                            "type": "string"
                        },
                        "@id": {
                            "type": "string"
                        },
                        "resource_id": {
                            "type": "string"
                        },
                        "instance_prefix": {
                            "type": "string",
                            "format": "uri"
                        },
                    },
                    "links": [{
                        "href": link,
                        "method": "GET",
                        "rel": "item"
                    }, {
                        "href": link,
                        "method": "GET",
                        "rel": "instance"
                    }]
                }
            },
        },
        "links": [{
            "href": "{+_base_url}",
            "method": "GET",
            "rel": "self"
        }, {
            "href": "{+_schema_url}",
            "method": "GET",
            "rel": "class"
        }, {
            "href": u"/{0}".format(context_name),
            "method": "GET",
            "rel": "context"
        }, {
            "href": href,
            "method": "POST",
            "rel": "add",
            "schema": {
                "$ref": schema_ref
            }
        }, {
            "href":
            "/{0}/{1}/_search?graph_uri={2}&class_uri={3}&pattern={{pattern}}".
            format(context_name, class_name, query_params['graph_uri'],
                   query_params['class_uri']),
            "method":
            "GET",
            "rel":
            "search",
            "schema":
            SEARCH_PARAM_SCHEMA
        }]
    }

    base_pagination_url = u'/{0}/{1}'.format(context_name, class_name)
    extra_url_params = '&class_prefix={_class_prefix}'
    pagination_dict = pagination_schema(base_pagination_url, extra_url_params)
    merge_schemas(base, pagination_dict)
    return base
示例#7
0
def schema(context_name, class_name):
    schema_ref = u"/{0}/{1}/_schema?class_prefix={{_class_prefix}}".format(
        context_name, class_name)
    href = u"/{0}/{1}/?class_prefix={{_class_prefix}}".format(
        context_name, class_name)
    link = u"/{0}/{1}/_?instance_uri={{id}}".format(context_name, class_name)
    search_url = "/{0}/{1}/_search?graph_uri={{_graph_uri}}&class_uri={{_class_uri}}&pattern={{pattern}}"

    base = {
        "$schema":
        "http://json-schema.org/draft-04/schema#",
        "title":
        "",
        "type":
        "object",
        "required": ["items", "_class_prefix", "@id"],
        "properties": {
            "pattern": {
                "type": "string"
            },  # used in _search service responses
            "_graph_uri": {
                "type": "string"
            },  # used in _search service responses
            "_context_name": {
                "type": "string"
            },  # used in _search service responses
            "_class_name": {
                "type": "string"
            },  # used in _search service responses
            "_class_prefix": {
                "type": "string"
            },  # used in _search service responses
            "_class_uri": {
                "type": "string"
            },  # used in _search service responses
            "do_item_count": {
                "type": "integer"
            },
            "item_count": {
                "type": "integer"
            },
            "@id": {
                "type": "string",
                "format": "uri"
            },
            "items": {
                "type": "array",
                "items": {
                    "type":
                    "object",
                    "required":
                    ["title", "id", "resource_id", "instance_prefix"],
                    "properties": {
                        "title": {
                            "type": "string"
                        },
                        "id": {
                            "type": "string"
                        },
                        "resource_id": {
                            "type": "string"
                        },
                        "instance_prefix": {
                            "type": "string",
                            "format": "uri"
                        },
                    },
                    "links": [{
                        "href": link,
                        "method": "GET",
                        "rel": "item"
                    }, {
                        "href": link,
                        "method": "GET",
                        "rel": "instance"
                    }]
                }
            },
        },
        "links": [{
            "href": "{+_base_url}",
            "method": "GET",
            "rel": "self"
        }, {
            "href": "{+_schema_url}",
            "method": "GET",
            "rel": "class"
        }, {
            "href": u"/{0}".format(context_name),
            "method": "GET",
            "rel": "context"
        }, {
            "href": href,
            "method": "POST",
            "rel": "add",
            "schema": {
                "$ref": schema_ref
            }
        }, {
            "href": search_url.format(context_name, class_name),
            "method": "GET",
            "rel": "search",
            "schema": SEARCH_PARAM_SCHEMA
        }, {
            "href": href,
            "method": "GET",
            "rel": "list"
        }, {
            "href": href,
            "method": "GET",
            "rel": "collection"
        }]
    }

    base_pagination_url = u'/{0}/{1}/_search'.format(context_name, class_name)
    extra_url_params = '&graph_uri={_graph_uri}&class_uri={_class_uri}'
    pagination_dict = pagination_schema(base_pagination_url, extra_url_params)
    merge_schemas(base, pagination_dict)
    return base
示例#8
0
def schema(context_name, class_name):
    schema_ref = u"/{0}/{1}/_schema?class_prefix={{_class_prefix}}".format(context_name, class_name)
    href = u"/{0}/{1}/?class_prefix={{_class_prefix}}".format(context_name, class_name)
    link = u"/{0}/{1}/_?instance_uri={{id}}".format(context_name, class_name)
    search_url = "/{0}/{1}/_search?graph_uri={{_graph_uri}}&class_uri={{_class_uri}}&pattern={{pattern}}"

    base = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "",
        "type": "object",
        "required": ["items", "_class_prefix", "@id"],
        "properties": {
            "pattern": {"type": "string"},  # used in _search service responses
            "_graph_uri": {"type": "string"},  # used in _search service responses
            "_context_name": {"type": "string"},  # used in _search service responses
            "_class_name": {"type": "string"},  # used in _search service responses
            "_class_prefix": {"type": "string"},  # used in _search service responses
            "_class_uri": {"type": "string"},  # used in _search service responses
            "do_item_count": {"type": "integer"},
            "item_count": {"type": "integer"},
            "@id": {"type": "string", "format": "uri"},
            "items": {
                "type": "array",
                "items": {
                    "type": "object",
                    "required": ["title", "id", "resource_id", "instance_prefix"],
                    "properties": {
                        "title": {"type": "string"},
                        "id": {"type": "string"},
                        "resource_id": {"type": "string"},
                        "instance_prefix": {"type": "string", "format": "uri"},
                    },
                    "links": [
                        {
                            "href": link,
                            "method": "GET",
                            "rel": "item"
                        },
                        {
                            "href": link,
                            "method": "GET",
                            "rel": "instance"
                        }
                    ]
                }
            },
        },
        "links": [
            {
                "href": "{+_base_url}",
                "method": "GET",
                "rel": "self"
            },
            {
                "href": "{+_schema_url}",
                "method": "GET",
                "rel": "class"
            },
            {
                "href": u"/{0}".format(context_name),
                "method": "GET",
                "rel": "context"
            },
            {
                "href": href,
                "method": "POST",
                "rel": "add",
                "schema": {"$ref": schema_ref}
            },
            {
                "href": search_url.format(context_name, class_name),
                "method": "GET",
                "rel": "search",
                "schema": SEARCH_PARAM_SCHEMA
            },
            {
                "href": href,
                "method": "GET",
                "rel": "list"
            },
            {
                "href": href,
                "method": "GET",
                "rel": "collection"
            }

        ]
    }

    base_pagination_url = u'/{0}/{1}/_search'.format(context_name, class_name)
    extra_url_params = '&graph_uri={_graph_uri}&class_uri={_class_uri}'
    pagination_dict = pagination_schema(base_pagination_url, extra_url_params)
    merge_schemas(base, pagination_dict)
    return base
示例#9
0
def schema():
    base = {
        "$schema":
        "http://json-schema.org/draft-04/schema#",
        "title":
        "Contexts",
        "type":
        "object",
        "required": ["items"],
        "properties": {
            "do_item_count": {
                "type": "integer"
            },
            "item_count": {
                "type": "integer"
            },
            "base_url": {
                "type": "string",
                "format": "uri"
            },
            "items": {
                "type": "array",
                "items": {
                    "type":
                    "object",
                    "required": ["title", "@id", "resource_id"],
                    "properties": {
                        "title": {
                            "type": "string"
                        },
                        "@id": {
                            "type": "string"
                        },
                        "resource_id": {
                            "type": "string"
                        }
                    },
                    "links": [{
                        "href": "/{resource_id}",
                        "method": "GET",
                        "rel": "list"
                    }, {
                        "href": "/{resource_id}",
                        "method": "GET",
                        "rel": "context"
                    }]
                }
            },
        },
        "links": [{
            "href": "{+_base_url}",
            "method": "GET",
            "rel": "self"
        }, {
            "href": "/_suggest",
            "method": "POST",
            "rel": "suggest",
            "schema": SUGGEST_PARAM_SCHEMA
        }, {
            "href": "/{{context_id}}/{{collection_id}}",
            "method": "GET",
            "rel": "collection",
            "schema": {
                "type": "object",
                "properties": {
                    "class_prefix": {
                        "type": "string"
                    }
                },
            }
        }, {
            "href": "/{{context_id}}/{{collection_id}}/{{resource_id}}",
            "method": "GET",
            "rel": "instance",
            "schema": {
                "type": "object",
                "properties": {
                    "class_prefix": {
                        "type": "string"
                    },
                    "instance_prefix": {
                        "type": "string"
                    },
                },
            }
        }]
    }

    merge_schemas(base, pagination_schema('/'))
    return base