[asterisk-commits] dlee: branch dlee/stasis-http r383101 - in /team/dlee/stasis-http: cog/ rest-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 14 13:43:27 CDT 2013


Author: dlee
Date: Thu Mar 14 13:43:23 2013
New Revision: 383101

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383101
Log:
Stub out response classes

Modified:
    team/dlee/stasis-http/cog/stasis_cog.py
    team/dlee/stasis-http/rest-api/asterisk.json
    team/dlee/stasis-http/rest-api/bridges.json
    team/dlee/stasis-http/rest-api/channels.json
    team/dlee/stasis-http/rest-api/endpoints.json
    team/dlee/stasis-http/rest-api/recordings.json

Modified: team/dlee/stasis-http/cog/stasis_cog.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/cog/stasis_cog.py?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/cog/stasis_cog.py (original)
+++ team/dlee/stasis-http/cog/stasis_cog.py Thu Mar 14 13:43:23 2013
@@ -275,6 +275,7 @@
         # Otherwise, search order won't match the .json files
         self.children = OrderedDict()
         self.operations = OrderedDict()
+        self.models = OrderedDict()
         self.includes = []
         self.author = None
         self.copyright = None
@@ -343,6 +344,7 @@
                                             operation['nickname'])
                 op.summary = operation.get('summary')
                 op.notes = operation.get('notes')
+                op.responseClass = operation['responseClass']
                 for param in operation.get('parameters') or []:
                     op.add_parameter(name=param['name'],
                                      description=param['description'],
@@ -352,6 +354,42 @@
                                      dataType=param.get('dataType'),
                                      defaultValue=param.get('defaultValue'))
 
+        for model_name in api_declaration['models'].keys():
+            model = api_declaration['models'][model_name]
+            if not 'id' in model:
+                raise ValueError("Model %s: missing id field" % model_name)
+            if model['id'] != model_name:
+                raise ValueError("Model name and id do not match (%s != %s)" %
+                                 (model['id'], model_name))
+            if not 'properties' in model:
+                raise ValueError("Model %s: missing properties field" % model_name)
+            for prop_name in model['properties'].keys():
+                prop = model['properties'][prop_name]
+                if prop.get('type') is None:
+                    raise ValueError("Property %s.%s missing type" %
+                                     (model_name, prop_name))
+                #if prop.get('description') is None:
+                #    raise ValueError("Property %s.%s missing description" %
+                #                     (model_name, prop_name))
+            self.add_model(model_name)
+
+        self.validate_response_classes(self.models)
+
+    def validate_response_classes(self, models):
+        list_re = re.compile("List\[([^]]*)\]")
+        for op in self.operations.itervalues():
+            model = op.responseClass
+            if model == 'void':
+                continue
+            is_list = list_re.match(model)
+            if is_list:
+                model = is_list.group(1)
+            if model not in models:
+                raise ValueError("Operation %s: undefined model %s" %
+                                 (op.nickname, model))
+        for child in self.children.itervalues():
+            child.validate_response_classes(models)
+
     def get_name(self):
         """Returns the fully qualified name of this Resource.
         """
@@ -379,9 +417,18 @@
     def add_operation(self, http_method, nickname):
         """Add an operation to this resource.
         """
+        if http_method in self.operations:
+            raise ValueError("Operation defined more than once (%s)" %
+                             nickname)
         op = Operation(http_method, nickname)
         self.operations[http_method] = op
         return op
+
+    def add_model(self, model_name):
+        self.models[model_name] = model_name
+
+    def has_model(self, model_name):
+        return model_name in self.models
 
 
 class Operation(object):

Modified: team/dlee/stasis-http/rest-api/asterisk.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/rest-api/asterisk.json?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/rest-api/asterisk.json (original)
+++ team/dlee/stasis-http/rest-api/asterisk.json Thu Mar 14 13:43:23 2013
@@ -38,5 +38,10 @@
             ]
         }
     ],
-    "models": {}
+    "models": {
+        "AsteriskInfo": {
+            "id": "AsteriskInfo",
+            "properties": {}
+        }
+    }
 }

Modified: team/dlee/stasis-http/rest-api/bridges.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/rest-api/bridges.json?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/rest-api/bridges.json (original)
+++ team/dlee/stasis-http/rest-api/bridges.json Thu Mar 14 13:43:23 2013
@@ -15,7 +15,7 @@
                     "httpMethod": "GET",
                     "summary": "List active bridges",
                     "nickname": "getBridges",
-                    "responseClass": "Bridges"
+                    "responseClass": "List[Bridge]"
                 },
                 {
                     "httpMethod": "POST",
@@ -208,5 +208,10 @@
             ]
         }
     ],
-    "models": {}
+    "models": {
+        "Bridge": {
+            "id": "Bridge",
+            "properties": {}
+        }
+    }
 }

Modified: team/dlee/stasis-http/rest-api/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/rest-api/channels.json?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/rest-api/channels.json (original)
+++ team/dlee/stasis-http/rest-api/channels.json Thu Mar 14 13:43:23 2013
@@ -367,6 +367,14 @@
         }
     ],
     "models": {
+        "Originated": {
+            "id": "Originated",
+            "properties": {}
+        },
+        "Dialed": {
+            "id": "Dialed",
+            "properties": {}
+        },
         "DialplanCEP": {
             "id": "DialplanCEP",
             "properties": {

Modified: team/dlee/stasis-http/rest-api/endpoints.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/rest-api/endpoints.json?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/rest-api/endpoints.json (original)
+++ team/dlee/stasis-http/rest-api/endpoints.json Thu Mar 14 13:43:23 2013
@@ -15,7 +15,7 @@
                     "httpMethod": "GET",
                     "summary": "List available endoints",
                     "nickname": "getEndpoints",
-                    "responseClass": "Endpoints",
+                    "responseClass": "List[Endpoint]",
                     "parameters": [
                         {
                             "name": "withType",
@@ -50,5 +50,10 @@
             ]
         }
     ],
-    "models": {}
+    "models": {
+        "Endpoint": {
+            "id": "Endpoint",
+            "properties": {}
+        }
+    }
 }

Modified: team/dlee/stasis-http/rest-api/recordings.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/rest-api/recordings.json?view=diff&rev=383101&r1=383100&r2=383101
==============================================================================
--- team/dlee/stasis-http/rest-api/recordings.json (original)
+++ team/dlee/stasis-http/rest-api/recordings.json Thu Mar 14 13:43:23 2013
@@ -15,7 +15,7 @@
                     "httpMethod": "GET",
                     "summary": "List recordings",
                     "nickname": "getRecordings",
-                    "responseClass": "Recordings"
+                    "responseClass": "List[Recording]"
                 }
              ]
         },
@@ -163,5 +163,10 @@
             ]
         }
     ],
-    "models": {}
+    "models": {
+        "Recording": {
+            "id": "Recording",
+            "properties": {}
+        }
+    }
 }




More information about the asterisk-commits mailing list