Source code for ourobori.docs.swagger_errors

"""
This module contains all functions, classes to create the OutputDefinitions
of errors used for the creation of the swagger-documentation.
It also contains already exsiting OutputDefinitions used by the BaseService.
"""


from pydantic import BaseModel
from pydantic import Schema

from ourobori.docs.swagger import OutputDefinition
from ourobori.services.errors import BaseError
from ourobori.services.errors import InvalidInputException
from ourobori.services.errors import InvalidOutputException
from ourobori.services.errors import ServiceCallException
from ourobori.services.errors import ServiceNotAliveException
from ourobori.services.errors import DatabaseNotAliveException
from ourobori.services.errors import DatabaseTransactionException
from ourobori.services.errors import HostCmdException
from ourobori.services.errors import HostConnectionException
from ourobori.services.errors import HostSCPFromException
from ourobori.services.errors import HostSCPToException


[docs]class SErrorModel(BaseModel): """ The base-schema used for OutputDefinition for the Exceptions. Attributes: status: The http-status-code used for the exception. data: The data contained in the exception. """ status: int = NotImplemented data: dict = NotImplemented
[docs]def create_error_output_def(error_class: BaseError, schema_class: SErrorModel) -> OutputDefinition: """ Wrapper function to create an OutputDefinition by passing an error_class and the corresponding schema_class. Parameters: error_class: The error-class to create the OutputDefinition for. schema_class: The schema-class to create the OutputDefinition for. Returns: output_definition: The created output-definition for the error-class. """ output_definition = OutputDefinition(status_code=str(error_class().status), description=error_class().description, schema=schema_class) return output_definition
class SInvalidInputException(SErrorModel): """ Schema used for the OutputDefinition for the InvalidInputException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(InvalidInputException().status) data: dict = Schema(InvalidInputException().data) class SInvalidOutputException(SErrorModel): """ Schema used for the OutputDefinition for the InvalidOutputException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(InvalidOutputException().status) data: dict = Schema(InvalidOutputException().data) class SServiceCallException(SErrorModel): """ Schema used for the OutputDefinition for the ServiceCallException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(ServiceCallException().status) data: dict = Schema(ServiceCallException().data) class SServiceNotAliveException(SErrorModel): """ Schema used for the OutputDefinition for the ServiceNotAliveException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(ServiceNotAliveException().status) data: dict = Schema(ServiceNotAliveException().data) class SDatabaseNotAliveException(SErrorModel): """ Schema used for the OutputDefinition for the DatabaseNotAliveException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(DatabaseNotAliveException().status) data: dict = Schema(DatabaseNotAliveException().data) class SDatabaseTransactionException(SErrorModel): """ Schema used for the OutputDefinition for the DatabaseTransactionException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(DatabaseTransactionException().status) data: dict = Schema(DatabaseTransactionException().data) class SHostCmdException(SErrorModel): """ Schema used for the OutputDefinition for the HostCmdException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(HostCmdException().status) data: dict = Schema(HostCmdException().data) class SHostSCPFromException(SErrorModel): """ Schema used for the OutputDefinition for the HostSCPFromException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(HostSCPFromException().status) data: dict = Schema(HostSCPFromException().data) class SHostSCPToException(SErrorModel): """ Schema used for the OutputDefinition for the HostSCPToException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(HostSCPToException().status) data: dict = Schema(HostSCPToException().data) class SHostConnectionException(SErrorModel): """ Schema used for the OutputDefinition for the HostConnectionException. Attributes: status: The http-status-code used for this exception. data: The data contained in this exception. """ status: int = Schema(HostConnectionException().status) data: dict = Schema(HostConnectionException().data) ODDatabaseNotAliveException = create_error_output_def( error_class=DatabaseNotAliveException, schema_class=SDatabaseNotAliveException) ODDatabaseTransactionException = create_error_output_def( error_class=DatabaseTransactionException, schema_class=SDatabaseTransactionException) ODHostCmdException = create_error_output_def( error_class=HostCmdException, schema_class=SHostCmdException) ODHostConnectionException = create_error_output_def( error_class=HostConnectionException, schema_class=SHostConnectionException) ODHostSCPFromException = create_error_output_def( error_class=HostSCPFromException, schema_class=SHostSCPFromException) ODHostSCPToException = create_error_output_def( error_class=HostSCPToException, schema_class=SHostSCPToException) ODInvalidInputException = create_error_output_def( error_class=InvalidInputException, schema_class=SInvalidInputException) ODInvalidOutputException = create_error_output_def( error_class=InvalidOutputException, schema_class=SInvalidOutputException) ODServiceCallException = create_error_output_def( error_class=ServiceCallException, schema_class=SServiceCallException) ODServiceNotAliveException = create_error_output_def( error_class=ServiceNotAliveException, schema_class=SServiceNotAliveException) __all__ = ['create_error_output_def', 'ODDatabaseNotAliveException', 'ODDatabaseTransactionException', 'ODHostCmdException', 'ODHostConnectionException', 'ODHostSCPFromException', 'ODHostSCPToException', 'ODInvalidInputException', 'ODInvalidOutputException', 'ODServiceCallException', 'ODServiceNotAliveException', 'SErrorModel', ]