[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392113 - in /team/dlee/ari-event-remode...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 17 16:49:20 CDT 2013


Author: dlee
Date: Mon Jun 17 16:49:19 2013
New Revision: 392113

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392113
Log:
Rebased from ari-event-remodel branch

Added:
    team/dlee/ari-event-remodel2/res/res_ari_model.c
      - copied unchanged from r392112, team/dlee/ari-event-remodel/res/res_ari_model.c
    team/dlee/ari-event-remodel2/res/res_ari_model.exports.in
      - copied unchanged from r392112, team/dlee/ari-event-remodel/res/res_ari_model.exports.in
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
      - copied unchanged from r392112, team/dlee/ari-event-remodel/res/stasis_http/ari_model.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
      - copied unchanged from r392112, team/dlee/ari-event-remodel/res/stasis_http/ari_model.h
    team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache
      - copied unchanged from r392112, team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/ari_model.h.mustache
      - copied unchanged from r392112, team/dlee/ari-event-remodel/rest-api-templates/ari_model.h.mustache
    team/dlee/ari-event-remodel2/tests/test_ari_model.c
      - copied unchanged from r392112, team/dlee/ari-event-remodel/tests/test_ari_model.c
Modified:
    team/dlee/ari-event-remodel2/Makefile
    team/dlee/ari-event-remodel2/include/asterisk/json.h
    team/dlee/ari-event-remodel2/main/json.c
    team/dlee/ari-event-remodel2/res/Makefile
    team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c
    team/dlee/ari-event-remodel2/res/stasis_http/resource_channels.c
    team/dlee/ari-event-remodel2/res/stasis_json/resource_asterisk.h
    team/dlee/ari-event-remodel2/res/stasis_json/resource_events.h
    team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py
    team/dlee/ari-event-remodel2/rest-api-templates/make_stasis_http_stubs.py
    team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py
    team/dlee/ari-event-remodel2/rest-api/api-docs/asterisk.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/bridges.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/endpoints.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/events.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/playback.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/recordings.json
    team/dlee/ari-event-remodel2/rest-api/api-docs/sounds.json

Modified: team/dlee/ari-event-remodel2/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/Makefile?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/Makefile (original)
+++ team/dlee/ari-event-remodel2/Makefile Mon Jun 17 16:49:19 2013
@@ -971,7 +971,7 @@
 	@false
 else
 	$(PYTHON) rest-api-templates/make_stasis_http_stubs.py \
-		rest-api/resources.json res/
+		rest-api/resources.json .
 endif
 
 .PHONY: menuselect

Modified: team/dlee/ari-event-remodel2/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/include/asterisk/json.h?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/include/asterisk/json.h (original)
+++ team/dlee/ari-event-remodel2/include/asterisk/json.h Mon Jun 17 16:49:19 2013
@@ -157,6 +157,15 @@
  * \return Type of \a value.
  */
 enum ast_json_type ast_json_typeof(const struct ast_json *value);
+
+/*!
+ * \brief Get the string name for the given type.
+ * \since 12.0.0
+ * \param type Type to convert to string.
+ * \return Simple string for the type name (object, array, string, etc.)
+ * \return \c "?" for invalid types.
+ */
+const char *ast_json_typename(enum ast_json_type type);
 
 /*!@}*/
 

Modified: team/dlee/ari-event-remodel2/main/json.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/main/json.c?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/main/json.c (original)
+++ team/dlee/ari-event-remodel2/main/json.c Mon Jun 17 16:49:19 2013
@@ -100,6 +100,23 @@
 	ast_assert(0); /* Unexpect return from json_typeof */
 	return r;
 }
+
+const char *ast_json_typename(enum ast_json_type type)
+{
+	switch (type) {
+	case AST_JSON_OBJECT: return "object";
+	case AST_JSON_ARRAY: return "array";
+	case AST_JSON_STRING: return "string";
+	case AST_JSON_INTEGER: return "integer";
+	case AST_JSON_REAL: return "real";
+	case AST_JSON_TRUE: return "boolean";
+	case AST_JSON_FALSE: return "boolean";
+	case AST_JSON_NULL: return "null";
+	}
+	ast_assert(0);
+	return "?";
+}
+
 
 struct ast_json *ast_json_true(void)
 {

Modified: team/dlee/ari-event-remodel2/res/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/Makefile?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/res/Makefile (original)
+++ team/dlee/ari-event-remodel2/res/Makefile Mon Jun 17 16:49:19 2013
@@ -83,5 +83,8 @@
 res_stasis_http.so: stasis_http/ari_websockets.o
 stasis_http/ari_websockets.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_asterisk)
 
+res_ari_model.so: stasis_http/ari_model.o
+stasis_http/ari_model.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_ari_model)
+
 # Dependencies for res_stasis_http_*.so are generated, so they're in this file
 include stasis_http.make

Modified: team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c Mon Jun 17 16:49:19 2013
@@ -1,60 +1,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2012 - 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.
- */
-
-/*
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * !!!!!                               DO NOT EDIT                        !!!!!
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * This file is generated by a mustache template. Please see the original
- * template in rest-api-templates/res_stasis_http_resource.c.mustache
- */
-
-/*! \file
- *
- * \brief Asterisk resources
- *
- * \author David M. Lee, II <dlee at digium.com>
- */
-
-/*** MODULEINFO
-	<support_level>core</support_level>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/module.h"
-#include "asterisk/json.h"
-#include "stasis_json/resource_asterisk.h"
-static int load_module(void)
-{
-	return 0;
-}
-
-static int unload_module(void)
-{
-	return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
-	"Stasis JSON Generators and Validators - Asterisk resources",
-	.load = load_module,
-	.unload = unload_module,
-	.load_pri = AST_MODPRI_DEFAULT,
-	);

Modified: team/dlee/ari-event-remodel2/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/resource_channels.c?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/resource_channels.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/resource_channels.c Mon Jun 17 16:49:19 2013
@@ -1,4 +1,4 @@
-/* -*- C -*-
+/*
  * Asterisk -- An open source telephony toolkit.
  *
  * Copyright (C) 2012 - 2013, Digium, Inc.

Modified: team/dlee/ari-event-remodel2/res/stasis_json/resource_asterisk.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_json/resource_asterisk.h?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_json/resource_asterisk.h (original)
+++ team/dlee/ari-event-remodel2/res/stasis_json/resource_asterisk.h Mon Jun 17 16:49:19 2013
@@ -1,46 +1,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2012 - 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.
- */
-
-/*! \file
- *
- * \brief Generated file - declares stubs to be implemented in
- * res/stasis_json/resource_asterisk.c
- *
- * Asterisk resources
- *
- * \author David M. Lee, II <dlee at digium.com>
- */
-
-/*
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * !!!!!                               DO NOT EDIT                        !!!!!
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * This file is generated by a mustache template. Please see the original
- * template in rest-api-templates/stasis_http_resource.h.mustache
- */
-
-#ifndef _ASTERISK_RESOURCE_ASTERISK_H
-#define _ASTERISK_RESOURCE_ASTERISK_H
-
-/*
- * JSON models
- *
- * AsteriskInfo
- */
-
-#endif /* _ASTERISK_RESOURCE_ASTERISK_H */

Modified: team/dlee/ari-event-remodel2/res/stasis_json/resource_events.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_json/resource_events.h?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_json/resource_events.h (original)
+++ team/dlee/ari-event-remodel2/res/stasis_json/resource_events.h Mon Jun 17 16:49:19 2013
@@ -151,6 +151,8 @@
 
 /*!
  * \brief Notification that another WebSocket has taken over for an application.
+ * 
+ * An application may only be subscribed to by a single WebSocket at a time. If multiple WebSockets attempt to subscribe to the same application, the newer WebSocket wins, and the older one receives this event.
  *
  * \param blob JSON blob containing the following parameters:
  * - application: string  (required)
@@ -294,6 +296,8 @@
 
 /*!
  * \brief DTMF received on a channel.
+ * 
+ * This event is sent when the DTMF ends. There is no notification about the start of DTMF
  *
  * \param channel The channel on which DTMF was received
  * \param blob JSON blob containing the following parameters:
@@ -359,27 +363,9 @@
  * ChannelDtmfReceived
  * - digit: string (required)
  * Event
- * - channel_varset: ChannelVarset
- * - channel_created: ChannelCreated
- * - channel_destroyed: ChannelDestroyed
- * - channel_entered_bridge: ChannelEnteredBridge
- * - channel_left_bridge: ChannelLeftBridge
- * - bridge_merged: BridgeMerged
- * - channel_dialplan: ChannelDialplan
- * - application_replaced: ApplicationReplaced
- * - channel_state_change: ChannelStateChange
- * - bridge_created: BridgeCreated
  * - application: string (required)
- * - channel_hangup_request: ChannelHangupRequest
- * - channel_userevent: ChannelUserevent
- * - stasis_start: StasisStart
- * - channel_snapshot: ChannelSnapshot
- * - channel_dtmf_received: ChannelDtmfReceived
- * - channel_caller_id: ChannelCallerId
- * - bridge_destroyed: BridgeDestroyed
- * - playback_started: PlaybackStarted
- * - playback_finished: PlaybackFinished
- * - stasis_end: StasisEnd
+ * - type: DISCRIMINATOR
+ * - timestamp: Date
  * StasisEnd
  */
 

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=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py Mon Jun 17 16:49:19 2013
@@ -145,17 +145,6 @@
                 for operation in api.operations:
                     segment.operations.append(operation)
                 api.full_name = segment.full_name
-            resource_api.api_declaration.has_events = False
-            for model in resource_api.api_declaration.models:
-                if model.id == "Event":
-                    resource_api.api_declaration.has_events = True
-                    break
-            if resource_api.api_declaration.has_events:
-                resource_api.api_declaration.events = \
-                    [self.process_model(model, context) for model in \
-                        resource_api.api_declaration.models if model.id != "Event"]
-            else:
-                resource_api.api_declaration.events = []
 
             # Since every API path should start with /[resource], root should
             # have exactly one child.
@@ -179,7 +168,7 @@
     def process_parameter(self, parameter, context):
         if not parameter.data_type in self.type_mapping:
             raise SwaggerError(
-                "Invalid parameter type %s" % paramter.data_type, context)
+                "Invalid parameter type %s" % parameter.data_type, context)
         # Parameter names are camelcase, Asterisk convention is snake case
         parameter.c_name = snakify(parameter.name)
         parameter.c_data_type = self.type_mapping[parameter.data_type]
@@ -191,41 +180,15 @@
             parameter.c_space = ' '
 
     def process_model(self, model, context):
+        model.description_dox = model.description.replace('\n', '\n * ')
+        model.description_dox = re.sub(' *\n', '\n', model.description_dox)
         model.c_id = snakify(model.id)
-        model.channel = False
-        model.channel_desc = ""
-        model.bridge = False
-        model.bridge_desc = ""
-        model.properties = [self.process_property(model, prop, context) for prop in model.properties]
-        model.properties = [prop for prop in model.properties if prop]
 	model.has_properties = (len(model.properties) != 0)
         return model
 
-    def process_property(self, model, prop, context):
-        # process channel separately since it will be pulled out
-        if prop.name == 'channel' and prop.type == 'Channel':
-            model.channel = True
-            model.channel_desc = prop.description or ""
-            return None
-
-        # process bridge separately since it will be pulled out
-        if prop.name == 'bridge' and prop.type == 'Bridge':
-            model.bridge = True
-            model.bridge_desc = prop.description or ""
-            return None
-
-	prop.c_name = snakify(prop.name)
-        if prop.type in self.type_mapping:
-            prop.c_type = self.type_mapping[prop.type]
-            prop.c_convert = self.convert_mapping[prop.c_type]
-        else:
-            prop.c_type = "Property type %s not mappable to a C type" % (prop.type)
-            prop.c_convert = "Property type %s not mappable to a C conversion" % (prop.type)
-            #raise SwaggerError(
-            #    "Invalid property type %s" % prop.type, context)
-        # You shouldn't put a space between 'char *' and the variable
-        if prop.c_type.endswith('*'):
-            prop.c_space = ''
-        else:
-            prop.c_space = ' '
-        return prop
+    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 not be lowercase", context)
+        prop.snake_type = snakify(prop.type)

Modified: team/dlee/ari-event-remodel2/rest-api-templates/make_stasis_http_stubs.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/make_stasis_http_stubs.py?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/make_stasis_http_stubs.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/make_stasis_http_stubs.py Mon Jun 17 16:49:19 2013
@@ -42,21 +42,17 @@
 
 API_TRANSFORMS = [
     Transform(rel('res_stasis_http_resource.c.mustache'),
-              'res_stasis_http_{{name}}.c'),
+              'res/res_stasis_http_{{name}}.c'),
     Transform(rel('stasis_http_resource.h.mustache'),
-              'stasis_http/resource_{{name}}.h'),
+              'res/stasis_http/resource_{{name}}.h'),
     Transform(rel('stasis_http_resource.c.mustache'),
-              'stasis_http/resource_{{name}}.c', False),
-    Transform(rel('res_stasis_json_resource.c.mustache'),
-              'res_stasis_json_{{name}}.c'),
-    Transform(rel('res_stasis_json_resource.exports.mustache'),
-              'res_stasis_json_{{name}}.exports.in'),
-    Transform(rel('stasis_json_resource.h.mustache'),
-              'stasis_json/resource_{{name}}.h'),
+              'res/stasis_http/resource_{{name}}.c', overwrite=False),
 ]
 
 RESOURCES_TRANSFORMS = [
-    Transform(rel('stasis_http.make.mustache'), 'stasis_http.make'),
+    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'),
 ]
 
 

Modified: team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache Mon Jun 17 16:49:19 2013
@@ -42,11 +42,7 @@
 
 {{#events}}
 /*!
- * \brief {{description}}
-{{#notes}}
- *
- * {{{notes}}}
-{{/notes}}
+ * \brief {{{description_dox}}}
  *
 {{#channel}}
  * \param channel {{#channel_desc}}{{channel_desc}}{{/channel_desc}}{{^channel_desc}}The channel to be used to generate this event{{/channel_desc}}

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=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py Mon Jun 17 16:49:19 2013
@@ -29,6 +29,7 @@
 import json
 import os.path
 import pprint
+import re
 import sys
 import traceback
 
@@ -37,8 +38,61 @@
 except ImportError:
     from odict import OrderedDict
 
-
-SWAGGER_VERSION = "1.1"
+SWAGGER_VERSIONS=["1.1", "1.2"]
+
+class Stringify(object):
+    """Simple mix-in to make the repr of the model classes more meaningful.
+    """
+    def __repr__(self):
+        return "%s(%s)" % (self.__class__, pprint.saferepr(self.__dict__))
+
+
+class ParsingContext(object):
+    """Context information for parsing.
+
+    This object is immutable. To change contexts (like adding an item to the
+    stack), use the next() and next_stack() functions to build a new one.
+    """
+
+    def __init__(self, swagger_version, stack):
+        self.__swagger_version = swagger_version
+        self.__stack = stack
+
+    def __repr__(self):
+        return "ParsingContext(swagger_version=%s, stack=%s)" % (
+            self.swagger_version, self.stack)
+
+    def get_swagger_version(self):
+        return self.__swagger_version
+
+    def get_stack(self):
+        return self.__stack
+
+    swagger_version = property(get_swagger_version)
+
+    stack = property(get_stack)
+
+    def is_version(self, ver):
+        return self.swagger_version == ver
+
+    def next_stack(self, json, id_field):
+        """Returns a new item pushed to the stack.
+
+        @param json: Current JSON object.
+        @param id_field: Field identifying this object.
+        @return New context with additional item in the stack.
+        """
+        if not id_field in json:
+            raise SwaggerError("Missing id_field: %s" % id_field, self)
+        new_stack = self.stack + ['%s=%s' % (id_field, str(json[id_field]))]
+        return ParsingContext(self.swagger_version, new_stack)
+
+    def next(self, version=None, stack=None):
+        if version is None:
+            version = self.version
+        if stack is None:
+            stack = self.stack
+        return ParsingContext(version, stack)
 
 
 class SwaggerError(Exception):
@@ -50,7 +104,7 @@
         """Ctor.
 
         @param msg: String message for the error.
-        @param context: Array of strings for current context in the API.
+        @param context: ParsingContext object
         @param cause: Optional exception that caused this one.
         """
         super(Exception, self).__init__(msg, context, cause)
@@ -85,12 +139,21 @@
         """
         pass
 
-
-class Stringify(object):
-    """Simple mix-in to make the repr of the model classes more meaningful.
-    """
-    def __repr__(self):
-        return "%s(%s)" % (self.__class__, pprint.saferepr(self.__dict__))
+    def process_model(self, model, context):
+        """Post process a Model object.
+
+        @param model: Model object.
+        @param context: Current context in the API.
+        """
+        pass
+
+    def process_property(self, property, context):
+        """Post process a Property object.
+
+        @param property: Property object.
+        @param context: Current context in the API.
+        """
+        pass
 
 
 class AllowableRange(Stringify):
@@ -158,7 +221,7 @@
         self.allow_multiple = None
 
     def load(self, parameter_json, processor, context):
-        context = add_context(context, parameter_json, 'name')
+        context = context.next_stack(parameter_json, 'name')
         validate_required_fields(parameter_json, self.required_fields, context)
         self.name = parameter_json.get('name')
         self.param_type = parameter_json.get('paramType')
@@ -188,7 +251,7 @@
         self.reason = None
 
     def load(self, err_json, processor, context):
-        context = add_context(context, err_json, 'code')
+        context = context.next_stack(err_json, 'code')
         validate_required_fields(err_json, self.required_fields, context)
         self.code = err_json.get('code')
         self.reason = err_json.get('reason')
@@ -213,7 +276,7 @@
         self.error_responses = []
 
     def load(self, op_json, processor, context):
-        context = add_context(context, op_json, 'nickname')
+        context = context.next_stack(op_json, 'nickname')
         validate_required_fields(op_json, self.required_fields, context)
         self.http_method = op_json.get('httpMethod')
         self.nickname = op_json.get('nickname')
@@ -265,7 +328,7 @@
         self.operations = []
 
     def load(self, api_json, processor, context):
-        context = add_context(context, api_json, 'path')
+        context = context.next_stack(api_json, 'path')
         validate_required_fields(api_json, self.required_fields, context)
         self.path = api_json.get('path')
         self.description = api_json.get('description')
@@ -293,9 +356,25 @@
 
     def load(self, property_json, processor, context):
         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
+        self.is_discriminator = self.type == 'DISCRIMINATOR'
+        if self.is_discriminator:
+            self.type = "string"
+            if context.is_version("1.1"):
+                raise SwaggerError(
+                    "DISCRIMINATOR support added in Swagger 1.2", context)
+        list_match = re.match('^List\[(.*)\]$', self.type)
+        self.is_list = list_match is not None
+        if self.is_list:
+            self.type_param = list_match.group(1)
+        # Some common errors
+        if self.type == 'integer':
+            raise SwaggerError("The type for integer should be 'int'", context)
+        processor.process_property(self, context)
         return self
 
 
@@ -304,6 +383,8 @@
 
     See https://github.com/wordnik/swagger-core/wiki/datatypes
     """
+
+    required_fields = ['description', 'properties']
 
     def __init__(self):
         self.id = None
@@ -312,15 +393,21 @@
         self.properties = None
 
     def load(self, id, model_json, processor, context):
-        context = add_context(context, model_json, 'id')
-        # This arrangement is required by the Swagger API spec
+        context = context.next_stack(model_json, 'id')
+        validate_required_fields(model_json, self.required_fields, context)
+        # The duplication of the model's id is required by the Swagger spec.
         self.id = model_json.get('id')
         if id != self.id:
             raise SwaggerError("Model id doesn't match name", c)
+        self.extends = model_json.get('extends')
+        if self.extends and context.is_version("1.1"):
+            raise SwaggerError("Type extension support added in Swagger 1.2")
         self.description = model_json.get('description')
         props = model_json.get('properties').items() or []
         self.properties = [
             Property(k).load(j, processor, context) for (k, j) in props]
+        self.properties = sorted(self.properties, key=lambda p: p.name)
+        processor.process_model(self, context)
         return self
 
 
@@ -345,8 +432,8 @@
         self.apis = []
         self.models = []
 
-    def load_file(self, api_declaration_file, processor, context=[]):
-        context = context + [api_declaration_file]
+    def load_file(self, api_declaration_file, processor):
+        context = ParsingContext(None, [api_declaration_file])
         try:
             return self.__load_file(api_declaration_file, processor, context)
         except SwaggerError:
@@ -376,7 +463,8 @@
         """
         # If the version doesn't match, all bets are off.
         self.swagger_version = api_decl_json.get('swaggerVersion')
-        if self.swagger_version != SWAGGER_VERSION:
+        context = context.next(version = self.swagger_version)
+        if not self.swagger_version in SWAGGER_VERSIONS:
             raise SwaggerError(
                 "Unsupported Swagger version %s" % swagger_version, context)
 
@@ -392,7 +480,8 @@
             Api().load(j, processor, context) for j in api_json]
         models = api_decl_json.get('models').items() or []
         self.models = [
-            Model().load(k, j, processor, context) for (k, j) in models]
+            Model().load(id, json, processor, context) for (id, json) in models]
+        self.models = sorted(self.models, key=lambda m: m.id)
 
         return self
 
@@ -409,7 +498,7 @@
         self.api_declaration = None
 
     def load(self, api_json, processor, context):
-        context = add_context(context, api_json, 'path')
+        context = context.next_stack(api_json, 'path')
         validate_required_fields(api_json, self.required_fields, context)
         self.path = api_json['path']
         self.description = api_json['description']
@@ -438,7 +527,7 @@
         self.apis = None
 
     def load_file(self, resource_file, processor):
-        context = [resource_file]
+        context = ParsingContext(None, [resource_file])
         try:
             return self.__load_file(resource_file, processor, context)
         except SwaggerError:
@@ -455,7 +544,7 @@
     def load(self, resources_json, processor, context):
         # If the version doesn't match, all bets are off.
         self.swagger_version = resources_json.get('swaggerVersion')
-        if self.swagger_version != SWAGGER_VERSION:
+        if not self.swagger_version in SWAGGER_VERSIONS:
             raise SwaggerError(
                 "Unsupported Swagger version %s" % swagger_version, context)
 
@@ -482,16 +571,3 @@
     if missing_fields:
         raise SwaggerError(
             "Missing fields: %s" % ', '.join(missing_fields), context)
-
-
-def add_context(context, json, id_field):
-    """Returns a new context with a new item added to it.
-
-    @param context: Old context.
-    @param json: Current JSON object.
-    @param id_field: Field identifying this object.
-    @return New context with additional item.
-    """
-    if not id_field in json:
-        raise SwaggerError("Missing id_field: %s" % id_field, context)
-    return context + ['%s=%s' % (id_field, str(json[id_field]))]

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/asterisk.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/asterisk.json?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/asterisk.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/asterisk.json Mon Jun 17 16:49:19 2013
@@ -41,6 +41,7 @@
 	"models": {
 		"AsteriskInfo": {
 			"id": "AsteriskInfo",
+			"description": "Asterisk system information",
 			"properties": {}
 		}
 	}

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/bridges.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/bridges.json?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/bridges.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/bridges.json Mon Jun 17 16:49:19 2013
@@ -232,8 +232,9 @@
 	"models": {
 		"Bridge": {
 			"id": "Bridge",
+			"description": "The merging of media from one or more channels.\n\nEveryone on the bridge receives the same audio.",
 			"properties": {
-				"bridgeType": {
+				"bridge_type": {
 					"type": "string",
 					"description": "Type of bridge technology",
 					"required": true,

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json Mon Jun 17 16:49:19 2013
@@ -589,10 +589,12 @@
 	"models": {
 		"Dialed": {
 			"id": "Dialed",
+			"description": "Dialed channel information.",
 			"properties": {}
 		},
 		"DialplanCEP": {
 			"id": "DialplanCEP",
+			"description": "Dialplan location (context/extension/priority)",
 			"properties": {
 				"context": {
 					"required": true,
@@ -613,6 +615,7 @@
 		},
 		"CallerID": {
 			"id": "CallerID",
+			"description": "Caller identification",
 			"properties": {
 				"name": {
 					"required": true,
@@ -626,6 +629,7 @@
 		},
 		"Channel": {
 			"id": "Channel",
+			"description": "A specific communication connection between Asterisk and an Endpoint.",
 			"properties": {
 				"uniqueid": {
 					"required": true,
@@ -692,44 +696,6 @@
 					"required": true,
 					"type": "Date",
 					"description": "Timestamp when channel was created"
-				}
-			}
-		},
-		"Playback": {
-			"id": "Playback",
-			"description": "Object representing the playback of media to a channel",
-			"properties": {
-				"id": {
-					"type": "string",
-					"description": "ID for this playback operation",
-					"required": true
-				},
-				"media_uri": {
-					"type": "string",
-					"description": "URI for the media to play back.",
-					"required": true
-				},
-				"target_uri": {
-					"type": "string",
-					"description": "URI for the channel or bridge to play the media on",
-					"required": true
-				},
-				"language": {
-					"type": "string",
-					"description": "For media types that support multiple languages, the language requested for playback."
-				},
-				"state": {
-					"type": "string",
-					"description": "Current state of the playback operation.",
-					"required": true,
-					"allowableValues": {
-						"valueType": "LIST",
-						"values": [
-							"queued",
-							"playing",
-							"complete"
-						]
-					}
 				}
 			}
 		}

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/endpoints.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/endpoints.json?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/endpoints.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/endpoints.json Mon Jun 17 16:49:19 2013
@@ -69,7 +69,7 @@
 	"models": {
 		"Endpoint": {
 			"id": "Endpoint",
-			"description": "A snapshot of an endpoint. Unlike most resources, which have a single unique identifier, an endpoint is uniquely identified by the technology/resource pair.",
+			"description": "An external device that may offer/accept calls to/from Asterisk.\n\nUnlike most resources, which have a single unique identifier, an endpoint is uniquely identified by the technology/resource pair.",
 			"properties": {
 				"technology": {
 					"type": "string",

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/events.json?view=diff&rev=392113&r1=392112&r2=392113
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/events.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/events.json Mon Jun 17 16:49:19 2013
@@ -3,7 +3,7 @@
 	"_author": "David M. Lee, II <dlee at digium.com>",
 	"_svn_revision": "$Revision$",
 	"apiVersion": "0.0.1",
-	"swaggerVersion": "1.1",
+	"swaggerVersion": "1.2",
 	"basePath": "http://localhost:8088/stasis",
 	"resourcePath": "/api-docs/events.{format}",
 	"apis": [
@@ -35,37 +35,27 @@
 	"models": {
 		"Event": {
 			"id": "Event",
-			"description": "Asynchronous events from Asterisk. The non-required fields of this object are mutually exclusive.",
-			"properties": {
+			"description": "Base type for asynchronous events from Asterisk.",
+			"properties": {
+				"type": {
+					"type": "DISCRIMINATOR",
+					"description": "Indicates the type of this event."
+				},
 				"application": {
 					"type": "string",
 					"description": "Name of the application receiving the event.",
 					"required": true
 				},
-				"application_replaced": { "type": "ApplicationReplaced" },
-				"bridge_created": { "type": "BridgeCreated" },
-				"bridge_destroyed": { "type": "BridgeDestroyed" },
-				"bridge_merged": { "type": "BridgeMerged" },
-				"channel_created": { "type": "ChannelCreated" },
-				"channel_destroyed": { "type": "ChannelDestroyed" },
-				"channel_snapshot": { "type": "ChannelSnapshot" },
-				"channel_entered_bridge": { "type": "ChannelEnteredBridge" },
-				"channel_left_bridge": { "type": "ChannelLeftBridge" },
-				"channel_state_change": { "type": "ChannelStateChange" },
-				"channel_dtmf_received": { "type": "ChannelDtmfReceived" },
-				"channel_dialplan": { "type": "ChannelDialplan" },
-				"channel_caller_id": { "type": "ChannelCallerId" },
-				"channel_userevent": { "type": "ChannelUserevent" },
-				"channel_hangup_request": { "type": "ChannelHangupRequest" },
-				"channel_varset": { "type": "ChannelVarset" },
-				"stasis_end": { "type": "StasisEnd" },
-				"stasis_start": { "type": "StasisStart" },
-				"playback_started": { "type": "PlaybackStarted" },
-				"playback_finished": { "type": "PlaybackFinished" }
+				"timestamp": {
+					"type": "Date",
+					"description": "Time at which this event was created.",
+					"required": false
+				}
 			}
 		},
 		"PlaybackStarted": {
 			"id": "PlaybackStarted",
+			"extends": "Event",
 			"description": "Event showing the start of a media playback operation.",
 			"properties": {
 				"playback": {
@@ -77,6 +67,7 @@
 		},
 		"PlaybackFinished": {
 			"id": "PlaybackFinished",
+			"extends": "Event",
 			"description": "Event showing the completion of a media playback operation.",
 			"properties": {
 				"playback": {
@@ -88,8 +79,8 @@
 		},
 		"ApplicationReplaced": {
 			"id": "ApplicationReplaced",
-			"description": "Notification that another WebSocket has taken over for an application.",
-			"notes": "An application may only be subscribed to by a single WebSocket at a time. If multiple WebSockets attempt to subscribe to the same application, the newer WebSocket wins, and the older one receives this event.",
+			"extends": "Event",
+			"description": "Notification that another WebSocket has taken over for an application.\n\nAn application may only be subscribed to by a single WebSocket at a time. If multiple WebSockets attempt to subscribe to the same application, the newer WebSocket wins, and the older one receives this event.",
 			"properties": {
 				"application": {
 					"required": true,
@@ -99,6 +90,7 @@
 		},
 		"BridgeCreated": {
 			"id": "BridgeCreated",
+			"extends": "Event",
 			"description": "Notification that a bridge has been created.",
 			"properties": {
 				"bridge": {
@@ -109,6 +101,7 @@
 		},
 		"BridgeDestroyed": {
 			"id": "BridgeDestroyed",
+			"extends": "Event",
 			"description": "Notification that a bridge has been destroyed.",
 			"properties": {
 				"bridge": {
@@ -119,6 +112,7 @@
 		},
 		"BridgeMerged": {
 			"id": "BridgeMerged",
+			"extends": "Event",
 			"description": "Notification that one bridge has merged into another.",
 			"properties": {
 				"bridge": {
@@ -133,6 +127,7 @@
 		},
 		"ChannelCreated": {
 			"id": "ChannelCreated",
+			"extends": "Event",
 			"description": "Notification that a channel has been created.",
 			"properties": {
 				"channel": {
@@ -143,6 +138,7 @@
 		},
 		"ChannelSnapshot": {
 			"id": "ChannelSnapshot",
+			"extends": "Event",
 			"description": "Some part of channel state changed.",
 			"properties": {
 				"channel": {
@@ -153,12 +149,13 @@
 		},
 		"ChannelDestroyed": {
 			"id": "ChannelDestroyed",
+			"extends": "Event",
 			"description": "Notification that a channel has been destroyed.",
 			"properties": {
 				"cause": {
 					"required": true,
 					"description": "Integer representation of the cause of the hangup",
-					"type": "integer"
+					"type": "int"
 				},
 				"cause_txt": {

[... 235 lines stripped ...]



More information about the asterisk-commits mailing list