[asterisk-dev] [Code Review] 2639: Update events to use Swagger 1.2 subtyping, and related aftermath

Matt Jordan reviewboard at asterisk.org
Mon Jul 1 19:21:26 CDT 2013


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2639/#review9039
-----------------------------------------------------------

Ship it!


Only trivial stuff.


/team/dlee/ari-url-shuffle/main/stasis_channels.c
<https://reviewboard.asterisk.org/r/2639/#comment17764>

    Because it feels appropriate...
    
    http://www.youtube.com/watch?v=juFZh92MUOY
    



/team/dlee/ari-url-shuffle/res/res_stasis.c
<https://reviewboard.asterisk.org/r/2639/#comment17765>

    I'd say go ahead and open an issue to do this. Even if we don't do it now, it'd be good to have something on the queue for it.



/team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c
<https://reviewboard.asterisk.org/r/2639/#comment17766>

    On initial inspection I couldn't tell why we only include this header in DEVMODE. Once I looked at it, it was obvious - it only includes validators.
    
    Is there a reason why this isn't called ari_model_validators or something similar?


- Matt Jordan


On June 28, 2013, 9:37 p.m., David Lee wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2639/
> -----------------------------------------------------------
> 
> (Updated June 28, 2013, 9:37 p.m.)
> 
> 
> Review request for Asterisk Developers and opticron.
> 
> 
> Bugs: ASTERISK-21885
>     https://issues.asterisk.org/jira/browse/ASTERISK-21885
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> 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.
> 
> This patch relies on the work in /team/dlee/ari-url-shuffle[2].
> 
>  [2]: https://reviewboard.asterisk.org/r/2621/
> 
> 
> Diffs
> -----
> 
>   /team/dlee/ari-url-shuffle/res/res_stasis.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_ari_model.exports.in PRE-CREATION 
>   /team/dlee/ari-url-shuffle/res/res_ari_model.c PRE-CREATION 
>   /team/dlee/ari-url-shuffle/res/Makefile 393218 
>   /team/dlee/ari-url-shuffle/main/stasis_endpoints.c 393218 
>   /team/dlee/ari-url-shuffle/main/stasis_channels.c 393218 
>   /team/dlee/ari-url-shuffle/main/stasis_bridging.c 393218 
>   /team/dlee/ari-url-shuffle/main/json.c 393218 
>   /team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h 393218 
>   /team/dlee/ari-url-shuffle/include/asterisk/json.h 393218 
>   /team/dlee/ari-url-shuffle/Makefile 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_events.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_asterisk.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_asterisk.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_bridges.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_bridges.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_channels.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_channels.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_endpoints.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_endpoints.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_events.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_events.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_playback.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_playback.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_recordings.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_recordings.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_sounds.c 393218 
>   /team/dlee/ari-url-shuffle/res/res_stasis_json_sounds.exports.in 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_http/ari_model.h PRE-CREATION 
>   /team/dlee/ari-url-shuffle/res/stasis_http/ari_model.c PRE-CREATION 
>   /team/dlee/ari-url-shuffle/res/stasis_http/ari_websockets.c 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_http/resource_recordings.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_http/resource_recordings.c 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_asterisk.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_bridges.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_channels.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_endpoints.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_events.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_playback.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_recordings.h 393218 
>   /team/dlee/ari-url-shuffle/res/stasis_json/resource_sounds.h 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/api.wiki.mustache PRE-CREATION 
>   /team/dlee/ari-url-shuffle/rest-api-templates/ari_model.c.mustache PRE-CREATION 
>   /team/dlee/ari-url-shuffle/rest-api-templates/ari_model.h.mustache PRE-CREATION 
>   /team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/event_function_decl.mustache 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/make_ari_stubs.py PRE-CREATION 
>   /team/dlee/ari-url-shuffle/rest-api-templates/make_stasis_http_stubs.py 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/models.wiki.mustache PRE-CREATION 
>   /team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_json_resource.c.mustache 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_json_resource.exports.mustache 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/stasis_json_resource.h.mustache 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py 393218 
>   /team/dlee/ari-url-shuffle/rest-api-templates/transform.py 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/asterisk.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/bridges.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/channels.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/endpoints.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/events.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/playback.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/recordings.json 393218 
>   /team/dlee/ari-url-shuffle/rest-api/api-docs/sounds.json 393218 
>   /team/dlee/ari-url-shuffle/tests/test_ari_model.c PRE-CREATION 
>   /team/dlee/ari-url-shuffle/tests/test_res_stasis.c 393218 
>   /team/dlee/ari-url-shuffle/tests/test_stasis_channels.c 393218 
> 
> Diff: https://reviewboard.asterisk.org/r/2639/diff/
> 
> 
> Testing
> -------
> 
> Unit tests for validator.
> 
> Created some channels, put them in Stasis(), using the ARI /bridges API to bridge them together. And it worked.
> 
> 
> Thanks,
> 
> David Lee
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130702/309421ce/attachment-0001.htm>


More information about the asterisk-dev mailing list