api-foundry 0.8.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: api-foundry
3
- Version: 0.8.3
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__(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,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
@@ -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.4"
8
8
  authors = [
9
9
  { name="Daniel Repik", email="danrepik@icloud.com" },
10
10
  ]
File without changes
File without changes