Skip to content

Commit 54cf6f1

Browse files
committed
initial commit
1 parent 4131ee5 commit 54cf6f1

File tree

10 files changed

+2521
-3
lines changed

10 files changed

+2521
-3
lines changed

.generator/V2/openapi.yaml

Lines changed: 1285 additions & 0 deletions
Large diffs are not rendered by default.

.generator/config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resources:
2+
reference_table:
3+
read:
4+
method: get
5+
path: /api/v2/reference-tables/tables/{id}
6+
create:
7+
method: post
8+
path: /api/v2/reference-tables/tables
9+
update:
10+
method: patch
11+
path: /api/v2/reference-tables/tables/{id}
12+
delete:
13+
method: delete
14+
path: /api/v2/reference-tables/tables/{id}
15+
16+
datasources:
17+
reference_table:
18+
singular: /api/v2/reference-tables/tables/{id}
19+
plural: /api/v2/reference-tables/tables
20+
reference_table_rows:
21+
singular: /api/v2/reference-tables/tables/{id}/rows
22+
plural: /api/v2/reference-tables/tables/{id}/rows

.generator/src/generator/openapi.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from .utils import (
24
GET_OPERATION,
35
CREATE_OPERATION,
@@ -91,9 +93,29 @@ def get_data_sources(spec: dict, config: dict) -> dict:
9193

9294

9395
def get_terraform_primary_id(operations, path=UPDATE_OPERATION):
94-
update_params = parameters(operations[path]["schema"])
95-
primary_id = operations[path]["path"].split("/")[-1][1:-1]
96-
primary_id_param = update_params.pop(primary_id)
96+
"""
97+
Extract primary ID from path parameters.
98+
99+
Handles path parameters anywhere in the URL, not just at the end.
100+
For example: /api/v2/tables/{id}/rows extracts 'id'
101+
"""
102+
operation_data = operations[path]
103+
path_str = operation_data["path"]
104+
params = parameters(operation_data["schema"])
105+
106+
# Find all path parameters (anything in curly braces like {id})
107+
path_params = re.findall(r'\{([^}]+)\}', path_str)
108+
109+
if not path_params:
110+
raise ValueError(f"No path parameters found in path: {path_str}")
111+
112+
# Use the first path parameter as primary ID
113+
primary_id = path_params[0]
114+
115+
if primary_id not in params:
116+
raise ValueError(f"Path parameter '{primary_id}' not found in operation parameters")
117+
118+
primary_id_param = params.pop(primary_id)
97119

98120
return {"schema": parameter_schema(primary_id_param), "name": primary_id}
99121

0 commit comments

Comments
 (0)