Skip to content

Commit 045add4

Browse files
update to library checks pipeline check version logic
1 parent 5d51a37 commit 045add4

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

scripts/import-documents.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
# -----------------------------------
88
# INIT FIREBASE
99
# -----------------------------------
10-
11-
# Add path to service account credentials
12-
cred = credentials.Certificate()
13-
10+
cred = credentials.Certificate(
11+
"C:\\Users\\Owner\\Code\\benefit-decision-toolkit\\builder-api\\src\\main\\resources\\benefit-decision-toolkit-play-69aed1a8f86b.json")
1412
firebase_admin.initialize_app(cred, {
1513
"storageBucket": "benefit-decision-toolkit-play.firebasestorage.app"
1614
})

scripts/parse-schema.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def walk(name, node):
131131
# --------------------------------------------
132132
# Process entire OpenAPI document
133133
# --------------------------------------------
134-
def extract_check_records(openapi):
134+
def extract_check_records(openapi, version):
135135
components = openapi.get("components", {}).get("schemas", {})
136136
paths = openapi.get("paths", {})
137137

@@ -147,9 +147,6 @@ def extract_check_records(openapi):
147147
# Split the URL into parts
148148
segments = path.strip("/").split("/")
149149

150-
# Extract version (always after 'api')
151-
version = segments[1]
152-
153150
# Find index of 'checks'
154151
checks_index = segments.index("checks")
155152

@@ -196,6 +193,47 @@ def extract_check_records(openapi):
196193
return output
197194

198195

196+
def transform_parameters(properties_obj):
197+
"""Convert properties dict to a list of {key, name, type} objects."""
198+
transformed = []
199+
200+
for key, val in properties_obj.items():
201+
# Determine the property's type
202+
prop_type = val.get("type", "object") # fallback
203+
204+
transformed.append({
205+
"key": key,
206+
"label": key,
207+
"required": False,
208+
"type": prop_type
209+
})
210+
211+
return transformed
212+
213+
214+
def transform_parameters_format(data):
215+
"""Transform all `inputs.parameters.properties` in the provided list."""
216+
for check in data:
217+
inputs = check.get("inputs", {})
218+
parameters = inputs.get("parameters")
219+
220+
# Only transform objects that follow the original structure
221+
if isinstance(parameters, dict) and "properties" in parameters:
222+
properties_obj = parameters["properties"]
223+
new_parameters = transform_parameters(properties_obj)
224+
225+
# Replace object with the transformed list
226+
check["parameters"] = new_parameters
227+
return data
228+
229+
230+
def transform_situation_format(data):
231+
"""Transform all `inputs.situation` in the provided list."""
232+
for check in data:
233+
check["situation"] = check["inputs"]["situation"]
234+
return data
235+
236+
199237
# --------------------------------------------
200238
# Load your OpenAPI JSON here
201239
# --------------------------------------------
@@ -212,7 +250,14 @@ def extract_check_records(openapi):
212250
# Parse JSON
213251
data = response.json()
214252

215-
check_records = extract_check_records(data)
253+
version = data["info"]["version"]
254+
255+
check_records = extract_check_records(data, version)
256+
check_records = transform_parameters_format(check_records)
257+
check_records = transform_situation_format(check_records)
258+
259+
for check in check_records:
260+
check.pop("inputs")
216261

217262
# Write JSON file using UTF-8 to avoid errors
218263
with open("endpoint_inputs.json", "w", encoding="utf-8") as out:

0 commit comments

Comments
 (0)