api-foundry 0.8.2__tar.gz → 0.8.4__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.
- {api_foundry-0.8.2 → api_foundry-0.8.4}/PKG-INFO +1 -1
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/iac/gateway_spec.py +220 -1
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/iac/pulumi/api_foundry.py +2 -1
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/utils/model_factory.py +76 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/pyproject.toml +1 -1
- {api_foundry-0.8.2 → api_foundry-0.8.4}/.gitignore +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/LICENSE +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/__init__.py +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/scripts/install_secret.py +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/utils/logger.py +0 -0
- {api_foundry-0.8.2 → api_foundry-0.8.4}/api_foundry/utils/schema_validator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api-foundry
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.4
|
|
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
|
|
@@ -16,9 +16,17 @@ class APISpecEditor:
|
|
|
16
16
|
api_spec: dict
|
|
17
17
|
function: Optional[Function]
|
|
18
18
|
integrations: list[dict]
|
|
19
|
+
batch_path: Optional[str]
|
|
19
20
|
|
|
20
|
-
def __init__(
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
*,
|
|
24
|
+
open_api_spec: Optional[dict],
|
|
25
|
+
function: Optional[Function],
|
|
26
|
+
batch_path: Optional[str] = None,
|
|
27
|
+
):
|
|
21
28
|
self.function = function
|
|
29
|
+
self.batch_path = batch_path
|
|
22
30
|
self.integrations = []
|
|
23
31
|
self.editor = AWSOpenAPISpecEditor(
|
|
24
32
|
copy.deepcopy(open_api_spec) if open_api_spec else None
|
|
@@ -36,6 +44,10 @@ class APISpecEditor:
|
|
|
36
44
|
if schema_name:
|
|
37
45
|
self.generate_crud_operations(schema_name, schema_object)
|
|
38
46
|
|
|
47
|
+
# Generate batch operation endpoint if batch_path is specified
|
|
48
|
+
if self.batch_path:
|
|
49
|
+
self.generate_batch_operation(self.batch_path)
|
|
50
|
+
|
|
39
51
|
# self.editor.remove_attributes_with_pattern("^x-af-.*$")
|
|
40
52
|
|
|
41
53
|
self.editor.correct_schema_names()
|
|
@@ -570,6 +582,213 @@ class APISpecEditor:
|
|
|
570
582
|
schema_object=schema_object,
|
|
571
583
|
)
|
|
572
584
|
|
|
585
|
+
def generate_batch_operation(self, path: str):
|
|
586
|
+
"""Generate batch operations endpoint with full schema definitions."""
|
|
587
|
+
|
|
588
|
+
# Define batch component schemas
|
|
589
|
+
batch_schemas = {
|
|
590
|
+
"BatchRequest": {
|
|
591
|
+
"type": "object",
|
|
592
|
+
"required": ["operations"],
|
|
593
|
+
"properties": {
|
|
594
|
+
"operations": {
|
|
595
|
+
"type": "array",
|
|
596
|
+
"minItems": 1,
|
|
597
|
+
"maxItems": 100,
|
|
598
|
+
"items": {
|
|
599
|
+
"$ref": "#/components/schemas/BatchOperation"
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
"options": {
|
|
603
|
+
"type": "object",
|
|
604
|
+
"properties": {
|
|
605
|
+
"atomic": {
|
|
606
|
+
"type": "boolean",
|
|
607
|
+
"default": True,
|
|
608
|
+
"description": "All-or-nothing transaction",
|
|
609
|
+
},
|
|
610
|
+
"continueOnError": {
|
|
611
|
+
"type": "boolean",
|
|
612
|
+
"default": False,
|
|
613
|
+
"description": (
|
|
614
|
+
"Continue executing after errors"
|
|
615
|
+
),
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
"BatchOperation": {
|
|
622
|
+
"type": "object",
|
|
623
|
+
"required": ["entity", "action"],
|
|
624
|
+
"properties": {
|
|
625
|
+
"id": {
|
|
626
|
+
"type": "string",
|
|
627
|
+
"description": (
|
|
628
|
+
"Unique operation identifier. Required only if "
|
|
629
|
+
"this operation is referenced by other "
|
|
630
|
+
"operations via depends_on or $ref"
|
|
631
|
+
),
|
|
632
|
+
"pattern": "^[a-zA-Z0-9_]+$",
|
|
633
|
+
},
|
|
634
|
+
"entity": {
|
|
635
|
+
"type": "string",
|
|
636
|
+
"description": "Target entity name",
|
|
637
|
+
},
|
|
638
|
+
"action": {
|
|
639
|
+
"type": "string",
|
|
640
|
+
"enum": ["create", "read", "update", "delete"],
|
|
641
|
+
"description": "Operation action",
|
|
642
|
+
},
|
|
643
|
+
"store_params": {
|
|
644
|
+
"type": "object",
|
|
645
|
+
"description": "Data to create/update",
|
|
646
|
+
},
|
|
647
|
+
"query_params": {
|
|
648
|
+
"type": "object",
|
|
649
|
+
"description": "Selection criteria",
|
|
650
|
+
},
|
|
651
|
+
"metadata_params": {
|
|
652
|
+
"type": "object",
|
|
653
|
+
"description": "Metadata like __limit, __sort",
|
|
654
|
+
},
|
|
655
|
+
"depends_on": {
|
|
656
|
+
"type": "array",
|
|
657
|
+
"items": {"type": "string"},
|
|
658
|
+
"description": (
|
|
659
|
+
"IDs of operations that must complete first"
|
|
660
|
+
),
|
|
661
|
+
},
|
|
662
|
+
"claims": {
|
|
663
|
+
"type": "object",
|
|
664
|
+
"description": "Optional JWT claims override",
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
"BatchResponse": {
|
|
669
|
+
"type": "object",
|
|
670
|
+
"properties": {
|
|
671
|
+
"success": {
|
|
672
|
+
"type": "boolean",
|
|
673
|
+
"description": "Overall batch success status",
|
|
674
|
+
},
|
|
675
|
+
"results": {
|
|
676
|
+
"type": "object",
|
|
677
|
+
"additionalProperties": True,
|
|
678
|
+
"description": (
|
|
679
|
+
"Map of operation IDs to results or errors"
|
|
680
|
+
),
|
|
681
|
+
},
|
|
682
|
+
"errors": {
|
|
683
|
+
"type": "array",
|
|
684
|
+
"items": {
|
|
685
|
+
"$ref": "#/components/schemas/OperationError"
|
|
686
|
+
},
|
|
687
|
+
"description": "List of errors that occurred",
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
"OperationError": {
|
|
692
|
+
"type": "object",
|
|
693
|
+
"properties": {
|
|
694
|
+
"operation_id": {
|
|
695
|
+
"type": "string",
|
|
696
|
+
"description": "ID of the failed operation",
|
|
697
|
+
},
|
|
698
|
+
"error": {
|
|
699
|
+
"type": "string",
|
|
700
|
+
"description": "Error message",
|
|
701
|
+
},
|
|
702
|
+
"code": {
|
|
703
|
+
"type": "integer",
|
|
704
|
+
"description": "Error code",
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
"ErrorResponse": {
|
|
709
|
+
"type": "object",
|
|
710
|
+
"properties": {
|
|
711
|
+
"error": {
|
|
712
|
+
"type": "string",
|
|
713
|
+
"description": "Error message",
|
|
714
|
+
},
|
|
715
|
+
"details": {
|
|
716
|
+
"type": "object",
|
|
717
|
+
"description": "Additional error details",
|
|
718
|
+
},
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
# Add schemas to the editor's spec by directly accessing components
|
|
724
|
+
# The editor will handle this when generating the final YAML
|
|
725
|
+
import yaml as yaml_lib
|
|
726
|
+
current_spec = yaml_lib.safe_load(self.editor.yaml)
|
|
727
|
+
if "components" not in current_spec:
|
|
728
|
+
current_spec["components"] = {}
|
|
729
|
+
if "schemas" not in current_spec["components"]:
|
|
730
|
+
current_spec["components"]["schemas"] = {}
|
|
731
|
+
|
|
732
|
+
# Add batch schemas
|
|
733
|
+
for schema_name, schema_def in batch_schemas.items():
|
|
734
|
+
current_spec["components"]["schemas"][schema_name] = schema_def
|
|
735
|
+
|
|
736
|
+
# Update the editor with the modified spec
|
|
737
|
+
self.editor = AWSOpenAPISpecEditor(current_spec)
|
|
738
|
+
|
|
739
|
+
# Add batch endpoint
|
|
740
|
+
self.add_operation(
|
|
741
|
+
path=path,
|
|
742
|
+
method="post",
|
|
743
|
+
operation={
|
|
744
|
+
"summary": "Execute batch operations",
|
|
745
|
+
"description": (
|
|
746
|
+
"Execute multiple database operations in a single "
|
|
747
|
+
"request with dependency resolution and transaction "
|
|
748
|
+
"management."
|
|
749
|
+
),
|
|
750
|
+
"tags": ["Batch Operations"],
|
|
751
|
+
"requestBody": {
|
|
752
|
+
"required": True,
|
|
753
|
+
"content": {
|
|
754
|
+
"application/json": {
|
|
755
|
+
"schema": {
|
|
756
|
+
"$ref": "#/components/schemas/BatchRequest"
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
"responses": {
|
|
762
|
+
"200": {
|
|
763
|
+
"description": "Batch execution completed",
|
|
764
|
+
"content": {
|
|
765
|
+
"application/json": {
|
|
766
|
+
"schema": {
|
|
767
|
+
"$ref": (
|
|
768
|
+
"#/components/schemas/BatchResponse"
|
|
769
|
+
)
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
"400": {
|
|
775
|
+
"description": "Invalid batch request",
|
|
776
|
+
"content": {
|
|
777
|
+
"application/json": {
|
|
778
|
+
"schema": {
|
|
779
|
+
"$ref": (
|
|
780
|
+
"#/components/schemas/ErrorResponse"
|
|
781
|
+
)
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
},
|
|
787
|
+
},
|
|
788
|
+
schema_name="batch",
|
|
789
|
+
schema_object={"type": "object"},
|
|
790
|
+
)
|
|
791
|
+
|
|
573
792
|
def transform_schemas(self, spec_dict):
|
|
574
793
|
for component_name, component_data in (
|
|
575
794
|
spec_dict.get("components", {}).get("schemas", {}).items()
|
|
@@ -121,6 +121,7 @@ class APIFoundry(ComponentResource):
|
|
|
121
121
|
name,
|
|
122
122
|
*,
|
|
123
123
|
api_spec: Union[str, list[str]],
|
|
124
|
+
batch_path: Optional[str] = None,
|
|
124
125
|
secrets: Optional[str] = None,
|
|
125
126
|
environment: Optional[dict[str, Union[str, pulumi.Output[str]]]] = None,
|
|
126
127
|
integrations: Optional[list[dict]] = None,
|
|
@@ -182,7 +183,7 @@ class APIFoundry(ComponentResource):
|
|
|
182
183
|
)
|
|
183
184
|
|
|
184
185
|
gateway_spec = APISpecEditor(
|
|
185
|
-
open_api_spec=api_spec_dict, function=self.api_function
|
|
186
|
+
open_api_spec=api_spec_dict, function=self.api_function, batch_path=batch_path
|
|
186
187
|
)
|
|
187
188
|
|
|
188
189
|
# Merge gateway_spec.integrations with user-provided integrations
|
|
@@ -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."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|