-
Notifications
You must be signed in to change notification settings - Fork 2
/
processBodyArgument.py
executable file
·134 lines (103 loc) · 2.93 KB
/
processBodyArgument.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
from bs4 import BeautifulSoup
from processValidValues import processValidValues
from processDefaults import processDefaults
from processModelName import determineModelName
from pprint import pprint
import json
import re
# Constants
DEFAULT = "Default:"
REQUIRED = "required"
NONE = -1
def processBodyArgument(soup, swggr, cursor):
# if cursor['entity'] == "board" and cursor['method'] != "get" \
# and cursor['path'] in ["/boards","/cards","/checklists","/labels","/lists","/organizations","/sessions","/webhooks"] :
# # ["/boards/{idBoard}/lists"] :
if cursor['path'] in ["xxxxx/members/{idMember}/boardStars/{idBoardStar}/idBoard"] :
debugPrint = True
else :
debugPrint = False
name = soup.code.span.text
if debugPrint : print 'Name : {}\n\n'.format(name)
required = False
if REQUIRED in soup.code.span.next_element.next_element.strip() :
required = True
swagger = swggr['paths'][cursor['path']][cursor['method']]
'''
print "##### "
print repr(soup.code.span.next_element.next_element.strip())
print "##### "
'''
parameter = {
"name" : name.strip()
, "required" : required
, "in" : "query"
, "type" : "string"
, "description" : "undefined"
, "default" : "undefined"
}
vvals = soup.find_all(text='Valid Values:')
'''
print "::::: "
print ' {}'.format(vvals)
print "::::: "
'''
for vval in vvals :
processValidValues(vval.parent.parent, parameter)
defaults = soup.find_all(text='Default:')
for default in defaults :
processDefaults(default.parent.parent, parameter)
model = determineModelName(cursor['path'])
if model not in swggr['definitions']:
swggr['definitions'][model] = {
"type" : "object",
"properties" : {
},
"xml":{
"name":cursor['entity']
}
}
swggr['definitions'][model]['properties'][parameter['name']] = {
'type' : parameter['type'],
'description' : parameter['description'],
}
if debugPrint :
print 'Swagger definitions : {}\n\n'.format(model)
pprint(swggr['definitions'][model])
# swagger["parameters"].append(parameter)
return model
# - - - - - - - - - - -
# Main routine (for testing)
def main():
from test.testdataBodyArgument import test_values
from test.testdataBodyArgument import swagger
from test.testdataBodyArgument import cursor
idx = 0
for frag in test_values :
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
soup = BeautifulSoup(frag)
# if idx == 0 :
if idx != -1 :
processBodyArgument(soup.body, swagger, cursor)
idx = idx + 1
print json.dumps(swagger)
print("\n>>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<<\n")
if __name__ == "__main__": main()
'''
"List":{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"pos":{
"type":"string",
"default":"top"
}
},
"xml":{
"name":"Pet"
}
}
'''