# Path: lepo/apidef/doc.py
# class APIDefinition:
#     version = None
#     path_class = Path
#     operation_class = None
# 
#     def __init__(self, doc):
#         """
#         Instantiate a new Lepo router.
# 
#         :param doc: The OpenAPI definition document.
#         :type doc: dict
#         """
#         self.doc = doc
#         self.resolver = RefResolver('', self.doc)
# 
#     def resolve_reference(self, ref):
#         """
#         Resolve a JSON Pointer object reference to the object itself.
# 
#         :param ref: Reference string (`#/foo/bar`, for instance)
#         :return: The object, if found
#         :raises jsonschema.exceptions.RefResolutionError: if there is trouble resolving the reference
#         """
#         url, resolved = self.resolver.resolve(ref)
#         return resolved
# 
#     def get_path_mapping(self, path):
#         return maybe_resolve(self.doc['paths'][path], self.resolve_reference)
# 
#     def get_path_names(self):
#         yield from self.doc['paths']
# 
#     def get_path(self, path):
#         """
#         Construct a Path object from a path string.
# 
#         The Path string must be declared in the API.
# 
#         :type path: str
#         :rtype: lepo.path.Path
#         """
#         mapping = self.get_path_mapping(path)
#         return self.path_class(api=self, path=path, mapping=mapping)
# 
#     def get_paths(self):
#         """
#         Iterate over all Path objects declared by the API.
# 
#         :rtype: Iterable[lepo.path.Path]
#         """
#         for path_name in self.get_path_names():
#             yield self.get_path(path_name)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """
#         Construct an APIDefinition by parsing the given `filename`.
# 
#         If PyYAML is installed, YAML files are supported.
#         JSON files are always supported.
# 
#         :param filename: The filename to read.
#         :rtype: APIDefinition
#         """
#         with open(filename) as infp:
#             if filename.endswith('.yaml') or filename.endswith('.yml'):
#                 import yaml
#                 data = yaml.safe_load(infp)
#             else:
#                 import json
#                 data = json.load(infp)
#         return cls.from_data(data)
# 
#     @classmethod
#     def from_data(cls, data):
#         version = parse_version(data)
#         if version == SWAGGER_2:
#             return Swagger2APIDefinition(data)
#         if version == OPENAPI_3:
#             return OpenAPI3APIDefinition(data)
#         raise NotImplementedError('We can never get here.')  # pragma: no cover
# 
#     @classmethod
#     def from_yaml(cls, yaml_string):
#         from yaml import safe_load
#         return cls.from_data(safe_load(yaml_string))
# 
# Path: lepo/parameter_utils.py
# def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
#     """
#     :param request: HttpRequest with attached api_info
#     :type request: HttpRequest
#     :type view_kwargs: dict[str, object]
#     :type capture_errors: bool
#     :rtype: dict[str, object]
#     """
#     if view_kwargs is None:
#         view_kwargs = {}
#     params = {}
#     errors = {}
#     for param in request.api_info.operation.parameters:
#         try:
#             value = param.get_value(request, view_kwargs)
#             if value is NO_VALUE:
#                 if param.has_default:
#                     params[param.name] = param.default
#                 elif param.required:  # Required but missing
#                     errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
#                 continue  # No value, or a default was added, or an error was added.
#             params[param.name] = param.cast(request.api_info.api, value)
#         except (NotImplementedError, ImproperlyConfigured):
#             raise
#         except Exception as e:
#             if not capture_errors:
#                 raise
#             errors[param.name] = e
#     if errors:
#         raise ErroneousParameters(errors, params)
#     return params
# 
# Path: lepo_tests/tests/utils.py
# def make_request_for_operation(operation, method='GET', query_string=''):
#     request = RequestFactory().generic(method=method, path=operation.path.path, QUERY_STRING=query_string)
#     request.api_info = APIInfo(operation)
#     return request


from lepo.apidef.doc import APIDefinition
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import make_request_for_operation
      parameters:
        - name: format
          in: path
          style: label
          explode: false
          schema:
            type: object
            items:
              type: string
        - name: thing
          in: path
          schema:
            type: string
''')


def test_label_parameter():
    request = make_request_for_operation(doc.get_path('/single/{thing}/data{format}').get_operation('get'))
    params = read_parameters(request, {
        'thing': 'blorp',
        'format': '.json',
    })
    assert params == {
        'thing': 'blorp',
        'format': 'json',  # Notice the missing dot
    }


def test_label_array_parameter():
    request = make_request_for_operation(doc.get_path('/array/{thing}/data{format}').get_operation('get'))

# Path: lepo/apidef/doc.py
# class APIDefinition:
#     version = None
#     path_class = Path
#     operation_class = None
# 
#     def __init__(self, doc):
#         """
#         Instantiate a new Lepo router.
# 
#         :param doc: The OpenAPI definition document.
#         :type doc: dict
#         """
#         self.doc = doc
#         self.resolver = RefResolver('', self.doc)
# 
#     def resolve_reference(self, ref):
#         """
#         Resolve a JSON Pointer object reference to the object itself.
# 
#         :param ref: Reference string (`#/foo/bar`, for instance)
#         :return: The object, if found
#         :raises jsonschema.exceptions.RefResolutionError: if there is trouble resolving the reference
#         """
#         url, resolved = self.resolver.resolve(ref)
#         return resolved
# 
#     def get_path_mapping(self, path):
#         return maybe_resolve(self.doc['paths'][path], self.resolve_reference)
# 
#     def get_path_names(self):
#         yield from self.doc['paths']
# 
#     def get_path(self, path):
#         """
#         Construct a Path object from a path string.
# 
#         The Path string must be declared in the API.
# 
#         :type path: str
#         :rtype: lepo.path.Path
#         """
#         mapping = self.get_path_mapping(path)
#         return self.path_class(api=self, path=path, mapping=mapping)
# 
#     def get_paths(self):
#         """
#         Iterate over all Path objects declared by the API.
# 
#         :rtype: Iterable[lepo.path.Path]
#         """
#         for path_name in self.get_path_names():
#             yield self.get_path(path_name)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """
#         Construct an APIDefinition by parsing the given `filename`.
# 
#         If PyYAML is installed, YAML files are supported.
#         JSON files are always supported.
# 
#         :param filename: The filename to read.
#         :rtype: APIDefinition
#         """
#         with open(filename) as infp:
#             if filename.endswith('.yaml') or filename.endswith('.yml'):
#                 import yaml
#                 data = yaml.safe_load(infp)
#             else:
#                 import json
#                 data = json.load(infp)
#         return cls.from_data(data)
# 
#     @classmethod
#     def from_data(cls, data):
#         version = parse_version(data)
#         if version == SWAGGER_2:
#             return Swagger2APIDefinition(data)
#         if version == OPENAPI_3:
#             return OpenAPI3APIDefinition(data)
#         raise NotImplementedError('We can never get here.')  # pragma: no cover
# 
#     @classmethod
#     def from_yaml(cls, yaml_string):
#         from yaml import safe_load
#         return cls.from_data(safe_load(yaml_string))
# 
# Path: lepo/parameter_utils.py
# def read_parameters(request, view_kwargs=None, capture_errors=False):  # noqa: C901
#     """
#     :param request: HttpRequest with attached api_info
#     :type request: HttpRequest
#     :type view_kwargs: dict[str, object]
#     :type capture_errors: bool
#     :rtype: dict[str, object]
#     """
#     if view_kwargs is None:
#         view_kwargs = {}
#     params = {}
#     errors = {}
#     for param in request.api_info.operation.parameters:
#         try:
#             value = param.get_value(request, view_kwargs)
#             if value is NO_VALUE:
#                 if param.has_default:
#                     params[param.name] = param.default
#                 elif param.required:  # Required but missing
#                     errors[param.name] = MissingParameter(f'parameter {param.name} is required but missing')
#                 continue  # No value, or a default was added, or an error was added.
#             params[param.name] = param.cast(request.api_info.api, value)
#         except (NotImplementedError, ImproperlyConfigured):
#             raise
#         except Exception as e:
#             if not capture_errors:
#                 raise
#             errors[param.name] = e
#     if errors:
#         raise ErroneousParameters(errors, params)
#     return params
# 
# Path: lepo_tests/tests/utils.py
# def make_request_for_operation(operation, method='GET', query_string=''):
#     request = RequestFactory().generic(method=method, path=operation.path.path, QUERY_STRING=query_string)
#     request.api_info = APIInfo(operation)
#     return request


# Path: lepo_tests/tests/test_openapi3_label.py
from lepo.apidef.doc import APIDefinition
from lepo.parameter_utils import read_parameters
from lepo_tests.tests.utils import make_request_for_operation

      parameters:
        - name: format
          in: path
          style: label
          explode: false
          schema:
            type: object
            items:
              type: string
        - name: thing
          in: path
          schema:
            type: string
''')


def test_label_parameter():
    request = make_request_for_operation(doc.get_path('/single/{thing}/data{format}').get_operation('get'))
    params = read_parameters(request, {
        'thing': 'blorp',
        'format': '.json',
    })
    assert params == {
        'thing': 'blorp',
        'format': 'json',  # Notice the missing dot
    }


def test_label_array_parameter():
    request = make_request_for_operation(doc.get_path('/array/{thing}/data{format}').get_operation('get'))

    params = read_parameters(request, {