api-foundry 0.8.3__tar.gz → 0.8.5__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.3
3
+ Version: 0.8.5
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__(self, *, open_api_spec: Optional[dict], function: Optional[Function]):
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,198 @@ 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": {"$ref": "#/components/schemas/BatchOperation"},
599
+ },
600
+ "options": {
601
+ "type": "object",
602
+ "properties": {
603
+ "atomic": {
604
+ "type": "boolean",
605
+ "default": True,
606
+ "description": "All-or-nothing transaction",
607
+ },
608
+ "continueOnError": {
609
+ "type": "boolean",
610
+ "default": False,
611
+ "description": ("Continue executing after errors"),
612
+ },
613
+ },
614
+ },
615
+ },
616
+ },
617
+ "BatchOperation": {
618
+ "type": "object",
619
+ "required": ["entity", "action"],
620
+ "properties": {
621
+ "id": {
622
+ "type": "string",
623
+ "description": (
624
+ "Unique operation identifier. Required only if "
625
+ "this operation is referenced by other "
626
+ "operations via depends_on or $ref"
627
+ ),
628
+ "pattern": "^[a-zA-Z0-9_]+$",
629
+ },
630
+ "entity": {
631
+ "type": "string",
632
+ "description": "Target entity name",
633
+ },
634
+ "action": {
635
+ "type": "string",
636
+ "enum": ["create", "read", "update", "delete"],
637
+ "description": "Operation action",
638
+ },
639
+ "store_params": {
640
+ "type": "object",
641
+ "description": "Data to create/update",
642
+ },
643
+ "query_params": {
644
+ "type": "object",
645
+ "description": "Selection criteria",
646
+ },
647
+ "metadata_params": {
648
+ "type": "object",
649
+ "description": "Metadata like __limit, __sort",
650
+ },
651
+ "depends_on": {
652
+ "type": "array",
653
+ "items": {"type": "string"},
654
+ "description": ("IDs of operations that must complete first"),
655
+ },
656
+ "claims": {
657
+ "type": "object",
658
+ "description": "Optional JWT claims override",
659
+ },
660
+ },
661
+ },
662
+ "BatchResponse": {
663
+ "type": "object",
664
+ "properties": {
665
+ "success": {
666
+ "type": "boolean",
667
+ "description": "Overall batch success status",
668
+ },
669
+ "results": {
670
+ "type": "object",
671
+ "additionalProperties": True,
672
+ "description": ("Map of operation IDs to results or errors"),
673
+ },
674
+ "errors": {
675
+ "type": "array",
676
+ "items": {"$ref": "#/components/schemas/OperationError"},
677
+ "description": "List of errors that occurred",
678
+ },
679
+ },
680
+ },
681
+ "OperationError": {
682
+ "type": "object",
683
+ "properties": {
684
+ "operation_id": {
685
+ "type": "string",
686
+ "description": "ID of the failed operation",
687
+ },
688
+ "error": {
689
+ "type": "string",
690
+ "description": "Error message",
691
+ },
692
+ "code": {
693
+ "type": "integer",
694
+ "description": "Error code",
695
+ },
696
+ },
697
+ },
698
+ "ErrorResponse": {
699
+ "type": "object",
700
+ "properties": {
701
+ "error": {
702
+ "type": "string",
703
+ "description": "Error message",
704
+ },
705
+ "details": {
706
+ "type": "object",
707
+ "description": "Additional error details",
708
+ },
709
+ },
710
+ },
711
+ }
712
+
713
+ # Add schemas to the editor's spec by directly accessing components
714
+ # The editor will handle this when generating the final YAML
715
+ import yaml as yaml_lib
716
+
717
+ current_spec = yaml_lib.safe_load(self.editor.yaml)
718
+ if "components" not in current_spec:
719
+ current_spec["components"] = {}
720
+ if "schemas" not in current_spec["components"]:
721
+ current_spec["components"]["schemas"] = {}
722
+
723
+ # Add batch schemas
724
+ for schema_name, schema_def in batch_schemas.items():
725
+ current_spec["components"]["schemas"][schema_name] = schema_def
726
+
727
+ # Update the editor with the modified spec
728
+ self.editor = AWSOpenAPISpecEditor(current_spec)
729
+
730
+ # Add batch endpoint
731
+ self.add_operation(
732
+ path=path,
733
+ method="post",
734
+ operation={
735
+ "summary": "Execute batch operations",
736
+ "description": (
737
+ "Execute multiple database operations in a single "
738
+ "request with dependency resolution and transaction "
739
+ "management."
740
+ ),
741
+ "tags": ["Batch Operations"],
742
+ "requestBody": {
743
+ "required": True,
744
+ "content": {
745
+ "application/json": {
746
+ "schema": {"$ref": "#/components/schemas/BatchRequest"}
747
+ }
748
+ },
749
+ },
750
+ "responses": {
751
+ "200": {
752
+ "description": "Batch execution completed",
753
+ "content": {
754
+ "application/json": {
755
+ "schema": {
756
+ "$ref": ("#/components/schemas/BatchResponse")
757
+ }
758
+ }
759
+ },
760
+ },
761
+ "400": {
762
+ "description": "Invalid batch request",
763
+ "content": {
764
+ "application/json": {
765
+ "schema": {
766
+ "$ref": ("#/components/schemas/ErrorResponse")
767
+ }
768
+ }
769
+ },
770
+ },
771
+ },
772
+ },
773
+ schema_name="batch",
774
+ schema_object={"type": "object"},
775
+ )
776
+
573
777
  def transform_schemas(self, spec_dict):
574
778
  for component_name, component_data in (
575
779
  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,
@@ -162,7 +163,7 @@ class APIFoundry(ComponentResource):
162
163
  )
163
164
 
164
165
  requirements.extend(
165
- ["psycopg2-binary", "pyyaml", "../api_foundry_query_engine"]
166
+ ["psycopg2-binary", "pyyaml", "api_foundry_query_engine"]
166
167
  )
167
168
  if env_vars.get("JWKS_HOST"):
168
169
  requirements.extend(["PyJWT", "cryptography", "requests"])
@@ -182,7 +183,9 @@ 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,
187
+ function=self.api_function,
188
+ batch_path=batch_path,
186
189
  )
187
190
 
188
191
  # Merge gateway_spec.integrations with user-provided integrations
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "api-foundry"
7
- version = "0.8.3"
7
+ version = "0.8.5"
8
8
  authors = [
9
9
  { name="Daniel Repik", email="danrepik@icloud.com" },
10
10
  ]
File without changes
File without changes