|
18 | 18 | from __future__ import annotations
|
19 | 19 |
|
20 | 20 | import json
|
| 21 | +from typing import Any |
21 | 22 |
|
22 | 23 | from pydantic import Field, field_validator
|
23 | 24 | from pydantic_core.core_schema import ValidationInfo
|
24 | 25 |
|
25 | 26 | from airflow.api_fastapi.core_api.base import BaseModel
|
| 27 | +from airflow.api_fastapi.core_api.datamodels.common import BulkAction, BulkBaseAction |
26 | 28 | from airflow.utils.log.secrets_masker import redact
|
27 | 29 |
|
28 | 30 |
|
@@ -90,8 +92,71 @@ class ConnectionBody(BaseModel):
|
90 | 92 | extra: str | None = Field(default=None)
|
91 | 93 |
|
92 | 94 |
|
93 |
| -class ConnectionBulkBody(BaseModel): |
94 |
| - """Connections Serializer for requests body.""" |
| 95 | +class ConnectionBulkCreateAction(BulkBaseAction): |
| 96 | + """Bulk Create Variable serializer for request bodies.""" |
| 97 | + |
| 98 | + action: BulkAction = BulkAction.CREATE |
| 99 | + connections: list[ConnectionBody] = Field(..., description="A list of connections to be created.") |
| 100 | + |
| 101 | + |
| 102 | +class ConnectionBulkUpdateAction(BulkBaseAction): |
| 103 | + """Bulk Update Connection serializer for request bodies.""" |
| 104 | + |
| 105 | + action: BulkAction = BulkAction.UPDATE |
| 106 | + connections: list[ConnectionBody] = Field(..., description="A list of connections to be updated.") |
95 | 107 |
|
96 |
| - connections: list[ConnectionBody] |
97 |
| - overwrite: bool | None = Field(default=False) |
| 108 | + |
| 109 | +class ConnectionBulkDeleteAction(BulkBaseAction): |
| 110 | + """Bulk Delete Connection serializer for request bodies.""" |
| 111 | + |
| 112 | + action: BulkAction = BulkAction.DELETE |
| 113 | + connection_ids: list[str] = Field(..., description="A list of connection IDs to be deleted.") |
| 114 | + |
| 115 | + |
| 116 | +class ConnectionBulkBody(BaseModel): |
| 117 | + """Request body for bulk Connection operations (create, update, delete).""" |
| 118 | + |
| 119 | + actions: list[ConnectionBulkCreateAction | ConnectionBulkUpdateAction | ConnectionBulkDeleteAction] = ( |
| 120 | + Field(..., description="A list of Connection actions to perform.") |
| 121 | + ) |
| 122 | + |
| 123 | + |
| 124 | +class ConnectionBulkActionResponse(BaseModel): |
| 125 | + """ |
| 126 | + Serializer for individual bulk action responses. |
| 127 | +
|
| 128 | + Represents the outcome of a single bulk operation (create, update, or delete). |
| 129 | + The response includes a list of successful connection_ids and any errors encountered during the operation. |
| 130 | + This structure helps users understand which key actions succeeded and which failed. |
| 131 | + """ |
| 132 | + |
| 133 | + success: list[str] = Field( |
| 134 | + default_factory=list, description="A list of connection_ids representing successful operations." |
| 135 | + ) |
| 136 | + errors: list[dict[str, Any]] = Field( |
| 137 | + default_factory=list, |
| 138 | + description="A list of errors encountered during the operation, each containing details about the issue.", |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +class ConnectionBulkResponse(BaseModel): |
| 143 | + """ |
| 144 | + Serializer for responses to bulk connection operations. |
| 145 | +
|
| 146 | + This represents the results of create, update, and delete actions performed on connections in bulk. |
| 147 | + Each action (if requested) is represented as a field containing details about successful connection_ids and any encountered errors. |
| 148 | + Fields are populated in the response only if the respective action was part of the request, else are set None. |
| 149 | + """ |
| 150 | + |
| 151 | + create: ConnectionBulkActionResponse | None = Field( |
| 152 | + default=None, |
| 153 | + description="Details of the bulk create operation, including successful connection_ids and errors.", |
| 154 | + ) |
| 155 | + update: ConnectionBulkActionResponse | None = Field( |
| 156 | + default=None, |
| 157 | + description="Details of the bulk update operation, including successful connection_ids and errors.", |
| 158 | + ) |
| 159 | + delete: ConnectionBulkActionResponse | None = Field( |
| 160 | + default=None, |
| 161 | + description="Details of the bulk delete operation, including successful connection_ids and errors.", |
| 162 | + ) |
0 commit comments