context.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ) -> None:
  14. self.rule = rule
  15. self.method = method
  16. class ContextInterface(object):
  17. def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
  18. raise NotImplementedError()
  19. def get_response(
  20. self,
  21. response: dict,
  22. http_code: int,
  23. ) -> typing.Any:
  24. raise NotImplementedError()
  25. def get_validation_error_response(
  26. self,
  27. error: ProcessValidationError,
  28. http_code: HTTPStatus=HTTPStatus.BAD_REQUEST,
  29. ) -> typing.Any:
  30. raise NotImplementedError()
  31. def find_route(
  32. self,
  33. decorated_controller: 'DecoratedController',
  34. ) -> RouteRepresentation:
  35. raise NotImplementedError()
  36. def get_swagger_path(self, contextualised_rule: str) -> str:
  37. """
  38. Return OpenAPI path with context path
  39. :param contextualised_rule: path of original context
  40. :return: OpenAPI path
  41. """
  42. raise NotImplementedError()