def process_property(self, prop, context): if "-" in prop.name: raise SwaggerError("Property names cannot have dashes", context) if prop.name != prop.name.lower(): raise SwaggerError("Property name should be all lowercase", context) prop.wiki_description = wikify(prop.description)
def process_resource_api(self, resource_api, context): resource_api.wiki_prefix = self.wiki_prefix # Derive a resource name from the API declaration's filename resource_api.name = re.sub('\..*', '', os.path.basename(resource_api.path)) # Now in all caps, for include guard resource_api.name_caps = resource_api.name.upper() resource_api.name_title = resource_api.name.capitalize() resource_api.c_name = snakify(resource_api.name) # Construct the PathSegement tree for the API. if resource_api.api_declaration: resource_api.root_path = PathSegment('', None) for api in resource_api.api_declaration.apis: segment = resource_api.root_path.get_child(api.path.split('/')) for operation in api.operations: segment.operations.append(operation) api.full_name = segment.full_name # Since every API path should start with /[resource], root should # have exactly one child. if resource_api.root_path.num_children() != 1: raise SwaggerError( "Should not mix resources in one API declaration", context) # root_path isn't needed any more resource_api.root_path = list(resource_api.root_path.children())[0] if resource_api.name != resource_api.root_path.name: raise SwaggerError("API declaration name should match", context) resource_api.root_full_name = resource_api.root_path.full_name
def process_parameter(self, parameter, context): if parameter.param_type == 'body': parameter.is_body_parameter = True parameter.c_data_type = 'struct ast_json *' else: parameter.is_body_parameter = False if not parameter.data_type in self.type_mapping: raise SwaggerError( "Invalid parameter type %s" % parameter.data_type, context) # Type conversions parameter.c_data_type = self.type_mapping[parameter.data_type] parameter.c_convert = self.convert_mapping[parameter.data_type] parameter.json_convert = self.json_convert_mapping[ parameter.data_type] # Parameter names are camelcase, Asterisk convention is snake case parameter.c_name = snakify(parameter.name) # You shouldn't put a space between 'char *' and the variable if parameter.c_data_type.endswith('*'): parameter.c_space = '' else: parameter.c_space = ' ' parameter.wiki_description = wikify(parameter.description) if parameter.allowable_values: parameter.wiki_allowable_values = parameter.allowable_values.to_wiki( ) else: parameter.wiki_allowable_values = None
def process_operation(self, operation, context): # Nicknames are camelCase, Asterisk coding is snake case operation.c_nickname = snakify(operation.nickname) operation.c_http_method = 'AST_HTTP_' + operation.http_method if not operation.summary.endswith("."): raise SwaggerError("Summary should end with .", context) operation.wiki_summary = wikify(operation.summary or "") operation.wiki_notes = wikify(operation.notes or "") for error_response in operation.error_responses: error_response.wiki_reason = wikify(error_response.reason or "") operation.parse_body = (operation.body_parameter or operation.has_query_parameters) and True