[Home]

Summary:ASTERISK-21885: Asterisk REST API - modify JSON events to include an event type field; update swagger and code generation to use a discriminated union
Reporter:Matt Jordan (mjordan)Labels:Asterisk12
Date Opened:2013-06-07 13:43:41Date Closed:2013-07-03 12:21:04
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/Stasis Resources/res_ari
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:Currently, JSON events returned from the websocket are typed based on the key:

{noformat}

{ 'type1': { 'foo': 'bar' } }

{ 'type2': { 'bar': 'yackity' } }

{noformat}

This can make parsers a bit more difficult, as they have to determine object types based on keys which may or may not be present in the event.

This approach was initially chosen due to the use of Swagger, which provides (among other things) the ability to generate static language bindings for the REST API. The static language bindings obviously require strongly typed objects, which is determined by the key. Having a nomenclature of:

{noformat}

{ 'type:' 'type1',
 'data:' { 'foo': 'bar' } }

{noformat}

however is ideal, as it does make it easier to parse for consumers of the API. Unfortunately, by default, this will make a mockery of static language bindings.

Instead, behind the scenes, we'll treat the object described by the 'data' field as a discriminated union. This will allow the object to be returned with the event type specified, but will keep Swagger useful.
Comments: