[svn-commits] dlee: branch dlee/ari-event-remodel2 r392389 - in /team/dlee/ari-event-remode...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 20 17:42:20 CDT 2013


Author: dlee
Date: Thu Jun 20 17:42:19 2013
New Revision: 392389

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392389
Log:
Docs working

Added:
    team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache   (with props)
Modified:
    team/dlee/ari-event-remodel2/Makefile
    team/dlee/ari-event-remodel2/rest-api-templates/api.wiki.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py
    team/dlee/ari-event-remodel2/rest-api-templates/make_ari_stubs.py
    team/dlee/ari-event-remodel2/rest-api-templates/models.wiki.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py

Modified: team/dlee/ari-event-remodel2/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/Makefile?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/Makefile (original)
+++ team/dlee/ari-event-remodel2/Makefile Thu Jun 20 17:42:19 2013
@@ -416,6 +416,7 @@
 	rm -f main/version.c
 	rm -f doc/core-en_US.xml
 	rm -f doc/full-en_US.xml
+	rm -f docs/rest-api/*.wiki
 	@$(MAKE) -C menuselect clean
 	cp -f .cleancount .lastclean
 

Modified: team/dlee/ari-event-remodel2/rest-api-templates/api.wiki.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/api.wiki.mustache?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/api.wiki.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/api.wiki.mustache Thu Jun 20 17:42:19 2013
@@ -5,7 +5,7 @@
 || Method || Path || Return Model || Summary ||
 {{#apis}}
 {{#operations}}
-| {{http_method}} | [{{path}}|#{{nickname}}] | {{response_class}} | {{summary}} |
+| {{http_method}} | [{{path}}|#{{nickname}}] | {{#response_class}}{{> type_link}}{{/response_class}} | {{summary}} |
 {{/operations}}
 {{/apis}}
 {{#apis}}

Modified: team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache Thu Jun 20 17:42:19 2013
@@ -76,15 +76,17 @@
 {{#required}}
 			has_{{name}} = 1;
 {{/required}}
+{{#type}}
 {{#is_list}}
 			prop_res = ari_validate_list(
 				ast_json_object_iter_value(iter),
-				ari_validate_{{c_type_param}});
+				ari_validate_{{c_singular_name}});
 {{/is_list}}
 {{^is_list}}
-			prop_res = ari_validate_{{snake_type}}(
+			prop_res = ari_validate_{{c_name}}(
 				ast_json_object_iter_value(iter));
 {{/is_list}}
+{{/type}}
 			if (!prop_res) {
 				ast_log(LOG_ERROR, "ARI {{id}} field {{name}} failed validation\n");
 				res = 0;

Modified: team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache Thu Jun 20 17:42:19 2013
@@ -150,7 +150,7 @@
 {{#models}}
  * {{id}}
 {{#properties}}
- * - {{name}}: {{type}}{{#required}} (required){{/required}}
+ * - {{name}}: {{type.name}}{{#required}} (required){{/required}}
 {{/properties}}
 {{/models}}
 {{/api_declaration}}

Modified: team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py Thu Jun 20 17:42:19 2013
@@ -131,12 +131,17 @@
         'double': 'atof',
     }
 
+    def __init__(self, wiki_prefix):
+        self.wiki_prefix = wiki_prefix
+
     def process_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, from include guard
+        # Now in all caps, for include guard
         resource_api.name_caps = resource_api.name.upper()
+        resource_api.name_title = resource_api.name.capitalize()
         # Construct the PathSegement tree for the API.
         if resource_api.api_declaration:
             resource_api.root_path = PathSegment('', None)
@@ -164,10 +169,6 @@
         operation.c_http_method = 'AST_HTTP_' + operation.http_method
         if not operation.summary.endswith("."):
             raise SwaggerError("Summary should end with .", context)
-        operation.snake_response_class = snakify(operation.response_class)
-        if hasattr(operation, 'response_class_param'):
-            operation.snake_response_class_param = \
-                snakify(operation.response_class_param)
 
     def process_parameter(self, parameter, context):
         if not parameter.data_type in self.type_mapping:
@@ -194,6 +195,7 @@
             raise SwaggerError("Property names cannot have dashes", context)
         if prop.name != prop.name.lower():
             raise SwaggerError("Property name should not be lowercase", context)
-        prop.snake_type = snakify(prop.type)
-        if hasattr(prop, 'type_param'):
-            prop.c_type_param = snakify(prop.type_param)
+
+    def process_type(self, swagger_type, context):
+        swagger_type.c_name = snakify(swagger_type.name)
+        swagger_type.c_singular_name = snakify(swagger_type.singular_name)

Modified: team/dlee/ari-event-remodel2/rest-api-templates/make_ari_stubs.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/make_ari_stubs.py?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/make_ari_stubs.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/make_ari_stubs.py Thu Jun 20 17:42:19 2013
@@ -40,9 +40,11 @@
     """
     return os.path.join(TOPDIR, file)
 
+WIKI_PREFIX='Asterisk 12'
+
 API_TRANSFORMS = [
     Transform(rel('api.wiki.mustache'),
-              'doc/rest-api/{{name}}.wiki'),
+              'doc/rest-api/%s {{name_title}} REST API.wiki' % WIKI_PREFIX),
     Transform(rel('res_stasis_http_resource.c.mustache'),
               'res/res_stasis_http_{{name}}.c'),
     Transform(rel('stasis_http_resource.h.mustache'),
@@ -52,7 +54,8 @@
 ]
 
 RESOURCES_TRANSFORMS = [
-    Transform(rel('models.wiki.mustache'), 'doc/rest-api/models.wiki'),
+    Transform(rel('models.wiki.mustache'),
+              'doc/rest-api/%s REST Data Models.wiki' % WIKI_PREFIX),
     Transform(rel('stasis_http.make.mustache'), 'res/stasis_http.make'),
     Transform(rel('ari_model.h.mustache'), 'res/stasis_http/ari_model.h'),
     Transform(rel('ari_model.c.mustache'), 'res/stasis_http/ari_model.c'),
@@ -70,7 +73,7 @@
     source = args[1]
     dest_dir = args[2]
     renderer = pystache.Renderer(search_dirs=[TOPDIR], missing_tags='strict')
-    processor = AsteriskProcessor()
+    processor = AsteriskProcessor(wiki_prefix=WIKI_PREFIX)
 
     # Build the models
     base_dir = os.path.dirname(source)

Modified: team/dlee/ari-event-remodel2/rest-api-templates/models.wiki.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/models.wiki.mustache?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/models.wiki.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/models.wiki.mustache Thu Jun 20 17:42:19 2013
@@ -14,7 +14,7 @@
 {{{model_json}}}
 {code}
 {{#properties}}
-* {{name}}: {{#is_primitive_type}}{{type}}{{/is_primitive_type}}{{^is_primitive_type}}[{{type}}|#{{type}}]{{/is_primitive_type}}{{^required}} _(optional)_{{/required}}{{#description}} - {{{description}}}{{/description}}
+* {{name}}: {{#type}}{{> type_link}}{{/type}}{{^required}} _(optional)_{{/required}}{{#description}} - {{{description}}}{{/description}}
 {{/properties}}
 
 {{/models}}

Modified: team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache Thu Jun 20 17:42:19 2013
@@ -86,14 +86,16 @@
 		break;
 	default:
 		if (200 <= code && code <= 299) {
-{{#is_response_list}}
+{{#response_class}}
+{{#is_list}}
 			is_valid = ari_validate_list(response->message,
-				ari_validate_{{snake_response_class_param}});
-{{/is_response_list}}
-{{^is_response_list}}
-			is_valid = ari_validate_{{snake_response_class}}(
+				ari_validate_{{c_singular_name}});
+{{/is_list}}
+{{^is_list}}
+			is_valid = ari_validate_{{c_name}}(
 				response->message);
-{{/is_response_list}}
+{{/is_list}}
+{{/response_class}}
 		} else {
 			ast_log(LOG_ERROR, "Invalid error response %d for {{path}}\n", code);
 			is_valid = 0;
@@ -122,7 +124,7 @@
 {{/has_path_parameters}}
 {{> param_parsing}}
 	session = ari_websocket_session_create(ws_session,
-		ari_validate_{{snake_response_class}});
+		ari_validate_{{response_class.c_name}});
 	if (!session) {
 		ast_log(LOG_ERROR, "Failed to create ARI session\n");
 		return;

Modified: team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py?view=diff&rev=392389&r1=392388&r2=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py Thu Jun 20 17:42:19 2013
@@ -41,6 +41,7 @@
 SWAGGER_VERSIONS=["1.1", "1.2"]
 
 SWAGGER_PRIMITIVES=[
+    'void',
     'string',
     'boolean',
     'number',
@@ -163,6 +164,22 @@
         """Post process a Property object.
 
         @param property: Property object.
+        @param context: Current context in the API.
+        """
+        pass
+
+    def process_type(self, swagger_type, context):
+        """Post process a SwaggerType object.
+
+        @param swagger_type: ResourceListing object.
+        @param context: Current context in the API.
+        """
+        pass
+
+    def process_resource_listing(self, resource_listing, context):
+        """Post process the overall ResourceListing object.
+
+        @param resource_listing: ResourceListing object.
         @param context: Current context in the API.
         """
         pass
@@ -270,6 +287,38 @@
         self.reason = err_json.get('reason')
         return self
 
+class SwaggerType(Stringify):
+    """Model of a data type.
+    """
+
+    def __init__(self):
+        self.name = None
+        self.is_discriminator = None
+        self.is_list = None
+        self.singular_name = None
+        self.is_primitive = None
+
+    def load(self, type_name, processor, context):
+        # Some common errors
+        if type_name == 'integer':
+            raise SwaggerError("The type for integer should be 'int'", context)
+
+        self.name = type_name
+        self.is_discriminator = self.name == 'DISCRIMINATOR'
+        if self.is_discriminator:
+            self.name = 'string'
+            if context.is_version("1.1"):
+                raise SwaggerError(
+                    "DISCRIMINATOR support added in Swagger 1.2", context)
+        type_param = get_list_parameter_type(self.name)
+        self.is_list = type_param is not None
+        if self.is_list:
+            self.singular_name = type_param
+        else:
+            self.singular_name = self.name
+        self.is_primitive = self.singular_name in SWAGGER_PRIMITIVES
+        processor.process_type(self, context)
+        return self
 
 class Operation(Stringify):
     """Model of an operation on an API
@@ -293,11 +342,9 @@
         validate_required_fields(op_json, self.required_fields, context)
         self.http_method = op_json.get('httpMethod')
         self.nickname = op_json.get('nickname')
-        self.response_class = op_json.get('responseClass')
-        response_class_param = get_list_parameter_type(self.response_class)
-        self.is_response_list = response_class_param is not None
-        if self.is_response_list:
-            self.response_class_param = response_class_param
+        response_class = op_json.get('responseClass')
+        self.response_class = response_class and SwaggerType().load(
+            response_class, processor, context)
 
         # Specifying WebSocket URL's is our own extension
         self.is_websocket = op_json.get('upgrade') == 'websocket'
@@ -387,29 +434,15 @@
         validate_required_fields(property_json, self.required_fields, context)
         # Bit of a hack, but properties do not self-identify
         context = context.next_stack({'name': self.name}, 'name')
-        self.type = property_json.get('type')
         self.description = property_json.get('description') or ''
         self.required = property_json.get('required') or False
-        type_param = get_list_parameter_type(self.type)
-        self.is_list = type_param is not None
-        if self.is_list:
-            self.type_param = type_param
-            self.is_primitive_type = type_param in SWAGGER_PRIMITIVES
-        else:
-            self.is_primitive_type = self.type in SWAGGER_PRIMITIVES
-
-        self.is_discriminator = self.type == 'DISCRIMINATOR'
-        if self.is_discriminator:
+
+        type = property_json.get('type')
+        self.type = type and SwaggerType().load(type, processor, context)
+        if self.type.is_discriminator:
             # Discriminators are always required
-            self.type = "string"
             self.required = True
-            if context.is_version("1.1"):
-                raise SwaggerError(
-                    "DISCRIMINATOR support added in Swagger 1.2", context)
-
-        # Some common errors
-        if self.type == 'integer':
-            raise SwaggerError("The type for integer should be 'int'", context)
+
         processor.process_property(self, context)
         return self
 
@@ -449,7 +482,7 @@
             Property(k).load(j, processor, context) for (k, j) in props]
         self.__properties = sorted(self.__properties, key=lambda p: p.name)
 
-        discriminators = [p for p in self.__properties if p.is_discriminator]
+        discriminators = [p for p in self.__properties if p.type.is_discriminator]
         if len(discriminators) > 1:
             raise SwaggerError("Model may have at most one discriminator",
                                context)
@@ -651,6 +684,7 @@
         apis_json = resources_json['apis']
         self.apis = [
             ResourceApi().load(j, processor, context) for j in apis_json]
+        processor.process_resource_listing(self, context)
         return self
 
 

Added: team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache?view=auto&rev=392389
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache (added)
+++ team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache Thu Jun 20 17:42:19 2013
@@ -1,0 +1,21 @@
+{{!
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+}}
+{{!
+ * Snippet to emit a linked type for the wiki
+}}
+{{#is_primitive}}{{name}}{{/is_primitive}}{{^is_primitive}}[{{name}}|{{wiki_prefix}} REST Data Models#{{singular_name}}]{{/is_primitive}}

Propchange: team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dlee/ari-event-remodel2/rest-api-templates/type_link.mustache
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list