test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Code maintenance (2) #333

Open HolQue opened 4 weeks ago

HolQue commented 4 weeks ago

What is the current state of the naming convention check for key names?

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/206

While searching for answers I found:

def __keyNameValidation(self, sInput):
    """
Validates the key names of a JSON object to ensure they adhere to certain rules and conventions.
...
    """
    if CNameMangling.STRINGCONVERT.value in sInput:
        sInput = sInput.replace(CNameMangling.STRINGCONVERT.value, '')
        errorMsg = f"A substitution in key names is not allowed! Please update the key name {sInput}"
        self.__reset()
        raise Exception(errorMsg)

The interface description tells that this method validates the key name. I assume now that 'sInput' is the key name. If this is true, the parameter should be renamed to 'sKeyName'. This would ease the readability.

'sInput' is checked against one single string only. Is this really the only thing that has to be done to realize a naming convention check? How shall this work?

Under certain circumstances the string 'CNameMangling.STRINGCONVERT.value' is added. Out of the existence of this string, in the code above you conclude, that a substitution in key names is not allowed. In other areas of the JsonPreprocessor code you make it an issue, if the string is not part of any input (the complete opposite). The conclusion in this case is that the expression cannot be evaluated.

These are much different things, but depend on the same indicator string. This is really hard to understand and makes it very difficult, to maintain, modify and extend the code.

Please try to find better solutions to make the code more plausible.

namsonx commented 4 weeks ago

Hello Holger,

Thank you for your comment! I will update the input parameter in this case to sKeyName Initially, we want to check the naming convention of parameter names for JPP, but then we decided that the key naming rules for JPP will align with those of JSON https://github.com/test-fullautomation/python-jsonpreprocessor/issues/206#issuecomment-2003567831. Then I use method __keyNameValidation() to check for a substitution in key name which is mentioned in https://github.com/test-fullautomation/python-jsonpreprocessor/issues/270

The key names validation of ROBFW-AIO will be handled in TestsuiteManagement package.

Thank you, Son