api-foundry 0.1.20__tar.gz → 0.1.21__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.1.20 → api_foundry-0.1.21}/PKG-INFO +1 -1
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/utils/model_factory.py +113 -36
- {api_foundry-0.1.20 → api_foundry-0.1.21}/pyproject.toml +1 -1
- {api_foundry-0.1.20 → api_foundry-0.1.21}/.gitignore +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/LICENSE +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/__init__.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/iac/gateway_spec.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/iac/pulumi/api_foundry.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/scripts/install_secret.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/api_foundry/utils/logger.py +0 -0
- {api_foundry-0.1.20 → api_foundry-0.1.21}/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.1.
|
|
3
|
+
Version: 0.1.21
|
|
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
|
|
@@ -26,8 +26,10 @@ SUPPORTED_TYPES = {
|
|
|
26
26
|
"date",
|
|
27
27
|
"date-time",
|
|
28
28
|
"time",
|
|
29
|
-
# Note: OpenAPI uses type 'number' with
|
|
30
|
-
#
|
|
29
|
+
# Note: OpenAPI uses base type 'number' with optional
|
|
30
|
+
# format 'float'/'double'. These formats are accepted and
|
|
31
|
+
# normalized to api_type='number' while preserving the
|
|
32
|
+
# original format in a separate attribute for mapping.
|
|
31
33
|
"uuid",
|
|
32
34
|
"array",
|
|
33
35
|
"object",
|
|
@@ -35,10 +37,16 @@ SUPPORTED_TYPES = {
|
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
class OpenAPIElement:
|
|
38
|
-
"""
|
|
40
|
+
"""
|
|
41
|
+
Base class for OpenAPI elements like schema properties and
|
|
42
|
+
associations.
|
|
43
|
+
"""
|
|
39
44
|
|
|
40
45
|
def to_dict(self) -> Dict[str, Any]:
|
|
41
|
-
"""
|
|
46
|
+
"""
|
|
47
|
+
Convert the OpenAPI element to a dictionary, including nested
|
|
48
|
+
properties.
|
|
49
|
+
"""
|
|
42
50
|
return {
|
|
43
51
|
k: (v.to_dict() if isinstance(v, OpenAPIElement) else v)
|
|
44
52
|
for k, v in self.__dict__.items()
|
|
@@ -47,13 +55,27 @@ class OpenAPIElement:
|
|
|
47
55
|
|
|
48
56
|
|
|
49
57
|
class SchemaObjectProperty(OpenAPIElement):
|
|
50
|
-
"""
|
|
58
|
+
"""
|
|
59
|
+
Represents a property of a schema object in the OpenAPI
|
|
60
|
+
specification.
|
|
61
|
+
"""
|
|
51
62
|
|
|
52
63
|
def __init__(self, schema_name: str, name: str, prop: Dict[str, Any]):
|
|
53
64
|
super().__init__()
|
|
54
65
|
self.api_name = name
|
|
55
|
-
#
|
|
56
|
-
|
|
66
|
+
# Base OpenAPI type and format
|
|
67
|
+
base_type = prop.get("type") or "string"
|
|
68
|
+
api_format = prop.get("format")
|
|
69
|
+
# Preserve numeric formats (float/double) but normalize api_type
|
|
70
|
+
# to 'number'
|
|
71
|
+
if base_type == "number" and api_format in {"float", "double"}:
|
|
72
|
+
self.api_type = "number"
|
|
73
|
+
self.numeric_format = api_format
|
|
74
|
+
else:
|
|
75
|
+
# Maintain prior behavior for date/date-time/time/uuid by
|
|
76
|
+
# allowing format as type
|
|
77
|
+
self.api_type = api_format or base_type
|
|
78
|
+
self.numeric_format = None
|
|
57
79
|
# Validate the raw OpenAPI 'type' first to catch invalid base types
|
|
58
80
|
raw_type = prop.get("type")
|
|
59
81
|
if raw_type is not None and raw_type not in {
|
|
@@ -67,17 +89,35 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
67
89
|
raise ApplicationException(
|
|
68
90
|
500,
|
|
69
91
|
(
|
|
70
|
-
f"Property: {name} in schema object: {schema_name}
|
|
71
|
-
|
|
92
|
+
f"Property: {name} in schema object: {schema_name} "
|
|
93
|
+
f"of type: {raw_type} is not a valid type"
|
|
72
94
|
),
|
|
73
95
|
)
|
|
74
96
|
if self.api_type not in SUPPORTED_TYPES:
|
|
75
97
|
raise ApplicationException(
|
|
76
98
|
500,
|
|
77
|
-
|
|
99
|
+
(
|
|
100
|
+
f"Property: {name} in schema object: {schema_name} "
|
|
101
|
+
f"of type: {self.api_type} is not a valid type"
|
|
102
|
+
),
|
|
78
103
|
)
|
|
79
104
|
self.column_name = prop.get("x-af-column-name") or name
|
|
80
|
-
|
|
105
|
+
# Choose column type. If user didn't specify x-af-column-type and this
|
|
106
|
+
# is a numeric with a float/double format, apply a sensible default
|
|
107
|
+
# (Postgres: float -> real, double -> double precision).
|
|
108
|
+
if prop.get("x-af-column-type"):
|
|
109
|
+
self.column_type = prop.get("x-af-column-type")
|
|
110
|
+
elif base_type == "number" and self.numeric_format in {
|
|
111
|
+
"float",
|
|
112
|
+
"double",
|
|
113
|
+
}:
|
|
114
|
+
self.column_type = (
|
|
115
|
+
"real"
|
|
116
|
+
if self.numeric_format == "float"
|
|
117
|
+
else "double precision"
|
|
118
|
+
)
|
|
119
|
+
else:
|
|
120
|
+
self.column_type = prop.get("type") or "string"
|
|
81
121
|
self.required = prop.get("required", False)
|
|
82
122
|
self.min_length = prop.get("minLength", None)
|
|
83
123
|
self.max_length = prop.get("maxLength", None)
|
|
@@ -88,9 +128,13 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
88
128
|
self.concurrency_control = self._concurrency_control(schema_name, prop)
|
|
89
129
|
# For embedded objects/arrays
|
|
90
130
|
self.sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
|
|
91
|
-
self.items_sub_properties: Optional[
|
|
131
|
+
self.items_sub_properties: Optional[
|
|
132
|
+
Dict[str, SchemaObjectProperty]
|
|
133
|
+
] = None
|
|
92
134
|
|
|
93
|
-
def _concurrency_control(
|
|
135
|
+
def _concurrency_control(
|
|
136
|
+
self, schema_name: str, prop_dict: dict
|
|
137
|
+
) -> Optional[str]:
|
|
94
138
|
concurrency_control = prop_dict.get("x-af-concurrency-control", None)
|
|
95
139
|
if concurrency_control:
|
|
96
140
|
concurrency_control = concurrency_control.lower()
|
|
@@ -109,7 +153,9 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
109
153
|
class SchemaObjectKey(SchemaObjectProperty):
|
|
110
154
|
"""Represents a primary key in a schema object."""
|
|
111
155
|
|
|
112
|
-
def __init__(
|
|
156
|
+
def __init__(
|
|
157
|
+
self, schema_name: str, name: str, properties: Dict[str, Any]
|
|
158
|
+
):
|
|
113
159
|
super().__init__(schema_name, name, properties)
|
|
114
160
|
self.key_type = properties.get("x-af-primary-key", "auto")
|
|
115
161
|
|
|
@@ -166,7 +212,9 @@ class SchemaObject(OpenAPIElement):
|
|
|
166
212
|
self.properties = self._resolve_properties(schema_object)
|
|
167
213
|
self.primary_key = self._get_primary_key(schema_object)
|
|
168
214
|
self.relations = self._resolve_relations(schema_object)
|
|
169
|
-
self.concurrency_property = self._get_concurrency_property(
|
|
215
|
+
self.concurrency_property = self._get_concurrency_property(
|
|
216
|
+
schema_object
|
|
217
|
+
)
|
|
170
218
|
self.permissions = self._get_permissions(schema_object)
|
|
171
219
|
|
|
172
220
|
def _get_table_name(self, schema_object: dict) -> str:
|
|
@@ -187,7 +235,8 @@ class SchemaObject(OpenAPIElement):
|
|
|
187
235
|
def _resolve_property(
|
|
188
236
|
self, property_name: str, prop: Dict[str, Any]
|
|
189
237
|
) -> Optional[SchemaObjectProperty]:
|
|
190
|
-
# Validate raw OpenAPI base type early to catch invalid types
|
|
238
|
+
# Validate raw OpenAPI base type early to catch invalid types
|
|
239
|
+
# like 'float'
|
|
191
240
|
raw_type = prop.get("type")
|
|
192
241
|
if raw_type is not None and raw_type not in {
|
|
193
242
|
"string",
|
|
@@ -200,8 +249,8 @@ class SchemaObject(OpenAPIElement):
|
|
|
200
249
|
raise ApplicationException(
|
|
201
250
|
500,
|
|
202
251
|
(
|
|
203
|
-
f"Property: {property_name} in schema object:
|
|
204
|
-
|
|
252
|
+
f"Property: {property_name} in schema object: "
|
|
253
|
+
f"{self.api_name} of type: {raw_type} is not a valid type"
|
|
205
254
|
),
|
|
206
255
|
)
|
|
207
256
|
# If $ref is present, treat as relation
|
|
@@ -256,48 +305,69 @@ class SchemaObject(OpenAPIElement):
|
|
|
256
305
|
property_name, prop, self.primary_key
|
|
257
306
|
)
|
|
258
307
|
# Array of $ref (array relation)
|
|
259
|
-
elif
|
|
308
|
+
elif (
|
|
309
|
+
prop.get("type") == "array"
|
|
310
|
+
and "$ref" in prop.get("items", {})
|
|
311
|
+
):
|
|
260
312
|
relations[property_name.lower()] = SchemaObjectAssociation(
|
|
261
313
|
property_name, prop, self.primary_key
|
|
262
314
|
)
|
|
263
315
|
return relations
|
|
264
316
|
|
|
265
317
|
def _get_concurrency_property(self, schema_object: dict) -> Optional[str]:
|
|
266
|
-
concurrency_property_name = schema_object.get(
|
|
318
|
+
concurrency_property_name = schema_object.get(
|
|
319
|
+
"x-af-concurrency-control"
|
|
320
|
+
)
|
|
267
321
|
if (
|
|
268
322
|
concurrency_property_name
|
|
269
323
|
and concurrency_property_name not in self.properties
|
|
270
324
|
):
|
|
271
325
|
raise ApplicationException(
|
|
272
326
|
500,
|
|
273
|
-
|
|
327
|
+
(
|
|
328
|
+
"Invalid concurrency property: "
|
|
329
|
+
f"{concurrency_property_name} not found in properties."
|
|
330
|
+
),
|
|
274
331
|
)
|
|
275
332
|
return concurrency_property_name
|
|
276
333
|
|
|
277
334
|
def _get_primary_key(self, schema_object: dict) -> Optional[str]:
|
|
278
|
-
for property_name, properties in schema_object.get(
|
|
335
|
+
for property_name, properties in schema_object.get(
|
|
336
|
+
"properties", {}
|
|
337
|
+
).items():
|
|
279
338
|
if "x-af-primary-key" in properties:
|
|
280
|
-
|
|
281
|
-
|
|
339
|
+
prop_obj = self.properties[property_name]
|
|
340
|
+
prop_obj.key_type = properties.get(
|
|
341
|
+
"x-af-primary-key", "auto"
|
|
342
|
+
)
|
|
282
343
|
|
|
283
|
-
if
|
|
344
|
+
if prop_obj.key_type not in [
|
|
345
|
+
"manual",
|
|
346
|
+
"uuid",
|
|
347
|
+
"auto",
|
|
348
|
+
"sequence",
|
|
349
|
+
]:
|
|
284
350
|
raise ApplicationException(
|
|
285
351
|
500,
|
|
286
352
|
(
|
|
287
|
-
f"Invalid primary key type '{
|
|
353
|
+
f"Invalid primary key type '{prop_obj.key_type}' "
|
|
288
354
|
+ f"in schema object '{self.api_name}'"
|
|
289
355
|
+ f", property '{property_name}'"
|
|
290
356
|
),
|
|
291
357
|
)
|
|
292
358
|
|
|
293
|
-
if
|
|
294
|
-
|
|
295
|
-
|
|
359
|
+
if prop_obj.key_type == "sequence":
|
|
360
|
+
prop_obj.sequence_name = properties.get(
|
|
361
|
+
"x-af-sequence-name", None
|
|
362
|
+
)
|
|
363
|
+
if not prop_obj.sequence_name:
|
|
296
364
|
raise ApplicationException(
|
|
297
365
|
500,
|
|
298
366
|
(
|
|
299
|
-
"Sequence-based primary keys must have a
|
|
300
|
-
|
|
367
|
+
"Sequence-based primary keys must have a "
|
|
368
|
+
"sequence name "
|
|
369
|
+
+ f"in schema object '{self.api_name}', "
|
|
370
|
+
+ f"property '{property_name}'"
|
|
301
371
|
),
|
|
302
372
|
)
|
|
303
373
|
return property_name
|
|
@@ -369,7 +439,10 @@ class SchemaObject(OpenAPIElement):
|
|
|
369
439
|
|
|
370
440
|
|
|
371
441
|
class PathOperation(OpenAPIElement):
|
|
372
|
-
"""
|
|
442
|
+
"""
|
|
443
|
+
Represents a single operation (method) on a path in the OpenAPI
|
|
444
|
+
specification.
|
|
445
|
+
"""
|
|
373
446
|
|
|
374
447
|
def __init__(self, path: str, method: str, path_operation: Dict[str, Any]):
|
|
375
448
|
super().__init__()
|
|
@@ -431,9 +504,10 @@ class PathOperation(OpenAPIElement):
|
|
|
431
504
|
return properties
|
|
432
505
|
|
|
433
506
|
def _get_permissions(self, path_operation: dict) -> dict:
|
|
434
|
-
"""
|
|
435
|
-
|
|
436
|
-
Also normalizes action names so 'create'/'update' map to
|
|
507
|
+
"""
|
|
508
|
+
Extract permissions from a path operation using x-af-permissions
|
|
509
|
+
only. Also normalizes action names so 'create'/'update' map to
|
|
510
|
+
'write'.
|
|
437
511
|
"""
|
|
438
512
|
raw_permissions = path_operation.get("x-af-permissions") or {}
|
|
439
513
|
|
|
@@ -510,7 +584,10 @@ class ModelFactory:
|
|
|
510
584
|
return merged
|
|
511
585
|
|
|
512
586
|
def resolve_all_refs(self, spec: Dict[str, Any]) -> Dict[str, Any]:
|
|
513
|
-
"""
|
|
587
|
+
"""
|
|
588
|
+
Recursively resolve all $ref references in an OpenAPI
|
|
589
|
+
specification.
|
|
590
|
+
"""
|
|
514
591
|
|
|
515
592
|
def resolve(obj: Any) -> Any:
|
|
516
593
|
if isinstance(obj, dict):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|