def _api_factory( partial_module_string: str, url_prefix: str, auth_function: Callable | None = None, *, description: str = "", ) -> APIBlueprint: """Register a flask_smorest blueprint.""" # Build out the module import path endpoint_folder = "public" if auth_function is None else "protected" import_name = [ "src", "views", endpoint_folder, partial_module_string, ] import_path: str = ".".join(import_name) # Actually create the blueprint blueprint = APIBlueprint( partial_module_string, import_path, url_prefix=f"/v2/{url_prefix}", description=description, ) # Protect the endpoint with an authorization routine # if one was given if auth_function is not None: blueprint.before_request(auth_function) blueprint.description += "\n\nNOTE: This is a protected endpoint." return blueprint
'DebtorConfig': 'debtors.DebtorConfigEndpoint', 'TransfersList': 'transfers.TransfersListEndpoint', 'Transfer': 'transfers.TransferEndpoint', 'SaveDocument': 'documents.SaveDocumentEndpoint', 'RedirectToDebtorsInfo': 'documents.RedirectToDebtorsInfoEndpoint', 'calc_reservation_deadline': calc_reservation_deadline, 'calc_checkup_datetime': calc_checkup_datetime, } admin_api = Blueprint( 'admin', __name__, url_prefix='/debtors', description="View debtors list, create new debtors.", ) admin_api.before_request(ensure_admin) @admin_api.route('/.debtor-reserve') class RandomDebtorReserveEndpoint(MethodView): @admin_api.arguments(DebtorReservationRequestSchema) @admin_api.response(DebtorReservationSchema(context=context)) @admin_api.doc(operationId='reserveRandomDebtor', security=specs.SCOPE_ACTIVATE, responses={409: specs.CONFLICTING_DEBTOR}) def post(self, debtor_reservation_request): """Reserve an auto-generated debtor ID. **Note:** The reserved debtor ID will be a random valid debtor ID.