summaryrefslogtreecommitdiff
path: root/rest-api
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-07-03 16:32:41 +0000
committerDavid M. Lee <dlee@digium.com>2013-07-03 16:32:41 +0000
commitc9a3d4562ddb1ed5b34f7d5530efd6aa695377c2 (patch)
treedd082285fbb5c7714164e26145acc5c966e663be /rest-api
parentdcf03554a0b38806bf1fe258acc423b070533d6e (diff)
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data model to be more sane. The original model would send out events like: { "stasis_start": { "args": [], "channel": { ... } } } The event discriminator was the field name instead of being a value in the object, due to limitations in how Swagger 1.1 could model objects. While technically sufficient in communicating event information, it was really difficult to deal with in terms of client side JSON handling. This patch takes advantage of a proposed extension[1] to Swagger which allows type variance through the use of a discriminator field. This had a domino effect that made this a surprisingly large patch. [1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ In changing the models, I also had to change the swagger_model.py processor so it can handle the type discriminator and subtyping. I took that a big step forward, and using that information to generate an ari_model module, which can validate a JSON object against the Swagger model. The REST and WebSocket generators were changed to take advantage of the validators. If compiled with AST_DEVMODE enabled, JSON objects that don't match their corresponding models will not be sent out. For REST API calls, a 500 Internal Server response is sent. For WebSockets, the invalid JSON message is replaced with an error message. Since this took over about half of the job of the existing JSON generators, and the .to_json virtual function on messages took over the other half, I reluctantly removed the generators. The validators turned up all sorts of errors and inconsistencies in our data models, and the code. These were cleaned up, with checks in the code generator avoid some of the consistency problems in the future. * The model for a channel snapshot was trimmed down to match the information sent via AMI. Many of the field being sent were not useful in the general case. * The model for a bridge snapshot was updated to be more consistent with the other ARI models. Another impact of introducing subtyping was that the swagger-codegen documentation generator was insufficient (at least until it catches up with Swagger 1.2). I wanted it to be easier to generate docs for the API anyways, so I ported the wiki pages to use the Asterisk Swagger generator. In the process, I was able to clean up many of the model links, which would occasionally give inconsistent results on the wiki. I also added error responses to the wiki docs, making the wiki documentation more complete. Finally, since Stasis-HTTP will now be named Asterisk REST Interface (ARI), any new functions and files I created carry the ari_ prefix. I changed a few stasis_http references to ari where it was non-intrusive and made sense. (closes issue ASTERISK-21885) Review: https://reviewboard.asterisk.org/r/2639/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'rest-api')
-rw-r--r--rest-api/api-docs/asterisk.json1
-rw-r--r--rest-api/api-docs/bridges.json52
-rw-r--r--rest-api/api-docs/channels.json114
-rw-r--r--rest-api/api-docs/endpoints.json20
-rw-r--r--rest-api/api-docs/events.json108
-rw-r--r--rest-api/api-docs/playback.json32
-rw-r--r--rest-api/api-docs/recordings.json25
-rw-r--r--rest-api/api-docs/sounds.json2
8 files changed, 188 insertions, 166 deletions
diff --git a/rest-api/api-docs/asterisk.json b/rest-api/api-docs/asterisk.json
index ef6c7b864..8ee88e439 100644
--- a/rest-api/api-docs/asterisk.json
+++ b/rest-api/api-docs/asterisk.json
@@ -41,6 +41,7 @@
"models": {
"AsteriskInfo": {
"id": "AsteriskInfo",
+ "description": "Asterisk system information",
"properties": {}
}
}
diff --git a/rest-api/api-docs/bridges.json b/rest-api/api-docs/bridges.json
index 5b0cf6298..87d5b3d4f 100644
--- a/rest-api/api-docs/bridges.json
+++ b/rest-api/api-docs/bridges.json
@@ -31,8 +31,8 @@
"required": false,
"allowMultiple": false,
"dataType": "string",
- "allowedValues": {
- "type": "LIST",
+ "allowableValues": {
+ "valueType": "LIST",
"values": [
"mixing",
"holding"
@@ -61,6 +61,12 @@
"allowMultiple": false,
"dataType": "string"
}
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Bridge not found"
+ }
]
},
{
@@ -78,6 +84,12 @@
"allowMultiple": false,
"dataType": "string"
}
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Bridge not found"
+ }
]
}
]
@@ -108,6 +120,20 @@
"allowMultiple": true,
"dataType": "string"
}
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Bridge not found"
+ },
+ {
+ "code": 409,
+ "reason": "Bridge not in Stasis application"
+ },
+ {
+ "code": 422,
+ "reason": "Channel not found, or not in Stasis application"
+ }
]
}
]
@@ -231,19 +257,35 @@
"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": {
+ "id": {
+ "type": "string",
+ "description": "Unique identifier for this bridge",
+ "required": true
+ },
+ "technology": {
+ "type": "string",
+ "description": "Name of the current bridging technology",
+ "required": true
+ },
+ "bridge_type": {
"type": "string",
"description": "Type of bridge technology",
"required": true,
- "allowedValues": {
- "type": "LIST",
+ "allowableValues": {
+ "valueType": "LIST",
"values": [
"mixing",
"holding"
]
}
},
+ "bridge_class": {
+ "type": "string",
+ "description": "Bridging class",
+ "required": true
+ },
"channels": {
"type": "List[string]",
"description": "Id's of channels participating in this bridge",
diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json
index 623cb17bb..f013ef641 100644
--- a/rest-api/api-docs/channels.json
+++ b/rest-api/api-docs/channels.json
@@ -286,6 +286,10 @@
{
"code": 404,
"reason": "Channel not found"
+ },
+ {
+ "code": 409,
+ "reason": "Channel not in a Stasis application"
}
]
}
@@ -616,11 +620,7 @@
},
{
"code": 409,
- "reason": "Channel is not in a Stasis application."
- },
- {
- "code": 409,
- "reason": "The channel is currently bridged with other channels."
+ "reason": "Channel is not in a Stasis application, or the channel is currently bridged with other channels."
}
]
}
@@ -630,10 +630,12 @@
"models": {
"Dialed": {
"id": "Dialed",
+ "description": "Dialed channel information.",
"properties": {}
},
"DialplanCEP": {
"id": "DialplanCEP",
+ "description": "Dialplan location (context/extension/priority)",
"properties": {
"context": {
"required": true,
@@ -654,6 +656,7 @@
},
"CallerID": {
"id": "CallerID",
+ "description": "Caller identification",
"properties": {
"name": {
"required": true,
@@ -667,11 +670,12 @@
},
"Channel": {
"id": "Channel",
+ "description": "A specific communication connection between Asterisk and an Endpoint.",
"properties": {
- "uniqueid": {
+ "id": {
"required": true,
"type": "string",
- "description": "Unique identifier of the channel"
+ "description": "Unique identifier of the channel.\n\nThis is the same as the Uniqueid field in AMI."
},
"name": {
"required": true,
@@ -680,99 +684,47 @@
},
"state": {
"required": true,
- "type": "string"
- },
- "accountcode": {
- "required": true,
- "type": "string"
- },
- "peeraccount": {
- "required": true,
- "type": "string"
- },
- "userfield": {
- "required": true,
- "type": "string"
+ "type": "string",
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "Down",
+ "Rsrved",
+ "OffHook",
+ "Dialing",
+ "Ring",
+ "Ringing",
+ "Up",
+ "Busy",
+ "Dialing Offhook",
+ "Pre-ring",
+ "Unknown"
+ ]
+ }
},
- "linkedid": {
+ "caller": {
"required": true,
- "type": "string"
+ "type": "CallerID"
},
- "parkinglot": {
+ "connected": {
"required": true,
- "type": "string"
+ "type": "CallerID"
},
- "hangupsource": {
+ "accountcode": {
"required": true,
"type": "string"
},
- "appl": {
- "required": true,
- "type": "string",
- "description": "Currently executing dialplan application"
- },
- "data": {
- "required": true,
- "type": "string",
- "description": "Arguments passed to appl"
- },
"dialplan": {
"required": true,
"type": "DialplanCEP",
"description": "Current location in the dialplan"
},
- "caller": {
- "required": true,
- "type": "CallerID"
- },
- "connected": {
- "required": true,
- "type": "CallerID"
- },
"creationtime": {
"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"
- ]
- }
- }
- }
}
}
}
diff --git a/rest-api/api-docs/endpoints.json b/rest-api/api-docs/endpoints.json
index d3d77d84a..9d0ff1840 100644
--- a/rest-api/api-docs/endpoints.json
+++ b/rest-api/api-docs/endpoints.json
@@ -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",
@@ -80,6 +80,24 @@
"type": "string",
"description": "Identifier of the endpoint, specific to the given technology.",
"required": true
+ },
+ "state": {
+ "type": "string",
+ "description": "Endpoint's state",
+ "required": false,
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "unknown",
+ "offline",
+ "online"
+ ]
+ }
+ },
+ "channel_ids": {
+ "type": "List[string]",
+ "description": "Id's of channels associated with this endpoint",
+ "required": true
}
}
}
diff --git a/rest-api/api-docs/events.json b/rest-api/api-docs/events.json
index 56a05e4ee..79908eff7 100644
--- a/rest-api/api-docs/events.json
+++ b/rest-api/api-docs/events.json
@@ -3,7 +3,7 @@
"_author": "David M. Lee, II <dlee@digium.com>",
"_svn_revision": "$Revision$",
"apiVersion": "0.0.1",
- "swaggerVersion": "1.1",
+ "swaggerVersion": "1.3",
"basePath": "http://localhost:8088/stasis",
"resourcePath": "/api-docs/events.{format}",
"apis": [
@@ -35,37 +35,29 @@
"models": {
"Event": {
"id": "Event",
- "description": "Asynchronous events from Asterisk. The non-required fields of this object are mutually exclusive.",
+ "description": "Base type for asynchronous events from Asterisk.",
+ "discriminator": "type",
"properties": {
+ "type": {
+ "type": "string",
+ "required": true,
+ "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 +69,7 @@
},
"PlaybackFinished": {
"id": "PlaybackFinished",
+ "extends": "Event",
"description": "Event showing the completion of a media playback operation.",
"properties": {
"playback": {
@@ -88,17 +81,13 @@
},
"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.",
- "properties": {
- "application": {
- "required": true,
- "type": "string"
- }
- }
+ "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": {}
},
"BridgeCreated": {
"id": "BridgeCreated",
+ "extends": "Event",
"description": "Notification that a bridge has been created.",
"properties": {
"bridge": {
@@ -109,6 +98,7 @@
},
"BridgeDestroyed": {
"id": "BridgeDestroyed",
+ "extends": "Event",
"description": "Notification that a bridge has been destroyed.",
"properties": {
"bridge": {
@@ -119,6 +109,7 @@
},
"BridgeMerged": {
"id": "BridgeMerged",
+ "extends": "Event",
"description": "Notification that one bridge has merged into another.",
"properties": {
"bridge": {
@@ -133,6 +124,7 @@
},
"ChannelCreated": {
"id": "ChannelCreated",
+ "extends": "Event",
"description": "Notification that a channel has been created.",
"properties": {
"channel": {
@@ -141,24 +133,15 @@
}
}
},
- "ChannelSnapshot": {
- "id": "ChannelSnapshot",
- "description": "Some part of channel state changed.",
- "properties": {
- "channel": {
- "required": true,
- "type": "Channel"
- }
- }
- },
"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": {
"required": true,
@@ -173,6 +156,7 @@
},
"ChannelEnteredBridge": {
"id": "ChannelEnteredBridge",
+ "extends": "Event",
"description": "Notification that a channel has entered a bridge.",
"properties": {
"bridge": {
@@ -186,6 +170,7 @@
},
"ChannelLeftBridge": {
"id": "ChannelLeftBridge",
+ "extends": "Event",
"description": "Notification that a channel has left a bridge.",
"properties": {
"bridge": {
@@ -200,6 +185,7 @@
},
"ChannelStateChange": {
"id": "ChannelStateChange",
+ "extends": "Event",
"description": "Notification of a channel's state change.",
"properties": {
"channel": {
@@ -210,14 +196,19 @@
},
"ChannelDtmfReceived": {
"id": "ChannelDtmfReceived",
- "description": "DTMF received on a channel.",
- "notes": "This event is sent when the DTMF ends. There is no notification about the start of DTMF",
+ "extends": "Event",
+ "description": "DTMF received on a channel.\n\nThis event is sent when the DTMF ends. There is no notification about the start of DTMF",
"properties": {
"digit": {
"required": true,
"type": "string",
"description": "DTMF digit received (0-9, A-E, # or *)"
},
+ "duration_ms": {
+ "required": true,
+ "type": "int",
+ "description": "Number of milliseconds DTMF was received"
+ },
"channel": {
"required": true,
"type": "Channel",
@@ -227,32 +218,34 @@
},
"ChannelDialplan": {
"id": "ChannelDialplan",
+ "extends": "Event",
"description": "Channel changed location in the dialplan.",
"properties": {
- "application": {
+ "channel": {
"required": true,
- "type": "string",
- "description": "The application that the channel is currently in."
+ "type": "Channel",
+ "description": "The channel that changed dialplan location."
},
- "application_data": {
+ "dialplan_app": {
"required": true,
"type": "string",
- "description": "The data that was passed to the application when it was invoked."
+ "description": "The application about to be executed."
},
- "channel": {
+ "dialplan_app_data": {
"required": true,
- "type": "Channel",
- "description": "The channel that changed dialplan location."
+ "type": "string",
+ "description": "The data to be passed to the application."
}
}
},
"ChannelCallerId": {
"id": "ChannelCallerId",
+ "extends": "Event",
"description": "Channel changed Caller ID.",
"properties": {
"caller_presentation": {
"required": true,
- "type": "integer",
+ "type": "int",
"description": "The integer representation of the Caller Presentation value."
},
"caller_presentation_txt": {
@@ -269,6 +262,7 @@
},
"ChannelUserevent": {
"id": "ChannelUserevent",
+ "extends": "Event",
"description": "User-generated event with additional user-defined fields in the object.",
"properties": {
"eventname": {
@@ -285,10 +279,11 @@
},
"ChannelHangupRequest": {
"id": "ChannelHangupRequest",
+ "extends": "Event",
"description": "A hangup was requested on the channel.",
"properties": {
"cause": {
- "type": "integer",
+ "type": "int",
"description": "Integer representation of the cause of the hangup."
},
"soft": {
@@ -304,6 +299,7 @@
},
"ChannelVarset": {
"id": "ChannelVarset",
+ "extends": "Event",
"description": "Channel variable changed.",
"properties": {
"variable": {
@@ -317,14 +313,15 @@
"description": "The new value of the variable."
},
"channel": {
- "required": true,
+ "required": false,
"type": "Channel",
- "description": "The channel on which the variable was set."
+ "description": "The channel on which the variable was set.\n\nIf missing, the variable is a global variable."
}
}
},
"StasisEnd": {
"id": "StasisEnd",
+ "extends": "Event",
"description": "Notification that a channel has left a Stasis appliction.",
"properties": {
"channel": {
@@ -335,6 +332,7 @@
},
"StasisStart": {
"id": "StasisStart",
+ "extends": "Event",
"description": "Notification that a channel has entered a Stasis appliction.",
"properties": {
"args": {
diff --git a/rest-api/api-docs/playback.json b/rest-api/api-docs/playback.json
index 38ca5e1a7..884c0db26 100644
--- a/rest-api/api-docs/playback.json
+++ b/rest-api/api-docs/playback.json
@@ -103,11 +103,39 @@
"models": {
"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,
- "description": "Playback's identifier.",
- "type": "string"
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "queued",
+ "playing",
+ "complete"
+ ]
+ }
}
}
}
diff --git a/rest-api/api-docs/recordings.json b/rest-api/api-docs/recordings.json
index 2f5f92a08..ce11d17c2 100644
--- a/rest-api/api-docs/recordings.json
+++ b/rest-api/api-docs/recordings.json
@@ -8,18 +8,6 @@
"resourcePath": "/api-docs/recordings.{format}",
"apis": [
{
- "path": "/recordings",
- "description": "Recordings",
- "operations": [
- {
- "httpMethod": "GET",
- "summary": "List all recordings.",
- "nickname": "getRecordings",
- "responseClass": "List[Recording]"
- }
- ]
- },
- {
"path": "/recordings/stored",
"description": "Recordings",
"operations": [
@@ -226,17 +214,9 @@
}
],
"models": {
- "Recording": {
- "id": "Recording",
- "properties": {
- "id": {
- "required": true,
- "type": "string"
- }
- }
- },
"StoredRecording": {
"id": "StoredRecording",
+ "description": "A past recording that may be played back.",
"properties": {
"id": {
"required": true,
@@ -246,7 +226,7 @@
"required": true,
"type": "List[string]"
},
- "durationSeconds": {
+ "duration_seconds": {
"required": false,
"type": "int"
},
@@ -259,6 +239,7 @@
},
"LiveRecording": {
"id": "LiveRecording",
+ "description": "A recording that is in progress",
"properties": {
"id": {
"required": true,
diff --git a/rest-api/api-docs/sounds.json b/rest-api/api-docs/sounds.json
index 06d84ea7e..103738c45 100644
--- a/rest-api/api-docs/sounds.json
+++ b/rest-api/api-docs/sounds.json
@@ -60,6 +60,7 @@
"models": {
"FormatLangPair": {
"id": "FormatLangPair",
+ "description": "Identifies the format and language of a sound file",
"properties": {
"language": {
"required": true,
@@ -73,6 +74,7 @@
},
"Sound": {
"id": "Sound",
+ "description": "A media file that may be played back.",
"properties": {
"id": {
"required": true,