From dd1ed81f6c1b43f2577c80286ae3dbaa2d37e41b Mon Sep 17 00:00:00 2001 From: Marcus Kida <mki@sinnerschrader-mobile.com> Date: Fri, 14 Mar 2014 12:00:31 +0100 Subject: [PATCH 1/4] Replaces dot, dash, comma in json-key by underscore for generating safe object property names --- ObjectiveCCodeGenerator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ObjectiveCCodeGenerator.py b/ObjectiveCCodeGenerator.py index e28d2ca..1f83d81 100755 --- a/ObjectiveCCodeGenerator.py +++ b/ObjectiveCCodeGenerator.py @@ -22,7 +22,7 @@ THE SOFTWARE. ''' -import datetime, time, os +import datetime, time, os, re class ObjectiveCCodeGenerator : @@ -51,7 +51,7 @@ def getSourceDescriptionString(self, name) : return mDescriptionString def makeVarName(self,schemeObj) : - returnName = schemeObj.type_name + returnName = re.sub('[,.-]', '_', schemeObj.type_name) if str(schemeObj.type_name) == "id" or str(schemeObj.type_name) == "description" : titleName = schemeObj.type_name.upper() titleName = titleName[:1] + schemeObj.type_name[1:] From 907a400817bd526d71e3c0c5078f400764542e91 Mon Sep 17 00:00:00 2001 From: Marcus Kida <mki@sinnerschrader-mobile.com> Date: Fri, 14 Mar 2014 13:55:09 +0100 Subject: [PATCH 2/4] Adds possibility to use ISO 8601 formatted date for base-type properties --- ObjectiveCCodeGenerator.py | 2 ++ doc/MetaJSONProtocol.md | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ObjectiveCCodeGenerator.py b/ObjectiveCCodeGenerator.py index 1f83d81..2449410 100755 --- a/ObjectiveCCodeGenerator.py +++ b/ObjectiveCCodeGenerator.py @@ -701,6 +701,8 @@ def getNaturalTypeGetterFromDictionaryCode(self, schemeObj, className, varName, dateObjSubType = schemeObj.getSubType() if len(dateObjSubType) and dateObjSubType[0] == str("ms") : resultString += firstIndent + className + varName + " = [" + self.projectPrefix + "APIParser dateWithMilliSecondsTimeIntervalFromResponseDictionary:" + dicName + " forKey:@\"" + keyName + "\" acceptNil:" + elif len(dateObjSubType) and dateObjSubType[0] == str("iso8601") : + resultString += firstIndent + className + varName + " = [" + self.projectPrefix + "APIParser dateFromResponseDictionary:" + dicName + " forKey:@\"" + keyName + "\" acceptNil:" else : resultString += firstIndent + className + varName + " = [" + self.projectPrefix + "APIParser dateWithTimeIntervalFromResponseDictionary:" + dicName + " forKey:@\"" + keyName + "\" acceptNil:" elif schemeBaseType == "data" : diff --git a/doc/MetaJSONProtocol.md b/doc/MetaJSONProtocol.md index a7a75e9..44c5e47 100644 --- a/doc/MetaJSONProtocol.md +++ b/doc/MetaJSONProtocol.md @@ -60,11 +60,19 @@ You can also use just one of those ("minValue" or "maxValue"). "description" : string "minValue" : UTC time interval since 1970 "maxValue" : UTC time interval since 1970 -} +}, +{ + "name" : "myISO8601Date", + "base-type" : "date", + "subType" : "iso8601", + "description" : string + "minValue" : UTC time interval since 1970 + "maxValue" : UTC time interval since 1970 +}, ``` * The value of myDate should be always UTC time interval since 1970. -* "subType" is optional, to specify wheather it's millisecond based timestamp or second based timestamp. +* "subType" is optional, to specify wheather it's millisecond based timestamp, a second based timestamp or an ISO 8601 timestamp. * If "subType" is specified as "ms", "minValue" and "maxValue" should be used like "1382455623.098" * "minValue" and "maxValue" are optional, to validate this type. * "maxValue" should be always same or later than "minValue". From 9d46521e28287d888d8db57ce70fe10b8641deaf Mon Sep 17 00:00:00 2001 From: Sanggeon Park <gunnih@Gunnihs-MacBook-Pro-2.local> Date: Wed, 5 Aug 2015 12:01:18 +0200 Subject: [PATCH 3/4] add option to specify Utility output path. --- ObjectiveCCodeGenerator.py | 12 ++++++------ readJSON.py | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ObjectiveCCodeGenerator.py b/ObjectiveCCodeGenerator.py index 2449410..ae52304 100755 --- a/ObjectiveCCodeGenerator.py +++ b/ObjectiveCCodeGenerator.py @@ -1017,14 +1017,14 @@ def writeAPIParser(self) : finally : implDstFile.close() - def writeTemplates(self) : + def writeTemplates(self, templatePath) : - if self.dirPath.endswith("/") : - self.dirPath = self.dirPath[:-1] - baseDirPath = self.dirPath - self.dirPath = baseDirPath + "/Utilities/NSString" + if templatePath.endswith("/") : + templatePath = templatePath[:-1] + + self.dirPath = templatePath + "/NSString" self.writeNSStringCategory() - self.dirPath = baseDirPath + "/Utilities/APIParser" + self.dirPath = templatePath + "/APIParser" self.writeAPIParser() diff --git a/readJSON.py b/readJSON.py index eba084b..4b21ee0 100755 --- a/readJSON.py +++ b/readJSON.py @@ -39,6 +39,7 @@ projectPrefix = '' target = 'iOS' dirPathToSaveCodes = './src' +dirPathToSaveUtility = '' objectSuffix = "JSONObject" usageString = '\nreadJSON.py [ -p | -t | -o | -s ] [-i]\n' @@ -49,11 +50,12 @@ usageString += ' -t, --target= target platform iOS or Android (default: iOS)\n' usageString += ' -i, --input= meta-JSON file to read\n' usageString += ' -o, --output= ouput path of generated source codes\n' +usageString += ' -u, --utility= ouput path of generated Utility codes. Use "-u false" for no utility\n' if __name__ == "__main__": argv = sys.argv[1:] try: - opts, args = getopt.getopt(argv,"ho:p:s:t:i:",["prefix=","suffix=","target=","input=","output="]) + opts, args = getopt.getopt(argv,"ho:p:s:t:i:u:",["prefix=","suffix=","target=","input=","output=","utility="]) except getopt.GetoptError: print usageString sys.exit(2) @@ -74,7 +76,20 @@ objectSuffix = arg if objectSuffix == "false": objectSuffix = "" + elif opt in ("-u", "--utility"): + dirPathToSaveUtility = arg + + + if dirPathToSaveUtility == "": + tmpSourcePath = dirPathToSaveCodes + if tmpSourcePath.endswith("/") : + tmpSourcePath = tmpSourcePath[:-1] + dirPathToSaveUtility = tmpSourcePath + "/Utility" + + elif dirPathToSaveUtility == "false": + dirPathToSaveUtility = ""; + addFiles = False for arg in argv : if arg.endswith(inputfile) : @@ -142,7 +157,8 @@ def openFileAndParseJSON(filePath): templateCodeGen.templatePath = templatePath templateCodeGen.projectPrefix = projectPrefix templateCodeGen.dirPath = dirPathToSaveCodes - templateCodeGen.writeTemplates() + if len(dirPathToSaveUtility) != 0 : + templateCodeGen.writeTemplates(dirPathToSaveUtility) JSONScheme.projectPrefix = projectPrefix JSONScheme.objectSuffix = objectSuffix From e5c3b36e8559f556c24961e93687cf5080147c42 Mon Sep 17 00:00:00 2001 From: Sanggeon Park <gunnih@Gunnihs-MacBook-Pro-3.local> Date: Thu, 20 Aug 2015 16:30:23 +0200 Subject: [PATCH 4/4] update description --- readJSON.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readJSON.py b/readJSON.py index 4b21ee0..5448e47 100755 --- a/readJSON.py +++ b/readJSON.py @@ -42,15 +42,15 @@ dirPathToSaveUtility = '' objectSuffix = "JSONObject" -usageString = '\nreadJSON.py [ -p | -t | -o | -s ] [-i]\n' +usageString = '\nreadJSON.py [ -p | -t | -o | -s | -u ] [-i]\n' usageString += 'Options:\n' usageString += ' -h, --help shows help\n' usageString += ' -p, --prefix= project prefix (default: S2M)\n' usageString += ' -s, --suffix= classname suffix (default: JSONObject). Use "-s false" for no suffix\n' usageString += ' -t, --target= target platform iOS or Android (default: iOS)\n' -usageString += ' -i, --input= meta-JSON file to read\n' usageString += ' -o, --output= ouput path of generated source codes\n' usageString += ' -u, --utility= ouput path of generated Utility codes. Use "-u false" for no utility\n' +usageString += ' -i, --input= meta-JSON file to read\n' if __name__ == "__main__": argv = sys.argv[1:]