-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(new-form-builder): updated the regex for initial fields to not allow empty string #1881
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import os | ||
import json | ||
import re | ||
from collections import defaultdict | ||
|
||
|
||
def validate_ui_config_file(file_path): | ||
try: | ||
with open(file_path, "r") as f: | ||
data = json.load(f) | ||
|
||
# Ensure the root data is always an object | ||
if not isinstance(data, dict): | ||
raise ValueError("Root data should be an object") | ||
|
||
# Check if uiConfig is an array | ||
ui_config = data.get("uiConfig", {}) | ||
if isinstance(ui_config, list): | ||
return {"status": "old", "regexes": []} # Mark as old config | ||
|
||
# If uiConfig is an object, validate the structure | ||
if isinstance(ui_config, dict): | ||
base_template = ui_config.get("baseTemplate", []) | ||
if not isinstance(base_template, list) or not base_template: | ||
raise ValueError("'baseTemplate' is missing or invalid") | ||
|
||
sections = base_template[0].get("sections", []) | ||
if not isinstance(sections, list): | ||
raise ValueError("'sections' should be a list") | ||
|
||
regexes = [] | ||
invalid_fields = [] | ||
# Iterate over each section | ||
for section in sections: | ||
if not isinstance(section, dict): | ||
raise ValueError("Section should be a dictionary") | ||
|
||
groups = section.get("groups", []) | ||
if not isinstance(groups, list): | ||
raise ValueError("'groups' in a section should be a list") | ||
|
||
# Iterate over each group's fields | ||
for group in groups: | ||
if not isinstance(group, dict): | ||
raise ValueError("Group should be a dictionary") | ||
|
||
fields = group.get("fields", []) | ||
if not isinstance(fields, list): | ||
raise ValueError("'fields' in a group should be a list") | ||
|
||
for field in fields: | ||
if not isinstance(field, dict): | ||
raise ValueError("Field should be a dictionary") | ||
|
||
if field.get("type") == "textInput": | ||
regex = field.get("regex") | ||
regex_error_message = field.get("regexErrorMessage") | ||
config_key = field.get("configKey", "unknown") | ||
|
||
# Check if regex and regexErrorMessage are defined | ||
if not regex or not regex_error_message: | ||
invalid_fields.append( | ||
{ | ||
"configKey": config_key, | ||
"error": "'regex' or 'regexErrorMessage' missing", | ||
} | ||
) | ||
|
||
# Check if the regex allows an empty string | ||
elif re.fullmatch(regex, ""): | ||
invalid_fields.append( | ||
{ | ||
"configKey": config_key, | ||
"error": "'regex' allows empty string", | ||
} | ||
) | ||
|
||
# Collect regex for reporting if valid | ||
else: | ||
regexes.append(regex) | ||
|
||
if invalid_fields: | ||
return {"status": "fail", "invalidFields": invalid_fields} | ||
|
||
return {"status": "pass", "regexes": regexes} # Validation passed | ||
|
||
except Exception as e: | ||
return {"status": "fail", "error": str(e)} # Return error message | ||
|
||
|
||
def validate_all_configs(base_path): | ||
invalid_directories = defaultdict(list) | ||
valid_directories = [] | ||
old_configs = [] | ||
|
||
if not os.path.exists(base_path): | ||
raise FileNotFoundError( | ||
f"The base path '{base_path}' does not exist. Please provide a valid path." | ||
) | ||
|
||
for root, dirs, files in os.walk(base_path): | ||
if "ui-config.json" in files: | ||
file_path = os.path.join(root, "ui-config.json") | ||
validation_result = validate_ui_config_file(file_path) | ||
|
||
directory_name = os.path.basename(root) | ||
|
||
# Separate passed, failed, and old configurations | ||
if validation_result["status"] == "fail": | ||
if "invalidFields" in validation_result: | ||
for field in validation_result["invalidFields"]: | ||
invalid_directories[field["error"]].append( | ||
{ | ||
"directory": directory_name, | ||
"configKey": field["configKey"], | ||
} | ||
) | ||
else: | ||
invalid_directories[validation_result["error"]].append( | ||
{"directory": directory_name} | ||
) | ||
elif validation_result["status"] == "old": | ||
old_configs.append(directory_name) | ||
else: | ||
valid_directories.append( | ||
{ | ||
"directory": directory_name, | ||
"regexes": validation_result["regexes"], | ||
} | ||
) | ||
|
||
return valid_directories, invalid_directories, old_configs | ||
|
||
|
||
if __name__ == "__main__": | ||
# Define the base path where the 'destinations' folder is located | ||
base_path = os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), "../src/configurations/destinations") | ||
) | ||
|
||
# Validate base path | ||
try: | ||
valid_dirs, invalid_dirs, old_configs = validate_all_configs(base_path) | ||
except FileNotFoundError as e: | ||
print(f"Error: {e}") | ||
exit(1) | ||
|
||
# Output results | ||
print("\nValidation Summary:\n") | ||
print(f"Valid Directories: {len(valid_dirs)}") | ||
print(f"Invalid Directories: {sum(len(v) for v in invalid_dirs.values())}") | ||
print(f"Old Configs: {len(old_configs)}\n") | ||
|
||
if valid_dirs: | ||
print("Details of Valid Directories:") | ||
for entry in valid_dirs: | ||
print( | ||
f"Destination: {entry['directory']}, Regexes: {', '.join(entry['regexes'])}" | ||
) | ||
print() | ||
|
||
if invalid_dirs: | ||
print("Details of Invalid Directories:") | ||
for error, directories in invalid_dirs.items(): | ||
print(f"Error: {error}") | ||
for entry in directories: | ||
print( | ||
f" - Destination: {entry['directory']}, ConfigKey: {entry.get('configKey', 'N/A')}" | ||
) | ||
print() | ||
|
||
if old_configs: | ||
print("Details of Old Configs:") | ||
for directory in old_configs: | ||
print(f"Destination: {directory}") | ||
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Schema validation is not enforcing the minimum length requirement
The schema correctly defines the pattern
^(.{1,100})$
requiring at least one character, but validation tests reveal that empty strings are still being accepted for bothaudienceId
andadAccountId
. This indicates a potential issue with the schema validation implementation.🔗 Analysis chain
LGTM! Schema validation has been strengthened.
The regex patterns for
audienceId
andadAccountId
have been updated to require at least one character while maintaining support for template variables and environment variables.Run the following script to verify the schema validation:
Also applies to: 415-415
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 960
Script:
Length of output: 190
Script:
Length of output: 12784
Script:
Length of output: 994