43 |
43 |
parameters=None,
|
44 |
44 |
cache_duration=None,
|
45 |
45 |
post=None,
|
46 |
|
show=True):
|
|
46 |
show=True,
|
|
47 |
show_undocumented_params=True):
|
47 |
48 |
self.perm = perm
|
48 |
49 |
self.methods = methods
|
49 |
50 |
self.serializer_type = serializer_type
|
... | ... | |
61 |
62 |
'patch': long_description_patch or long_description,
|
62 |
63 |
}
|
63 |
64 |
self.example_pattern = example_pattern
|
64 |
|
self.parameters = parameters
|
|
65 |
self.parameters = parameters or {}
|
65 |
66 |
self.cache_duration = cache_duration
|
66 |
67 |
self.post = post
|
67 |
68 |
if post:
|
... | ... | |
71 |
72 |
if post.get('long_description'):
|
72 |
73 |
self.long_descriptions['post'] = post.get('long_description')
|
73 |
74 |
self.show = show
|
|
75 |
self.show_undocumented_params = show_undocumented_params
|
74 |
76 |
|
75 |
77 |
def __call__(self, func):
|
76 |
78 |
func.endpoint_info = self
|
... | ... | |
160 |
162 |
return 'float'
|
161 |
163 |
|
162 |
164 |
params = []
|
163 |
|
defaults = dict(zip(
|
164 |
|
reversed(inspect.getargspec(self.func).args),
|
165 |
|
reversed(inspect.getargspec(self.func).defaults or [])))
|
166 |
|
for param in inspect.getargspec(self.func).args[2:]:
|
167 |
|
if param == 'post_data':
|
168 |
|
continue
|
|
165 |
spec = inspect.getargspec(self.func)
|
|
166 |
# order parameters according to func signature
|
|
167 |
available_params = {x: self.parameters[x] for x in spec.args if x in self.parameters}
|
|
168 |
defaults = dict(zip(reversed(spec.args), reversed(spec.defaults or [])))
|
|
169 |
if self.show_undocumented_params:
|
|
170 |
for arg in spec.args[2:]:
|
|
171 |
if arg in available_params or arg == 'post_data':
|
|
172 |
continue
|
|
173 |
available_params[arg] = {}
|
|
174 |
for param, info in available_params.items():
|
169 |
175 |
param_info = {'name': param}
|
170 |
|
if self.parameters and param in self.parameters:
|
171 |
|
info = self.parameters[param]
|
172 |
|
if info.get('description'):
|
173 |
|
param_info['description'] = info['description']
|
174 |
|
if 'type' in info:
|
175 |
|
typ = info['type']
|
176 |
|
if typ == 'int':
|
177 |
|
param_info['type'] = 'integer'
|
178 |
|
elif typ == 'bool':
|
179 |
|
param_info['type'] = 'boolean'
|
180 |
|
else:
|
181 |
|
param_info['type'] = typ
|
182 |
|
elif 'example_value' in info:
|
183 |
|
typ = type_to_str(info['example_value'])
|
184 |
|
if typ:
|
185 |
|
param_info['type'] = typ
|
|
176 |
if info.get('description'):
|
|
177 |
param_info['description'] = info['description']
|
|
178 |
typ = None
|
|
179 |
if 'type' in info:
|
|
180 |
typ = info['type']
|
|
181 |
if typ == 'int':
|
|
182 |
typ = 'integer'
|
|
183 |
elif typ == 'bool':
|
|
184 |
typ = 'boolean'
|
|
185 |
elif 'example_value' in info:
|
|
186 |
typ = type_to_str(info['example_value'])
|
186 |
187 |
if param in defaults:
|
187 |
188 |
param_info['optional'] = True
|
188 |
189 |
param_info['default_value'] = defaults[param]
|
189 |
|
if 'type' not in param_info:
|
|
190 |
if not typ:
|
190 |
191 |
typ = type_to_str(defaults[param])
|
191 |
|
if typ:
|
192 |
|
param_info['type'] = typ
|
|
192 |
if typ:
|
|
193 |
param_info['type'] = typ
|
193 |
194 |
params.append(param_info)
|
194 |
195 |
return params
|
195 |
|
-
|