-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswifty_flavors.py
80 lines (62 loc) · 2.08 KB
/
swifty_flavors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import re
def typeNameFromProperty(property):
primitive = typeNameString(property.type)
if primitive != None:
return primitive
if property.type == "array":
elementName = typeNameString(property.itemType)
return "[" + elementName + "]"
def typeNameFromParameter(parameter):
typeName = ""
if parameter.type == "array":
elementName = typeNameString(parameter.itemType)
typeName = "[" + elementName + "]"
else:
typeName = typeNameString(parameter.type)
if parameter.nullable:
typeName += "?"
return typeName
def typeNameFromResponse(response):
if response == None:
return "Void"
elif hasattr(response, "type") == False:
return "Void"
typeName = ""
if response.type == "array":
elementName = typeNameString(response.itemType)
typeName = "Array<" + elementName + ">"
else:
typeName = typeNameString(response.type)
return typeName
def typeNameString(typeName):
if typeName == "integer":
return "Int"
elif typeName == "string":
return "String"
elif typeName == "boolean":
return "Bool"
elif typeName == "array":
return None
elif typeName == "file":
return "Data"
elif typeName == None:
return None
else:
m = re.search(r"#/definitions/(.*)", typeName)
return m.group(1)
def endpointTypeName(endpoint):
pathComponents = endpoint.path.replace("{", "").replace("}", "").split("/")
words = [pathComponent[0].upper() + pathComponent[1:] for pathComponent in pathComponents if pathComponent != ""]
return "_".join(words)
def makeCamelCase(snakeCaseString):
return re.sub("_(.)",lambda x:x.group(1).upper(), snakeCaseString)
def makePascalCase(snakeCaseString):
camelCase = makeCamelCase(snakeCaseString)
return camelCase[0].upper() + camelCase[1:]
def pathToPropertyInterpolation(path):
return path.replace("{", "\(").replace("}", ")")
def descriptionComment(text):
if text == "":
return ""
else:
return "// " + text