Skip to content

Commit

Permalink
fix: clean up adobe analytics dynamic config support (#1857)
Browse files Browse the repository at this point in the history
Co-authored-by: Sai Sankeerth <[email protected]>
  • Loading branch information
sanpj2292 and Sai Sankeerth authored Jan 23, 2025
1 parent 313db82 commit fed05fa
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 80 deletions.
43 changes: 36 additions & 7 deletions scripts/schemaGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ def get_options_list_for_enum(field):
return options_list


def generate_uiconfig_pattern(field, dbConfig=None) -> str:
"""
Generates the pattern for schema based on the type of field.
Cases:
If dynamicConfigSupported is present in dbConfig:
- Regex is present in ui-config for the field
- Use the regex mentioned in ui-config.
- Regex is not present in ui-config for the field
- Use the regex ^(.{0,100})$.
If dynamicConfigSupported is not present in dbConfig:
- Regex is present in ui-config for the field
- Use the regex mentioned in ui-config & includes dynamic config regex & env regex(if not already present).
- Regex is not present in ui-config for the field
- Use the regex ^(.{0,100})$ & includes dynamic config regex & env regex(if not already present).
"""
# TODO: remove this once all the destinations have been updated with dynamicConfigSupported field
if "dynamicConfigSupported" not in dbConfig:
return generalize_regex_pattern(field) # old way

# regex from ui-config
if "regex" in field:
return field["regex"]
else:
return "^(.{0,100})$"


def generalize_regex_pattern(field):
"""Generates the pattern for schema based on the type of field.
- For type : singleSelect and dynamicSelectForm, the pattern is generated by iterating over options.
Expand Down Expand Up @@ -269,12 +296,12 @@ def generate_schema_for_textinput(field, dbConfig, schema_field_name):
}
if "regex" in field:
textInputSchemaObj["properties"][sourceType]["pattern"] = (
generalize_regex_pattern(field)
generate_uiconfig_pattern(field, dbConfig)
)
else:
textInputSchemaObj = {"type": FieldTypeEnum.STRING.value}
if "regex" in field:
textInputSchemaObj["pattern"] = generalize_regex_pattern(field)
textInputSchemaObj["pattern"] = generate_uiconfig_pattern(field, dbConfig)
return textInputSchemaObj


Expand All @@ -292,7 +319,7 @@ def generate_schema_for_textarea_input(field, dbConfig, schema_field_name):
"""
textareaInputObj = {"type": FieldTypeEnum.STRING.value}
if "regex" in field:
textareaInputObj["pattern"] = generalize_regex_pattern(field)
textareaInputObj["pattern"] = generate_uiconfig_pattern(field, dbConfig)
return textareaInputObj


Expand Down Expand Up @@ -394,7 +421,9 @@ def generate_schema_for_dynamic_custom_form(field, dbConfig, schema_field_name):
and customField["type"] != "singleSelect"
and customField["type"] != "dynamicSelectForm"
):
customFieldSchemaObj["pattern"] = generalize_regex_pattern(customField)
customFieldSchemaObj["pattern"] = generate_uiconfig_pattern(
customField, dbConfig
)

# If the custom field is source dependent, we remove the source keys as it's not required inside custom fields, rather they need to be moved to top.
if isCustomFieldDependentOnSource:
Expand Down Expand Up @@ -510,13 +539,13 @@ def generate_key(forFieldWithTo):
}
if field["type"] == "dynamicSelectForm":
if forFieldWithTo != (field.get("reverse", False) == False):
obj["pattern"] = generalize_regex_pattern(field)
obj["pattern"] = generate_uiconfig_pattern(field, dbConfig)
else:
if "defaultOption" in field:
obj["default"] = field["defaultOption"]["value"]
obj["enum"] = get_options_list_for_enum(field)
else:
obj["pattern"] = generalize_regex_pattern(field)
obj["pattern"] = generate_uiconfig_pattern(field, dbConfig)
return obj

dynamicFormSchemaObject = {}
Expand Down Expand Up @@ -602,7 +631,7 @@ def generate_schema_for_tag_input(field, dbConfig, schema_field_name):
tagItemProps = {
str(field["tagKey"]): {
"type": FieldTypeEnum.STRING.value,
"pattern": generalize_regex_pattern(field),
"pattern": generate_uiconfig_pattern(field, dbConfig),
}
}
tagItem["properties"] = tagItemProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"config": {
"transformAtV1": "processor",
"saveDestinationResponse": true,
"dynamicConfigSupported": ["trackingServerUrl", "reportSuiteIds", "trackingServerSecureUrl"],
"includeKeys": [
"trackingServerUrl",
"reportSuiteIds",
Expand Down
Loading

0 comments on commit fed05fa

Please sign in to comment.