context.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. import typing
  3. from http import HTTPStatus
  4. from hapic.processor import RequestParameters
  5. from hapic.processor import ProcessValidationError
  6. if typing.TYPE_CHECKING:
  7. from hapic.decorator import DecoratedController
  8. class RouteRepresentation(object):
  9. def __init__(
  10. self,
  11. rule: str,
  12. method: str,
  13. original_route_object: typing.Any=None,
  14. ) -> None:
  15. self.rule = rule
  16. self.method = method
  17. self.original_route_object = original_route_object
  18. class ContextInterface(object):
  19. def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
  20. raise NotImplementedError()
  21. def get_response(
  22. self,
  23. response: dict,
  24. http_code: int,
  25. ) -> typing.Any:
  26. raise NotImplementedError()
  27. def get_validation_error_response(
  28. self,
  29. error: ProcessValidationError,
  30. http_code: HTTPStatus=HTTPStatus.BAD_REQUEST,
  31. ) -> typing.Any:
  32. raise NotImplementedError()
  33. def find_route(
  34. self,
  35. decorated_controller: 'DecoratedController',
  36. ) -> RouteRepresentation:
  37. raise NotImplementedError()
  38. def get_swagger_path(self, contextualised_rule: str) -> str:
  39. """
  40. Return OpenAPI path with context path
  41. :param contextualised_rule: path of original context
  42. :return: OpenAPI path
  43. """
  44. raise NotImplementedError()