# Path: apis/v1/schemas.py
# class Current(object):
# class Security(object):
#     class DataWrapper(object):
#     def __init__(self):
#     def scopes(self):
#     def scopes_loader(self, func):
# def merge_default(schema, value, get_first=True):
# def normalize(schema, data, required_defaults=None):
#         def __init__(self, data):
#         def get(self, key, default=None):
#         def has(self, key):
#         def keys(self):
#         def get_check(self, key, default=None):
#     def _merge_dict(src, dst):
#     def _normalize_dict(schema, data):
#     def _normalize_list(schema, data):
#     def _normalize_default(schema, data):
#     def _normalize(schema, data):


import re
import json
import six
from datetime import date
from functools import wraps
from sanic import response
from sanic.exceptions import ServerError
from sanic.response import HTTPResponse
from werkzeug.datastructures import MultiDict, Headers
from sanic.request import RequestParameters
from jsonschema import Draft4Validator
from .schemas import (
    validators, filters, scopes, security, base_path, normalize, current)
        from inspect import isawaitable
        def convert_array(type_, v):
            func = convert_funs.get(type_, lambda v: v[0])
            return [func([i]) for i in v]

        for k, values in obj.items():
            prop = self.validator.schema['properties'].get(k, {})
            type_ = prop.get('type')
            fun = convert_funs.get(type_, lambda v: v[0])
            if type_ == 'array':
                item_type = prop.get('items', {}).get('type')
                result[k] = convert_array(item_type, values)
            else:
                result[k] = fun(values)
        return result

    def validate(self, value):
        value = self.type_convert(value)
        errors = list(e.message for e in self.validator.iter_errors(value))
        return normalize(self.validator.schema, value)[0], errors


def request_validate(view):

    @wraps(view)
    def wrapper(*args, **kwargs):
        request = args[1]
        endpoint = _path_to_endpoint(request.uri_template)
        current.request = request
        # scope
        if (endpoint, request.method) in scopes and not set(

# Path: apis/v1/schemas.py
# class Current(object):
# class Security(object):
#     class DataWrapper(object):
#     def __init__(self):
#     def scopes(self):
#     def scopes_loader(self, func):
# def merge_default(schema, value, get_first=True):
# def normalize(schema, data, required_defaults=None):
#         def __init__(self, data):
#         def get(self, key, default=None):
#         def has(self, key):
#         def keys(self):
#         def get_check(self, key, default=None):
#     def _merge_dict(src, dst):
#     def _normalize_dict(schema, data):
#     def _normalize_list(schema, data):
#     def _normalize_default(schema, data):
#     def _normalize(schema, data):


# Path: apis/v1/validators.py
import re
import json
import six
from datetime import date
from functools import wraps
from sanic import response
from sanic.exceptions import ServerError
from sanic.response import HTTPResponse
from werkzeug.datastructures import MultiDict, Headers
from sanic.request import RequestParameters
from jsonschema import Draft4Validator
from .schemas import (
    validators, filters, scopes, security, base_path, normalize, current)
        from inspect import isawaitable

        def convert_array(type_, v):
            func = convert_funs.get(type_, lambda v: v[0])
            return [func([i]) for i in v]

        for k, values in obj.items():
            prop = self.validator.schema['properties'].get(k, {})
            type_ = prop.get('type')
            fun = convert_funs.get(type_, lambda v: v[0])
            if type_ == 'array':
                item_type = prop.get('items', {}).get('type')
                result[k] = convert_array(item_type, values)
            else:
                result[k] = fun(values)
        return result

    def validate(self, value):
        value = self.type_convert(value)
        errors = list(e.message for e in self.validator.iter_errors(value))
        return normalize(self.validator.schema, value)[0], errors


def request_validate(view):

    @wraps(view)
    def wrapper(*args, **kwargs):
        request = args[1]
        endpoint = _path_to_endpoint(request.uri_template)
        current.request = request
        # scope
        if (endpoint, request.method) in scopes and not set(

                scopes[(endpoint, request.method)]).issubset(set(security.scopes)):