19"""Implementation of SwaggerPostProcessor which adds fields needed to generate
20Asterisk RESTful HTTP binding code.
26from swagger_model
import Stringify, SwaggerError, SwaggerPostProcessor
29 from collections
import OrderedDict
31 from odict
import OrderedDict
35 """Removes the {markers} from a path segement.
37 @param name: Swagger path segement,
with {pathVar} markers.
39 if name.startswith(
'{')
and name.endswith(
'}'):
45 """Escapes a string for the wiki.
47 @param str: String to escape
50 str = re.sub(
r'<br\s*/?>',
'\n', str)
51 return re.sub(
r'([{}\[\]])',
r'\\\1', str)
55 """Helper to take a camelCase or dash-seperated name and make it
61 if c.isupper()
and prior_lower:
65 prior_lower = c.islower()
71 """Tree representation of a Swagger API declaration.
76 @param name: Name of this path segment. May have {pathVar} markers.
77 @param parent: Parent PathSegment.
96 if not parent
or not parent.name:
102 """Walks descendants to get path, creating it if necessary.
104 @param path: List of path names.
105 @return: PageSegment corresponding to path.
114 return child.get_child(path[1:])
117 """Gets list of children.
122 """Gets count of children.
128 """A SwaggerPostProcessor which adds fields needed to generate Asterisk
129 RESTful HTTP binding code.
134 'string':
'const char *',
149 'boolean':
'ast_true',
153 json_convert_mapping = {
154 'string':
'ast_json_string_get',
155 'int':
'ast_json_integer_get',
156 'long':
'ast_json_integer_get',
157 'double':
'ast_json_real_get',
158 'boolean':
'ast_json_is_true',
167 resource_api.name = re.sub(
'\..*',
'',
168 os.path.basename(resource_api.path))
170 resource_api.name_caps = resource_api.name.upper()
171 resource_api.name_title = resource_api.name.capitalize()
172 resource_api.c_name =
snakify(resource_api.name)
174 if resource_api.api_declaration:
176 for api
in resource_api.api_declaration.apis:
177 segment = resource_api.root_path.get_child(api.path.split(
'/'))
178 for operation
in api.operations:
179 segment.operations.append(operation)
180 api.full_name = segment.full_name
184 if resource_api.root_path.num_children() != 1:
186 "Should not mix resources in one API declaration", context)
188 resource_api.root_path = list(resource_api.root_path.children())[0]
189 if resource_api.name != resource_api.root_path.name:
191 "API declaration name should match", context)
192 resource_api.root_full_name = resource_api.root_path.full_name
195 api.wiki_path =
wikify(api.path)
199 operation.c_nickname =
snakify(operation.nickname)
200 operation.c_http_method =
'AST_HTTP_' + operation.http_method
201 if not operation.summary.endswith(
"."):
202 raise SwaggerError(
"Summary should end with .", context)
203 operation.wiki_summary =
wikify(operation.summary
or "")
204 operation.wiki_notes =
wikify(operation.notes
or "")
205 for error_response
in operation.error_responses:
206 error_response.wiki_reason =
wikify(error_response.reason
or "")
207 operation.parse_body = (operation.body_parameter
or operation.has_query_parameters)
and True
210 if parameter.param_type ==
'body':
211 parameter.is_body_parameter =
True;
212 parameter.c_data_type =
'struct ast_json *'
214 parameter.is_body_parameter =
False;
217 "Invalid parameter type %s" % parameter.data_type, context)
219 parameter.c_data_type = self.
type_mapping[parameter.data_type]
224 parameter.c_name =
snakify(parameter.name)
226 if parameter.c_data_type.endswith(
'*'):
227 parameter.c_space =
''
229 parameter.c_space =
' '
230 parameter.wiki_description =
wikify(parameter.description)
231 if parameter.allowable_values:
232 parameter.wiki_allowable_values = parameter.allowable_values.to_wiki()
234 parameter.wiki_allowable_values =
None
237 model.description_dox = model.description.replace(
'\n',
'\n * ')
238 model.description_dox = re.sub(
' *\n',
'\n', model.description_dox)
239 model.wiki_description =
wikify(model.description)
245 raise SwaggerError(
"Property names cannot have dashes", context)
246 if prop.name != prop.name.lower():
247 raise SwaggerError(
"Property name should be all lowercase",
249 prop.wiki_description =
wikify(prop.description)
252 swagger_type.c_name =
snakify(swagger_type.name)
253 swagger_type.c_singular_name =
snakify(swagger_type.singular_name)
254 swagger_type.wiki_name =
wikify(swagger_type.name)
dictionary json_convert_mapping
def process_resource_api(self, resource_api, context)
def process_operation(self, operation, context)
dictionary convert_mapping
def process_type(self, swagger_type, context)
def process_property(self, prop, context)
def process_model(self, model, context)
def __init__(self, wiki_prefix)
def process_parameter(self, parameter, context)
def process_api(self, api, context)
def __init__(self, name, parent)
def get_child(self, path)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)