From 7d0d1a1efb1d484cce28137f1abc1a6ece61d7e9 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Thu, 7 Nov 2013 21:10:31 +0000 Subject: ari: User better nicknames for ARI operations While working on building client libraries from the Swagger API, I noticed a problem with the nicknames. channel.deleteChannel() channel.answerChannel() channel.muteChannel() Etc. We put the object name in the nickname (since we were generating C code), but it makes OO generators redundant. This patch makes the nicknames more OO friendly. This resulted in a lot of name changing within the res_ari_*.so modules, but not much else. There were a couple of other fixed I made in the process. * When reversible operations (POST /hold, POST /unhold) were made more RESTful (POST /hold, DELETE /unhold), the path for the second operation was left in the API declaration. This worked, but really the two operations should have been on the same API. * The POST /unmute operation had still not been REST-ified. Review: https://reviewboard.asterisk.org/r/2940/ ........ Merged revisions 402528 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402529 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- rest-api-templates/ari_resource.c.mustache | 12 ++++++------ rest-api-templates/ari_resource.h.mustache | 8 ++++---- rest-api-templates/asterisk_processor.py | 3 ++- rest-api-templates/res_ari_resource.c.mustache | 14 +++++++------- rest-api-templates/rest_handler.mustache | 2 +- rest-api-templates/swagger_model.py | 5 +++++ 6 files changed, 25 insertions(+), 19 deletions(-) (limited to 'rest-api-templates') diff --git a/rest-api-templates/ari_resource.c.mustache b/rest-api-templates/ari_resource.c.mustache index cdbd283e4..5015d347e 100644 --- a/rest-api-templates/ari_resource.c.mustache +++ b/rest-api-templates/ari_resource.c.mustache @@ -33,19 +33,19 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") {{#apis}} {{#operations}} {{#is_req}} -void ast_ari_{{c_nickname}}(struct ast_variable *headers, - struct ast_{{c_nickname}}_args *args, +void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_variable *headers, + struct ast_ari_{{c_name}}_{{c_nickname}}_args *args, struct ast_ari_response *response) { - ast_log(LOG_ERROR, "TODO: ast_ari_{{c_nickname}}\n"); + ast_log(LOG_ERROR, "TODO: ast_ari_{{c_name}}_{{c_nickname}}\n"); } {{/is_req}} {{#is_websocket}} -void ast_ari_websocket_{{c_nickname}}(struct ast_ari_websocket_session *session, +void ast_ari_websocket_{{c_name}}_{{c_nickname}}(struct ast_ari_websocket_session *session, struct ast_variable *headers, - struct ast_{{c_nickname}}_args *args) + struct ast_ari_{{c_name}}_{{c_nickname}}_args *args) { - ast_log(LOG_ERROR, "TODO: ast_ari_websocket_{{c_nickname}}\n"); + ast_log(LOG_ERROR, "TODO: ast_ari_websocket_{{c_name}}_{{c_nickname}}\n"); } {{/is_websocket}} {{/operations}} diff --git a/rest-api-templates/ari_resource.h.mustache b/rest-api-templates/ari_resource.h.mustache index 8b4b0acec..e389eb5d7 100644 --- a/rest-api-templates/ari_resource.h.mustache +++ b/rest-api-templates/ari_resource.h.mustache @@ -40,8 +40,8 @@ {{#apis}} {{#operations}} -/*! \brief Argument struct for ast_ari_{{c_nickname}}() */ -struct ast_{{c_nickname}}_args { +/*! \brief Argument struct for ast_ari_{{c_name}}_{{c_nickname}}() */ +struct ast_ari_{{c_name}}_{{c_nickname}}_args { {{#parameters}} {{#description}} {{/description}} @@ -73,7 +73,7 @@ struct ast_{{c_nickname}}_args { * \param args Swagger parameters * \param[out] response HTTP response */ -void ast_ari_{{c_nickname}}(struct ast_variable *headers, struct ast_{{c_nickname}}_args *args, struct ast_ari_response *response); +void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_variable *headers, struct ast_ari_{{c_name}}_{{c_nickname}}_args *args, struct ast_ari_response *response); {{/is_req}} {{#is_websocket}} /*! @@ -87,7 +87,7 @@ void ast_ari_{{c_nickname}}(struct ast_variable *headers, struct ast_{{c_nicknam * \param headers HTTP headers. * \param args Swagger parameters. */ -void ast_ari_websocket_{{c_nickname}}(struct ast_ari_websocket_session *session, struct ast_variable *headers, struct ast_{{c_nickname}}_args *args); +void ast_ari_websocket_{{c_name}}_{{c_nickname}}(struct ast_ari_websocket_session *session, struct ast_variable *headers, struct ast_ari_{{c_name}}_{{c_nickname}}_args *args); {{/is_websocket}} {{/operations}} {{/apis}} diff --git a/rest-api-templates/asterisk_processor.py b/rest-api-templates/asterisk_processor.py index e7a0b5fd1..18044f57e 100644 --- a/rest-api-templates/asterisk_processor.py +++ b/rest-api-templates/asterisk_processor.py @@ -157,6 +157,7 @@ class AsteriskProcessor(SwaggerPostProcessor): # 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) @@ -182,7 +183,7 @@ class AsteriskProcessor(SwaggerPostProcessor): api.wiki_path = wikify(api.path) def process_operation(self, operation, context): - # Nicknames are camelcase, Asterisk coding is snake case + # 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("."): diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache index 8e043e682..06b493cc4 100644 --- a/rest-api-templates/res_ari_resource.c.mustache +++ b/rest-api-templates/res_ari_resource.c.mustache @@ -73,11 +73,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") * \param headers HTTP headers. * \param[out] response Response to the HTTP request. */ -static void ast_ari_{{c_nickname}}_cb( +static void ast_ari_{{c_name}}_{{c_nickname}}_cb( struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_ari_response *response) { - struct ast_{{c_nickname}}_args args = {}; + struct ast_ari_{{c_name}}_{{c_nickname}}_args args = {}; {{#has_parameters}} struct ast_variable *i; {{/has_parameters}} @@ -87,7 +87,7 @@ static void ast_ari_{{c_nickname}}_cb( #endif /* AST_DEVMODE */ {{> param_parsing}} - ast_ari_{{c_nickname}}(headers, &args, response); + ast_ari_{{c_name}}_{{c_nickname}}(headers, &args, response); #if defined(AST_DEVMODE) code = response->response_code; @@ -133,10 +133,10 @@ fin: __attribute__((unused)) } {{/is_req}} {{#is_websocket}} -static void ast_ari_{{c_nickname}}_ws_cb(struct ast_websocket *ws_session, +static void ast_ari_{{c_name}}_{{c_nickname}}_ws_cb(struct ast_websocket *ws_session, struct ast_variable *get_params, struct ast_variable *headers) { - struct ast_{{c_nickname}}_args args = {}; + struct ast_ari_{{c_name}}_{{c_nickname}}_args args = {}; {{#has_parameters}} RAII_VAR(struct ast_ari_response *, response, NULL, ast_free); struct ast_variable *i; @@ -171,7 +171,7 @@ static void ast_ari_{{c_nickname}}_ws_cb(struct ast_websocket *ws_session, {{> param_parsing}} - ast_ari_websocket_{{c_nickname}}(session, headers, &args); + ast_ari_websocket_{{c_name}}_{{c_nickname}}(session, headers, &args); fin: __attribute__((unused)) if (response && response->response_code != 0) { @@ -216,7 +216,7 @@ static int load_module(void) {{#operations}} {{#is_websocket}} res |= ast_websocket_server_add_protocol({{full_name}}.ws_server, - "{{websocket_protocol}}", ast_ari_{{c_nickname}}_ws_cb); + "{{websocket_protocol}}", ast_ari_{{c_name}}_{{c_nickname}}_ws_cb); {{/is_websocket}} {{/operations}} {{/apis}} diff --git a/rest-api-templates/rest_handler.mustache b/rest-api-templates/rest_handler.mustache index ceff6a72d..baa1aa65d 100644 --- a/rest-api-templates/rest_handler.mustache +++ b/rest-api-templates/rest_handler.mustache @@ -31,7 +31,7 @@ static struct stasis_rest_handlers {{full_name}} = { .callbacks = { {{#operations}} {{#is_req}} - [{{c_http_method}}] = ast_ari_{{c_nickname}}_cb, + [{{c_http_method}}] = ast_ari_{{c_name}}_{{c_nickname}}_cb, {{/is_req}} {{/operations}} }, diff --git a/rest-api-templates/swagger_model.py b/rest-api-templates/swagger_model.py index be98c4a3c..144f22bdb 100644 --- a/rest-api-templates/swagger_model.py +++ b/rest-api-templates/swagger_model.py @@ -631,6 +631,11 @@ class ApiDeclaration(Stringify): api_json = api_decl_json.get('apis') or [] self.apis = [ Api().load(j, processor, context) for j in api_json] + paths = set() + for api in self.apis: + if api.path in paths: + raise SwaggerError("API with duplicated path: %s" % api.path, context) + paths.add(api.path) self.has_websocket = filter(lambda api: api.has_websocket, self.apis) == [] models = api_decl_json.get('models').items() or [] -- cgit v1.2.3