-
Notifications
You must be signed in to change notification settings - Fork 2
/
swagger-api-client.html
90 lines (70 loc) · 2.31 KB
/
swagger-api-client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!--
@license
Copyright (c) 2015 Paul Koanui <[email protected]>. All rights reserved.
This code may only be used under the BSD style license found at http://paulkoanui.github.io/LICENSE.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="swagger-import.html">
<!--
An element that wraps the <a href="https://github.com/swagger-api/swagger-js">swagger-js</a> library for generating
dynamic swagger api clients for easy use in the browser.
Example:
<swagger-api-client
spec="http://petstore.swagger.io/v2/swagger.json">
</swagger-api-client>
@demo
-->
<dom-module id="swagger-api-client">
<style></style>
<template></template>
</dom-module>
<script>
Polymer({
is: 'swagger-api-client',
properties: {
/**
* The URL of a Swagger API specification.
*
* @type {string}
*/
spec: {
type: String,
observer: '_specChanged'
},
/**
* The dynamically generated Swagger API client.<br/>
* See https://github.com/swagger-api/swagger-js for more info.
*
* @type {swagger-client}
*/
client: {
type: Object
}
},
_specChanged: function(){
this.loadSpec(this.spec);
},
// Element Behavior
/**
* Dynamically generate a Swagger API client from a Swagger specification.
* The event, "swagger-client-ready" is fired when the API client is ready.
*
* @param {string} The URL of a Swagger API specification.
* @fires swagger-client-ready
*/
loadSpec: function(spec) {
this.client = new SwaggerClient({
url: spec,
success: function() {
console.log('swagger-client', this.client);
/**
* This event is fired when the Swagger API client has been fully initialized and ready for use.
*
* @event swagger-client-ready
*/
this.fire('swagger-client-ready', { loaded: new Date() });
}.bind(this)
});
},
});
</script>