summaryrefslogtreecommitdiff
path: root/rest-api-templates/asterisk_processor.py
AgeCommit message (Collapse)Author
2016-12-21Fixes to various issues reported by pyflakesTzafrir Cohen
Pyflake is a python (2) source checker. This patch fixes various (mostly trivial) errors and warnings it reports. Change-Id: Ia35c5ac61751b927814cf693994c632c412386ea
2015-10-20rest-api-templates: Wikify error code response reasonsMatt Jordan
Error response code descriptions may contain wiki markup that need to be escaped. Without this patch, Confluence will reject the document being sent and the responsible script will raise an exception. Change-Id: I21fcb66fee7f6332381f2b99b1b0195dff215ee5
2015-01-27ARI: Improve wiki documentationMatthew Jordan
This patch improves the documentation of ARI on the wiki. Specifically, it addresses the following: * Allowed values and allowed ranges weren't documented. This was particularly frustrating, as Asterisk would reject query parameters with disallowed values - but we didn't tell anyone what the allowed values were. * The /play/id operation on /channels and /bridges failed to document all of the added media resource types. * Documentation for creating a channel into a Stasis application failed to note when it occurred, and that creating a channel into Stasis conflicts with creating a channel into the dialplan. * Some other minor tweaks in the mustache templates, including italicizing the parameter type, putting the default value on its own sub-bullet, and some other nicities. Review: https://reviewboard.asterisk.org/r/4351 ........ Merged revisions 431145 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431148 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-01-21ARI: Support channel variables in originateKinsey Moore
This adds back in support for specifying channel variables during an originate without compromising the ability to specify query parameters in the JSON body. This was accomplished by generating the body-parsing code in a separate function instead of being integrated with the URI query parameter parsing code such that it could be called by paths with body parameters. This is transparent to the user of the API and prevents manual duplication of code or data structures. (closes issue ASTERISK-23051) Review: https://reviewboard.asterisk.org/r/3122/ Reported by: Matt Jordan ........ Merged revisions 406003 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@406006 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-11-27ari:Add application/json parameter supportDavid M. Lee
The patch allows ARI to parse request parameters from an incoming JSON request body, instead of requiring the request to come in as query parameters (which is just weird for POST and DELETE) or form parameters (which is okay, but a bit asymmetric given that all of our responses are JSON). For any operation that does _not_ have a parameter defined of type body (i.e. "paramType": "body" in the API declaration), if a request provides a request body with a Content type of "application/json", the provided JSON document is parsed and searched for parameters. The expected fields in the provided JSON document should match the query parameters defined for the operation. If the parameter has 'allowMultiple' set, then the field in the JSON document may optionally be an array of values. (closes issue ASTERISK-22685) Review: https://reviewboard.asterisk.org/r/2994/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403177 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-11-07ari: User better nicknames for ARI operationsDavid M. Lee
While working on building client libraries from the Swagger API, I noticed a problem with the nicknames. channel.deleteChannel() channel.answerChannel() channel.muteChannel() Etc. We put the object name in the nickname (since we were generating C code), but it makes OO generators redundant. This patch makes the nicknames more OO friendly. This resulted in a lot of name changing within the res_ari_*.so modules, but not much else. There were a couple of other fixed I made in the process. * When reversible operations (POST /hold, POST /unhold) were made more RESTful (POST /hold, DELETE /unhold), the path for the second operation was left in the API declaration. This worked, but really the two operations should have been on the same API. * The POST /unmute operation had still not been REST-ified. Review: https://reviewboard.asterisk.org/r/2940/ ........ Merged revisions 402528 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-10-15My doc correction in r400842 had a silly bug.David M. Lee
Because I added a wiki_description to models and not their properties, the rendered wiki page had the model description instead of the property descriptions, which looks very silly indeed. (closes issue ASTERISK-22705) ........ Merged revisions 400958 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400959 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-10-11Multiple revisions 400508,400842-400843,400848David M. Lee
........ r400508 | dlee | 2013-10-03 23:54:51 -0500 (Thu, 03 Oct 2013) | 1 line Corrected response class for stopPlayback ........ r400842 | dlee | 2013-10-10 14:23:24 -0500 (Thu, 10 Oct 2013) | 1 line Correct some ARI wiki rendering errors ........ r400843 | dlee | 2013-10-10 14:26:19 -0500 (Thu, 10 Oct 2013) | 1 line Updated /play resource docs. The playback of http: resources isn't implemented... yet ........ r400848 | dlee | 2013-10-11 11:18:46 -0500 (Fri, 11 Oct 2013) | 5 lines Fix a stupid copy/paste error in ARI docs. Patches: ari-doc-patch.txt uploaded by jbigelow (license 5091) ........ Merged revisions 400508,400842-400843,400848 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400852 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-29Account for {} in Swagger notesDavid M. Lee
........ Merged revisions 397927 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03ARI - channel recording supportDavid M. Lee
This patch is the first step in adding recording support to the Asterisk REST Interface. Recordings are stored in /var/spool/recording. Since recordings may be destructive (overwriting existing files), the API rejects attempts to escape the recording directory (avoiding issues if someone attempts to record to ../../lib/sounds/greeting, for example). (closes issue ASTERISK-21594) (closes issue ASTERISK-21581) Review: https://reviewboard.asterisk.org/r/2612/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393550 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03Update events to use Swagger 1.3 subtyping, and related aftermathDavid M. Lee
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
2013-07-03Shuffle RESTful URL's around.David M. Lee
This patch moves the RESTful URL's around to more appropriate locations for release. The /stasis URL's are moved to /ari, since Asterisk REST Interface was a more appropriate name than Stasis-HTTP. (Most of the code still has stasis_http references, but they will be cleaned up after there are no more outstanding branches that would have merge conflicts with such a change). A larger change was moving the ARI events WebSocket off of the shared /ws URL to its permanent home on /ari/events. The Swagger code generator was extended to handle "upgrade: websocket" and "websocketProtocol:" attributes on an operation. The WebSocket module was modified to better handle WebSocket servers that have a single registered protocol handler. If a client connections does not specify the Sec-WebSocket-Protocol header, and the server has a single protocol handler registered, the WebSocket server will go ahead and accept the client for that subprotocol. (closes issue ASTERISK-21857) Review: https://reviewboard.asterisk.org/r/2621/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393528 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-10Add channel events for res_stasis appsKinsey Moore
This change adds a framework in res_stasis for handling events from channel topics. JSON event generation and validation code is created from event documentation in rest-api/api-docs/events.json to assist in JSON event generation, ensure consistency, and ensure that accurate documentation is available for ALL events that are received by res_stasis applications. The userevent application has been refactored along with the code that handles userevent channel blob events to pass the headers as key/value pairs in the JSON blob. As a side-effect, app_userevent now handles duplicate keys by overwriting the previous value. Review: https://reviewboard.asterisk.org/r/2428/ (closes issue ASTERISK-21180) Patch-By: Kinsey Moore <kmoore@digium.com> git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@388275 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-04-22This patch adds a RESTful HTTP interface to Asterisk.David M. Lee
The API itself is documented using Swagger, a lightweight mechanism for documenting RESTful API's using JSON. This allows us to use swagger-ui to provide executable documentation for the API, generate client bindings in different languages, and generate a lot of the boilerplate code for implementing the RESTful bindings. The API docs live in the rest-api/ directory. The RESTful bindings are generated from the Swagger API docs using a set of Mustache templates. The code generator is written in Python, and uses Pystache. Pystache has no dependencies, and be installed easily using pip. Code generation code lives in rest-api-templates/. The generated code reduces a lot of boilerplate when it comes to handling HTTP requests. It also helps us have greater consistency in the REST API. (closes issue ASTERISK-20891) Review: https://reviewboard.asterisk.org/r/2376/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386232 65c4cc65-6c06-0410-ace0-fbb531ad65f3