api-foundry 0.8.2__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: api-foundry
3
- Version: 0.8.2
3
+ Version: 0.8.3
4
4
  Summary: The `api_foundry` project is a powerful tool designed to automate the deployment of REST APIs on AWS using Lambda services to access and interact with relational databases (RDBMS). This project leverages the OpenAPI specification to define and manage the APIs
5
5
  Project-URL: Documentation, https://github.com/DanRepik/api-foundry
6
6
  Project-URL: Source, https://github.com/DanRepik/api-foundry
@@ -127,6 +127,8 @@ class SchemaObjectProperty(OpenAPIElement):
127
127
  # Value injection attributes
128
128
  self.inject_value = prop.get("x-af-inject-value", None)
129
129
  self.inject_on = self._parse_inject_on(name, prop) or None
130
+ # Soft delete configuration
131
+ self.soft_delete = self._parse_soft_delete(schema_name, name, prop)
130
132
  # For embedded objects/arrays
131
133
  self.sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
132
134
  self.items_sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
@@ -187,6 +189,80 @@ class SchemaObjectProperty(OpenAPIElement):
187
189
  # Default: inject only on create for safety
188
190
  return ["create"]
189
191
 
192
+ def _parse_soft_delete(
193
+ self, schema_name: str, property_name: str, prop_dict: dict
194
+ ) -> Optional[Dict[str, Any]]:
195
+ """
196
+ Parse x-af-soft-delete attribute with validation.
197
+ """
198
+ soft_delete_config = prop_dict.get("x-af-soft-delete")
199
+ if not soft_delete_config:
200
+ return None
201
+
202
+ if not isinstance(soft_delete_config, dict):
203
+ raise ApplicationException(
204
+ 500,
205
+ f"Invalid x-af-soft-delete configuration for property "
206
+ f"'{property_name}' in schema '{schema_name}'. "
207
+ f"Must be an object with strategy and configuration.",
208
+ )
209
+
210
+ strategy = soft_delete_config.get("strategy")
211
+ if not strategy:
212
+ raise ApplicationException(
213
+ 500,
214
+ f"Missing 'strategy' in x-af-soft-delete configuration "
215
+ f"for property '{property_name}' in schema '{schema_name}'.",
216
+ )
217
+
218
+ valid_strategies = [
219
+ "null_check",
220
+ "boolean_flag",
221
+ "exclude_values",
222
+ "audit_field",
223
+ ]
224
+ if strategy not in valid_strategies:
225
+ raise ApplicationException(
226
+ 500,
227
+ f"Invalid soft delete strategy '{strategy}' for property "
228
+ f"'{property_name}' in schema '{schema_name}'. "
229
+ f"Valid strategies are: {', '.join(valid_strategies)}",
230
+ )
231
+
232
+ # Validate strategy-specific configuration
233
+ if strategy == "boolean_flag":
234
+ active_value = soft_delete_config.get("active_value", True)
235
+ if not isinstance(active_value, bool):
236
+ raise ApplicationException(
237
+ 500,
238
+ f"Property '{property_name}' in schema '{schema_name}' "
239
+ f"uses boolean_flag strategy but active_value is not "
240
+ f"boolean.",
241
+ )
242
+
243
+ elif strategy == "exclude_values":
244
+ values = soft_delete_config.get("values", [])
245
+ if not isinstance(values, list) or not values:
246
+ raise ApplicationException(
247
+ 500,
248
+ f"Property '{property_name}' in schema '{schema_name}' "
249
+ f"uses exclude_values strategy but 'values' is not a "
250
+ f"non-empty list.",
251
+ )
252
+
253
+ elif strategy == "audit_field":
254
+ action = soft_delete_config.get("action")
255
+ valid_actions = ["delete", "restore", "restore_timestamp"]
256
+ if action not in valid_actions:
257
+ raise ApplicationException(
258
+ 500,
259
+ f"Property '{property_name}' in schema '{schema_name}' "
260
+ f"uses audit_field strategy but action '{action}' is not "
261
+ f"valid. Valid actions are: {', '.join(valid_actions)}",
262
+ )
263
+
264
+ return soft_delete_config
265
+
190
266
 
191
267
  class SchemaObjectKey(SchemaObjectProperty):
192
268
  """Represents a primary key in a schema object."""
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "api-foundry"
7
- version = "0.8.2"
7
+ version = "0.8.3"
8
8
  authors = [
9
9
  { name="Daniel Repik", email="danrepik@icloud.com" },
10
10
  ]
File without changes
File without changes