swaggard 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-700.eot +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-700.svg +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-700.ttf +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-700.woff +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-700.woff2 +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-regular.eot +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-regular.svg +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-regular.ttf +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-regular.woff +0 -0
- data/app/assets/fonts/swaggard/droid-sans-v6-latin-regular.woff2 +0 -0
- data/app/assets/images/swaggard/explorer_icons.png +0 -0
- data/app/assets/images/swaggard/favicon-16x16.png +0 -0
- data/app/assets/images/swaggard/favicon-32x32.png +0 -0
- data/app/assets/images/swaggard/favicon.ico +0 -0
- data/app/assets/images/swaggard/logo_small.png +0 -0
- data/app/assets/images/swaggard/pet_store_api.png +0 -0
- data/app/assets/images/swaggard/throbber.gif +0 -0
- data/app/assets/images/swaggard/wordnik_api.png +0 -0
- data/app/assets/javascripts/swaggard/application.js +12 -12
- data/app/assets/javascripts/swaggard/lib/backbone-min.js +0 -0
- data/app/assets/javascripts/swaggard/lib/handlebars-2.0.0.js +0 -0
- data/app/assets/javascripts/swaggard/lib/highlight.7.3.pack.js +0 -0
- data/app/assets/javascripts/swaggard/lib/jquery-1.8.0.min.js +1 -1
- data/app/assets/javascripts/swaggard/lib/jquery.ba-bbq.min.js +0 -0
- data/app/assets/javascripts/swaggard/lib/jquery.slideto.min.js +0 -0
- data/app/assets/javascripts/swaggard/lib/jquery.wiggle.min.js +0 -0
- data/app/assets/javascripts/swaggard/lib/marked.js +0 -0
- data/app/assets/javascripts/swaggard/lib/swagger-oauth.js +290 -0
- data/app/assets/javascripts/swaggard/lib/underscore-min.js +6 -32
- data/app/assets/javascripts/swaggard/lib/underscore-min.map +1 -0
- data/app/assets/javascripts/swaggard/swaggard.js +59 -0
- data/app/assets/javascripts/swaggard/swagger-ui.js +31404 -1363
- data/app/assets/stylesheets/swaggard/application.css +1 -1
- data/app/assets/stylesheets/swaggard/application_print.css +15 -0
- data/app/assets/stylesheets/swaggard/print.css.scss +1175 -0
- data/app/assets/stylesheets/swaggard/reset.css +0 -0
- data/app/assets/stylesheets/swaggard/screen.css.scss +41 -15
- data/app/assets/stylesheets/swaggard/typography.css.scss +2 -1
- data/app/controllers/swaggard/swagger_controller.rb +3 -1
- data/app/views/swaggard/swagger/index.html.erb +30 -71
- data/config/initializers/assets.rb +1 -0
- data/lib/swaggard.rb +13 -7
- data/lib/swaggard/api_definition.rb +3 -1
- data/lib/swaggard/configuration.rb +18 -6
- data/lib/swaggard/engine.rb +8 -2
- data/lib/swaggard/parsers/controllers.rb +0 -2
- data/lib/swaggard/parsers/models.rb +1 -1
- data/lib/swaggard/swagger/default_response.rb +17 -0
- data/lib/swaggard/swagger/definition.rb +3 -1
- data/lib/swaggard/swagger/operation.rb +3 -0
- data/lib/swaggard/swagger/parameters/body.rb +4 -2
- data/lib/swaggard/swagger/parameters/query.rb +13 -1
- data/lib/swaggard/swagger/response.rb +14 -6
- data/lib/swaggard/swagger/type.rb +27 -42
- data/lib/swaggard/version.rb +1 -1
- data/spec/fixtures/api.json +1 -1
- data/spec/fixtures/dummy/app/controllers/admin/pets_controller.rb +11 -0
- data/spec/fixtures/dummy/config/routes.rb +4 -1
- data/spec/fixtures/swagger_schema.json +1495 -0
- data/spec/integration/swaggard_spec.rb +8 -4
- data/spec/spec_helper.rb +0 -1
- metadata +17 -8
- data/app/assets/javascripts/swaggard/lib/MD5.js +0 -319
- data/app/assets/javascripts/swaggard/lib/handlebars-1.0.rc.1.js +0 -1920
- data/app/assets/javascripts/swaggard/lib/shred.bundle.js +0 -2765
- data/app/assets/javascripts/swaggard/lib/swagger-client.js +0 -3294
- data/app/assets/javascripts/swaggard/lib/swagger.js +0 -794
- data/app/assets/javascripts/swaggard/swagger-ui_org.js +0 -2005
@@ -1,794 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 1.4.0
|
2
|
-
(function() {
|
3
|
-
var SwaggerApi, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
|
4
|
-
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
5
|
-
|
6
|
-
SwaggerApi = (function() {
|
7
|
-
|
8
|
-
SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
|
9
|
-
|
10
|
-
SwaggerApi.prototype.debug = false;
|
11
|
-
|
12
|
-
SwaggerApi.prototype.api_key = null;
|
13
|
-
|
14
|
-
SwaggerApi.prototype.basePath = null;
|
15
|
-
|
16
|
-
function SwaggerApi(options) {
|
17
|
-
if (options == null) {
|
18
|
-
options = {};
|
19
|
-
}
|
20
|
-
if (options.discoveryUrl != null) {
|
21
|
-
this.discoveryUrl = options.discoveryUrl;
|
22
|
-
}
|
23
|
-
if (options.debug != null) {
|
24
|
-
this.debug = options.debug;
|
25
|
-
}
|
26
|
-
this.apiKeyName = options.apiKeyName != null ? options.apiKeyName : 'api_key';
|
27
|
-
if (options.apiKey != null) {
|
28
|
-
this.api_key = options.apiKey;
|
29
|
-
}
|
30
|
-
if (options.api_key != null) {
|
31
|
-
this.api_key = options.api_key;
|
32
|
-
}
|
33
|
-
if (options.verbose != null) {
|
34
|
-
this.verbose = options.verbose;
|
35
|
-
}
|
36
|
-
this.supportHeaderParams = options.supportHeaderParams != null ? options.supportHeaderParams : false;
|
37
|
-
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
|
38
|
-
if (options.success != null) {
|
39
|
-
this.success = options.success;
|
40
|
-
}
|
41
|
-
this.failure = options.failure != null ? options.failure : function() {};
|
42
|
-
this.progress = options.progress != null ? options.progress : function() {};
|
43
|
-
this.headers = options.headers != null ? options.headers : {};
|
44
|
-
this.auth_hash = options.auth_hash != null ? options.auth_hash : {};
|
45
|
-
this.booleanValues = options.booleanValues != null ? options.booleanValues : new Array('true', 'false');
|
46
|
-
this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
|
47
|
-
if (options.success != null) {
|
48
|
-
this.build();
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
SwaggerApi.prototype.build = function() {
|
53
|
-
var _this = this;
|
54
|
-
this.progress('fetching resource list: ' + this.discoveryUrl);
|
55
|
-
return jQuery.getJSON(this.discoveryUrl, function(response) {
|
56
|
-
var res, resource, _i, _j, _len, _len1, _ref, _ref1;
|
57
|
-
if (response.apiVersion != null) {
|
58
|
-
_this.apiVersion = response.apiVersion;
|
59
|
-
}
|
60
|
-
if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
|
61
|
-
_this.basePath = response.basePath;
|
62
|
-
if (_this.basePath.match(/^HTTP/i) == null) {
|
63
|
-
_this.fail("discoveryUrl basePath must be a URL.");
|
64
|
-
}
|
65
|
-
_this.basePath = _this.basePath.replace(/\/$/, '');
|
66
|
-
} else {
|
67
|
-
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('/'));
|
68
|
-
log('derived basepath from discoveryUrl as ' + _this.basePath);
|
69
|
-
}
|
70
|
-
_this.apis = {};
|
71
|
-
_this.apisArray = [];
|
72
|
-
if (response.resourcePath != null) {
|
73
|
-
_this.resourcePath = response.resourcePath;
|
74
|
-
res = null;
|
75
|
-
_ref = response.apis;
|
76
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
77
|
-
resource = _ref[_i];
|
78
|
-
if (res === null) {
|
79
|
-
res = new SwaggerResource(resource, _this);
|
80
|
-
} else {
|
81
|
-
res.addOperations(resource.path, resource.operations);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
if (res != null) {
|
85
|
-
_this.apis[res.name] = res;
|
86
|
-
_this.apisArray.push(res);
|
87
|
-
res.ready = true;
|
88
|
-
_this.selfReflect();
|
89
|
-
}
|
90
|
-
} else {
|
91
|
-
_ref1 = response.apis;
|
92
|
-
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
93
|
-
resource = _ref1[_j];
|
94
|
-
res = new SwaggerResource(resource, _this);
|
95
|
-
_this.apis[res.name] = res;
|
96
|
-
_this.apisArray.push(res);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
return _this;
|
100
|
-
}).error(function(error) {
|
101
|
-
if (_this.discoveryUrl.substring(0, 4) !== 'http') {
|
102
|
-
return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
|
103
|
-
} else if (error.status === 0) {
|
104
|
-
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
|
105
|
-
} else if (error.status === 404) {
|
106
|
-
return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
|
107
|
-
} else {
|
108
|
-
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
|
109
|
-
}
|
110
|
-
});
|
111
|
-
};
|
112
|
-
|
113
|
-
SwaggerApi.prototype.selfReflect = function() {
|
114
|
-
var resource, resource_name, _ref;
|
115
|
-
if (this.apis == null) {
|
116
|
-
return false;
|
117
|
-
}
|
118
|
-
_ref = this.apis;
|
119
|
-
for (resource_name in _ref) {
|
120
|
-
resource = _ref[resource_name];
|
121
|
-
if (resource.ready == null) {
|
122
|
-
return false;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
this.setConsolidatedModels();
|
126
|
-
this.ready = true;
|
127
|
-
if (this.success != null) {
|
128
|
-
return this.success();
|
129
|
-
}
|
130
|
-
};
|
131
|
-
|
132
|
-
SwaggerApi.prototype.fail = function(message) {
|
133
|
-
this.failure(message);
|
134
|
-
throw message;
|
135
|
-
};
|
136
|
-
|
137
|
-
SwaggerApi.prototype.setConsolidatedModels = function() {
|
138
|
-
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
|
139
|
-
this.modelsArray = [];
|
140
|
-
this.models = {};
|
141
|
-
_ref = this.apis;
|
142
|
-
for (resource_name in _ref) {
|
143
|
-
resource = _ref[resource_name];
|
144
|
-
for (modelName in resource.models) {
|
145
|
-
if (!(this.models[modelName] != null)) {
|
146
|
-
this.models[modelName] = resource.models[modelName];
|
147
|
-
this.modelsArray.push(resource.models[modelName]);
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
_ref1 = this.modelsArray;
|
152
|
-
_results = [];
|
153
|
-
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
154
|
-
model = _ref1[_i];
|
155
|
-
_results.push(model.setReferencedModels(this.models));
|
156
|
-
}
|
157
|
-
return _results;
|
158
|
-
};
|
159
|
-
|
160
|
-
SwaggerApi.prototype.suffixApiKey = function(url) {
|
161
|
-
var sep;
|
162
|
-
if ((this.api_key != null) && jQuery.trim(this.api_key).length > 0 && (url != null)) {
|
163
|
-
sep = url.indexOf('?') > 0 ? '&' : '?';
|
164
|
-
return url + sep + this.apiKeyName + '=' + this.api_key;
|
165
|
-
} else {
|
166
|
-
return url;
|
167
|
-
}
|
168
|
-
};
|
169
|
-
|
170
|
-
SwaggerApi.prototype.help = function() {
|
171
|
-
var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
|
172
|
-
_ref = this.apis;
|
173
|
-
for (resource_name in _ref) {
|
174
|
-
resource = _ref[resource_name];
|
175
|
-
console.log(resource_name);
|
176
|
-
_ref1 = resource.operations;
|
177
|
-
for (operation_name in _ref1) {
|
178
|
-
operation = _ref1[operation_name];
|
179
|
-
console.log(" " + operation.nickname);
|
180
|
-
_ref2 = operation.parameters;
|
181
|
-
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
182
|
-
parameter = _ref2[_i];
|
183
|
-
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
}
|
187
|
-
return this;
|
188
|
-
};
|
189
|
-
|
190
|
-
return SwaggerApi;
|
191
|
-
|
192
|
-
})();
|
193
|
-
|
194
|
-
SwaggerResource = (function() {
|
195
|
-
|
196
|
-
function SwaggerResource(resourceObj, api) {
|
197
|
-
var parts,
|
198
|
-
_this = this;
|
199
|
-
this.api = api;
|
200
|
-
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
201
|
-
this.description = resourceObj.description;
|
202
|
-
// SwaggerYard changes
|
203
|
-
// Do not parse out .{format} from path, swagger-ui treats it the format differently.
|
204
|
-
// parts = this.path.split("/");
|
205
|
-
// this.name = parts[parts.length - 1].replace('.{format}', '');
|
206
|
-
this.name = this.path.substring(1);
|
207
|
-
// End of changes
|
208
|
-
this.basePath = this.api.basePath;
|
209
|
-
this.operations = {};
|
210
|
-
this.operationsArray = [];
|
211
|
-
this.modelsArray = [];
|
212
|
-
this.models = {};
|
213
|
-
if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
|
214
|
-
this.api.progress('reading resource ' + this.name + ' models and operations');
|
215
|
-
this.addModels(resourceObj.models);
|
216
|
-
this.addOperations(resourceObj.path, resourceObj.operations);
|
217
|
-
this.api[this.name] = this;
|
218
|
-
} else {
|
219
|
-
if (this.path == null) {
|
220
|
-
this.api.fail("SwaggerResources must have a path.");
|
221
|
-
}
|
222
|
-
this.url = this.api.suffixApiKey(this.api.basePath + this.path.replace('{format}', 'json'));
|
223
|
-
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
|
224
|
-
jQuery.getJSON(this.url, function(response) {
|
225
|
-
var endpoint, _i, _len, _ref;
|
226
|
-
if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
|
227
|
-
_this.basePath = response.basePath;
|
228
|
-
_this.basePath = _this.basePath.replace(/\/$/, '');
|
229
|
-
}
|
230
|
-
_this.addModels(response.models);
|
231
|
-
if (response.apis) {
|
232
|
-
_ref = response.apis;
|
233
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
234
|
-
endpoint = _ref[_i];
|
235
|
-
_this.addOperations(endpoint.path, endpoint.operations);
|
236
|
-
}
|
237
|
-
}
|
238
|
-
_this.api[_this.name] = _this;
|
239
|
-
_this.ready = true;
|
240
|
-
return _this.api.selfReflect();
|
241
|
-
}).error(function(error) {
|
242
|
-
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
|
243
|
-
});
|
244
|
-
}
|
245
|
-
}
|
246
|
-
|
247
|
-
SwaggerResource.prototype.addModels = function(models) {
|
248
|
-
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
249
|
-
if (models != null) {
|
250
|
-
for (modelName in models) {
|
251
|
-
if (!(this.models[modelName] != null)) {
|
252
|
-
swaggerModel = new SwaggerModel(modelName, models[modelName]);
|
253
|
-
this.modelsArray.push(swaggerModel);
|
254
|
-
this.models[modelName] = swaggerModel;
|
255
|
-
}
|
256
|
-
}
|
257
|
-
_ref = this.modelsArray;
|
258
|
-
_results = [];
|
259
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
260
|
-
model = _ref[_i];
|
261
|
-
_results.push(model.setReferencedModels(this.models));
|
262
|
-
}
|
263
|
-
return _results;
|
264
|
-
}
|
265
|
-
};
|
266
|
-
|
267
|
-
SwaggerResource.prototype.addOperations = function(resource_path, ops) {
|
268
|
-
var consumes, o, op, _i, _len, _results;
|
269
|
-
if (ops) {
|
270
|
-
_results = [];
|
271
|
-
for (_i = 0, _len = ops.length; _i < _len; _i++) {
|
272
|
-
o = ops[_i];
|
273
|
-
consumes = o.consumes;
|
274
|
-
if (o.supportedContentTypes) {
|
275
|
-
consumes = o.supportedContentTypes;
|
276
|
-
}
|
277
|
-
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this, o.consumes, o.produces);
|
278
|
-
this.operations[op.nickname] = op;
|
279
|
-
_results.push(this.operationsArray.push(op));
|
280
|
-
}
|
281
|
-
return _results;
|
282
|
-
}
|
283
|
-
};
|
284
|
-
|
285
|
-
SwaggerResource.prototype.help = function() {
|
286
|
-
var operation, operation_name, parameter, _i, _len, _ref, _ref1;
|
287
|
-
_ref = this.operations;
|
288
|
-
for (operation_name in _ref) {
|
289
|
-
operation = _ref[operation_name];
|
290
|
-
console.log(" " + operation.nickname);
|
291
|
-
_ref1 = operation.parameters;
|
292
|
-
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
293
|
-
parameter = _ref1[_i];
|
294
|
-
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
295
|
-
}
|
296
|
-
}
|
297
|
-
return this;
|
298
|
-
};
|
299
|
-
|
300
|
-
return SwaggerResource;
|
301
|
-
|
302
|
-
})();
|
303
|
-
|
304
|
-
SwaggerModel = (function() {
|
305
|
-
|
306
|
-
function SwaggerModel(modelName, obj) {
|
307
|
-
var propertyName;
|
308
|
-
this.name = obj.id != null ? obj.id : modelName;
|
309
|
-
this.properties = [];
|
310
|
-
for (propertyName in obj.properties) {
|
311
|
-
this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
|
312
|
-
}
|
313
|
-
}
|
314
|
-
|
315
|
-
SwaggerModel.prototype.setReferencedModels = function(allModels) {
|
316
|
-
var prop, _i, _len, _ref, _results;
|
317
|
-
_ref = this.properties;
|
318
|
-
_results = [];
|
319
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
320
|
-
prop = _ref[_i];
|
321
|
-
if (allModels[prop.dataType] != null) {
|
322
|
-
_results.push(prop.refModel = allModels[prop.dataType]);
|
323
|
-
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
|
324
|
-
_results.push(prop.refModel = allModels[prop.refDataType]);
|
325
|
-
} else {
|
326
|
-
_results.push(void 0);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
return _results;
|
330
|
-
};
|
331
|
-
|
332
|
-
SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
|
333
|
-
var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
|
334
|
-
propertiesStr = [];
|
335
|
-
_ref = this.properties;
|
336
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
337
|
-
prop = _ref[_i];
|
338
|
-
propertiesStr.push(prop.toString());
|
339
|
-
}
|
340
|
-
strong = '<span class="strong">';
|
341
|
-
stronger = '<span class="stronger">';
|
342
|
-
strongClose = '</span>';
|
343
|
-
classOpen = strong + this.name + ' {' + strongClose;
|
344
|
-
classClose = strong + '}' + strongClose;
|
345
|
-
returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
|
346
|
-
if (!modelsToIgnore) {
|
347
|
-
modelsToIgnore = [];
|
348
|
-
}
|
349
|
-
modelsToIgnore.push(this);
|
350
|
-
_ref1 = this.properties;
|
351
|
-
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
352
|
-
prop = _ref1[_j];
|
353
|
-
if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
|
354
|
-
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
|
355
|
-
}
|
356
|
-
}
|
357
|
-
return returnVal;
|
358
|
-
};
|
359
|
-
|
360
|
-
SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
|
361
|
-
var prop, result, _i, _len, _ref;
|
362
|
-
result = {};
|
363
|
-
modelsToIgnore = modelsToIgnore || [];
|
364
|
-
modelsToIgnore.push(this.name);
|
365
|
-
_ref = this.properties;
|
366
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
367
|
-
prop = _ref[_i];
|
368
|
-
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
369
|
-
}
|
370
|
-
return result;
|
371
|
-
};
|
372
|
-
|
373
|
-
return SwaggerModel;
|
374
|
-
|
375
|
-
})();
|
376
|
-
|
377
|
-
SwaggerModelProperty = (function() {
|
378
|
-
|
379
|
-
function SwaggerModelProperty(name, obj) {
|
380
|
-
this.name = name;
|
381
|
-
this.dataType = obj.type;
|
382
|
-
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
|
383
|
-
this.descr = obj.description;
|
384
|
-
this.required = obj.required;
|
385
|
-
if (obj.items != null) {
|
386
|
-
if (obj.items.type != null) {
|
387
|
-
this.refDataType = obj.items.type;
|
388
|
-
}
|
389
|
-
if (obj.items.$ref != null) {
|
390
|
-
this.refDataType = obj.items.$ref;
|
391
|
-
}
|
392
|
-
}
|
393
|
-
this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
|
394
|
-
if (obj.allowableValues != null) {
|
395
|
-
this.valueType = obj.allowableValues.valueType;
|
396
|
-
this.values = obj.allowableValues.values;
|
397
|
-
if (this.values != null) {
|
398
|
-
this.valuesString = "'" + this.values.join("' or '") + "'";
|
399
|
-
}
|
400
|
-
}
|
401
|
-
}
|
402
|
-
|
403
|
-
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
404
|
-
var result;
|
405
|
-
if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
|
406
|
-
result = this.refModel.createJSONSample(modelsToIgnore);
|
407
|
-
} else {
|
408
|
-
if (this.isCollection) {
|
409
|
-
result = this.refDataType;
|
410
|
-
} else {
|
411
|
-
if(this.dataType === 'int'){
|
412
|
-
result = 0;
|
413
|
-
|
414
|
-
}else if(this.dataType === 'long' || this.dataType === 'float'){
|
415
|
-
result = parseFloat("0.1");
|
416
|
-
}
|
417
|
-
else if(this.dataType === 'boolean')
|
418
|
-
{
|
419
|
-
result = false;
|
420
|
-
}
|
421
|
-
else
|
422
|
-
{
|
423
|
-
result = this.dataType;
|
424
|
-
}
|
425
|
-
}
|
426
|
-
}
|
427
|
-
if (this.isCollection) {
|
428
|
-
return [result];
|
429
|
-
} else {
|
430
|
-
return result;
|
431
|
-
}
|
432
|
-
};
|
433
|
-
|
434
|
-
SwaggerModelProperty.prototype.toString = function() {
|
435
|
-
var req, str;
|
436
|
-
req = this.required ? 'propReq' : 'propOpt';
|
437
|
-
str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
|
438
|
-
if (!this.required) {
|
439
|
-
str += ', <span class="propOptKey">optional</span>';
|
440
|
-
}
|
441
|
-
str += ')';
|
442
|
-
if (this.values != null) {
|
443
|
-
str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
|
444
|
-
}
|
445
|
-
if (this.descr != null) {
|
446
|
-
str += ': <span class="propDesc">' + this.descr + '</span>';
|
447
|
-
}
|
448
|
-
return str;
|
449
|
-
};
|
450
|
-
|
451
|
-
return SwaggerModelProperty;
|
452
|
-
|
453
|
-
})();
|
454
|
-
|
455
|
-
SwaggerOperation = (function() {
|
456
|
-
|
457
|
-
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, consumes, produces) {
|
458
|
-
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
|
459
|
-
_this = this;
|
460
|
-
this.nickname = nickname;
|
461
|
-
this.path = path;
|
462
|
-
this.httpMethod = httpMethod;
|
463
|
-
this.parameters = parameters != null ? parameters : [];
|
464
|
-
this.summary = summary;
|
465
|
-
this.notes = notes;
|
466
|
-
this.responseClass = responseClass;
|
467
|
-
this.errorResponses = errorResponses;
|
468
|
-
this.resource = resource;
|
469
|
-
this.consumes = consumes;
|
470
|
-
this.produces = produces;
|
471
|
-
this["do"] = __bind(this["do"], this);
|
472
|
-
|
473
|
-
if (this.nickname == null) {
|
474
|
-
this.resource.api.fail("SwaggerOperations must have a nickname.");
|
475
|
-
}
|
476
|
-
if (this.path == null) {
|
477
|
-
this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
|
478
|
-
}
|
479
|
-
if (this.httpMethod == null) {
|
480
|
-
this.resource.api.fail("SwaggerOperation " + nickname + " is missing httpMethod.");
|
481
|
-
}
|
482
|
-
this.path = this.path.replace('{format}', 'json');
|
483
|
-
this.httpMethod = this.httpMethod.toLowerCase();
|
484
|
-
this.isGetMethod = this.httpMethod === "get";
|
485
|
-
this.resourceName = this.resource.name;
|
486
|
-
if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
|
487
|
-
this.responseClass = void 0;
|
488
|
-
}
|
489
|
-
if (this.responseClass != null) {
|
490
|
-
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
|
491
|
-
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
|
492
|
-
}
|
493
|
-
this.errorResponses = this.errorResponses || [];
|
494
|
-
_ref1 = this.parameters;
|
495
|
-
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
496
|
-
parameter = _ref1[_i];
|
497
|
-
parameter.name = parameter.name || parameter.dataType;
|
498
|
-
if (parameter.dataType.toLowerCase() === 'boolean') {
|
499
|
-
parameter.allowableValues = {};
|
500
|
-
parameter.allowableValues.values = this.resource.api.booleanValues;
|
501
|
-
}
|
502
|
-
parameter.signature = this.getSignature(parameter.dataType, this.resource.models);
|
503
|
-
parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models);
|
504
|
-
if (parameter.allowableValues != null) {
|
505
|
-
if (parameter.allowableValues.valueType === "RANGE") {
|
506
|
-
parameter.isRange = true;
|
507
|
-
} else {
|
508
|
-
parameter.isList = true;
|
509
|
-
}
|
510
|
-
if (parameter.allowableValues.values != null) {
|
511
|
-
parameter.allowableValues.descriptiveValues = [];
|
512
|
-
_ref2 = parameter.allowableValues.values;
|
513
|
-
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
514
|
-
v = _ref2[_j];
|
515
|
-
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
|
516
|
-
parameter.allowableValues.descriptiveValues.push({
|
517
|
-
value: v,
|
518
|
-
isDefault: true
|
519
|
-
});
|
520
|
-
} else {
|
521
|
-
parameter.allowableValues.descriptiveValues.push({
|
522
|
-
value: v,
|
523
|
-
isDefault: false
|
524
|
-
});
|
525
|
-
}
|
526
|
-
}
|
527
|
-
}
|
528
|
-
}
|
529
|
-
}
|
530
|
-
this.resource[this.nickname] = function(args, callback, error) {
|
531
|
-
return _this["do"](args, callback, error);
|
532
|
-
};
|
533
|
-
}
|
534
|
-
|
535
|
-
SwaggerOperation.prototype.isListType = function(dataType) {
|
536
|
-
if (dataType.indexOf('[') >= 0) {
|
537
|
-
return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']'));
|
538
|
-
} else {
|
539
|
-
return void 0;
|
540
|
-
}
|
541
|
-
};
|
542
|
-
|
543
|
-
SwaggerOperation.prototype.getSignature = function(dataType, models) {
|
544
|
-
var isPrimitive, listType;
|
545
|
-
listType = this.isListType(dataType);
|
546
|
-
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
|
547
|
-
if (isPrimitive) {
|
548
|
-
return dataType;
|
549
|
-
} else {
|
550
|
-
if (listType != null) {
|
551
|
-
return models[listType].getMockSignature();
|
552
|
-
} else {
|
553
|
-
return models[dataType].getMockSignature();
|
554
|
-
}
|
555
|
-
}
|
556
|
-
};
|
557
|
-
|
558
|
-
SwaggerOperation.prototype.getSampleJSON = function(dataType, models) {
|
559
|
-
var isPrimitive, listType, val;
|
560
|
-
listType = this.isListType(dataType);
|
561
|
-
isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
|
562
|
-
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample());
|
563
|
-
if (val) {
|
564
|
-
val = listType ? [val] : val;
|
565
|
-
return JSON.stringify(val, null, 2);
|
566
|
-
}
|
567
|
-
};
|
568
|
-
|
569
|
-
SwaggerOperation.prototype["do"] = function(args, callback, error) {
|
570
|
-
var body, headers;
|
571
|
-
if (args == null) {
|
572
|
-
args = {};
|
573
|
-
}
|
574
|
-
if ((typeof args) === "function") {
|
575
|
-
error = callback;
|
576
|
-
callback = args;
|
577
|
-
args = {};
|
578
|
-
}
|
579
|
-
if (error == null) {
|
580
|
-
error = function(xhr, textStatus, error) {
|
581
|
-
return console.log(xhr, textStatus, error);
|
582
|
-
};
|
583
|
-
}
|
584
|
-
if (callback == null) {
|
585
|
-
callback = function(data) {
|
586
|
-
return console.log(data);
|
587
|
-
};
|
588
|
-
}
|
589
|
-
if (args.headers != null) {
|
590
|
-
headers = args.headers;
|
591
|
-
delete args.headers;
|
592
|
-
}
|
593
|
-
if (args.body != null) {
|
594
|
-
body = args.body;
|
595
|
-
delete args.body;
|
596
|
-
}
|
597
|
-
return new SwaggerRequest(this.httpMethod, this.urlify(args), headers, body, callback, error, this);
|
598
|
-
};
|
599
|
-
|
600
|
-
SwaggerOperation.prototype.pathJson = function() {
|
601
|
-
return this.path.replace("{format}", "json");
|
602
|
-
};
|
603
|
-
|
604
|
-
SwaggerOperation.prototype.pathXml = function() {
|
605
|
-
return this.path.replace("{format}", "xml");
|
606
|
-
};
|
607
|
-
|
608
|
-
SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
|
609
|
-
var param, queryParams, reg, url, _i, _len, _ref;
|
610
|
-
if (includeApiKey == null) {
|
611
|
-
includeApiKey = true;
|
612
|
-
}
|
613
|
-
url = this.resource.basePath + this.pathJson();
|
614
|
-
_ref = this.parameters;
|
615
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
616
|
-
param = _ref[_i];
|
617
|
-
if (param.paramType === 'path') {
|
618
|
-
if (args[param.name]) {
|
619
|
-
reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
|
620
|
-
url = url.replace(reg, encodeURIComponent(args[param.name]));
|
621
|
-
delete args[param.name];
|
622
|
-
} else {
|
623
|
-
throw "" + param.name + " is a required path param.";
|
624
|
-
}
|
625
|
-
}
|
626
|
-
}
|
627
|
-
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
|
628
|
-
args[this.apiKeyName] = this.resource.api.api_key;
|
629
|
-
}
|
630
|
-
if (this.supportHeaderParams()) {
|
631
|
-
queryParams = jQuery.param(this.getQueryParams(args, includeApiKey));
|
632
|
-
} else {
|
633
|
-
queryParams = jQuery.param(this.getQueryAndHeaderParams(args, includeApiKey));
|
634
|
-
}
|
635
|
-
if ((queryParams != null) && queryParams.length > 0) {
|
636
|
-
url += "?" + queryParams;
|
637
|
-
}
|
638
|
-
return url;
|
639
|
-
};
|
640
|
-
|
641
|
-
SwaggerOperation.prototype.supportHeaderParams = function() {
|
642
|
-
return this.resource.api.supportHeaderParams;
|
643
|
-
};
|
644
|
-
|
645
|
-
SwaggerOperation.prototype.supportedSubmitMethods = function() {
|
646
|
-
return this.resource.api.supportedSubmitMethods;
|
647
|
-
};
|
648
|
-
|
649
|
-
SwaggerOperation.prototype.auth_hash = function() {
|
650
|
-
return this.resource.api.auth_hash;
|
651
|
-
};
|
652
|
-
|
653
|
-
SwaggerOperation.prototype.getQueryAndHeaderParams = function(args, includeApiKey) {
|
654
|
-
if (includeApiKey == null) {
|
655
|
-
includeApiKey = true;
|
656
|
-
}
|
657
|
-
return this.getMatchingParams(['query', 'header'], args, includeApiKey);
|
658
|
-
};
|
659
|
-
|
660
|
-
SwaggerOperation.prototype.getQueryParams = function(args, includeApiKey) {
|
661
|
-
if (includeApiKey == null) {
|
662
|
-
includeApiKey = true;
|
663
|
-
}
|
664
|
-
return this.getMatchingParams(['query'], args, includeApiKey);
|
665
|
-
};
|
666
|
-
|
667
|
-
SwaggerOperation.prototype.getHeaderParams = function(args, includeApiKey) {
|
668
|
-
if (includeApiKey == null) {
|
669
|
-
includeApiKey = true;
|
670
|
-
}
|
671
|
-
return this.getMatchingParams(['header'], args, includeApiKey);
|
672
|
-
};
|
673
|
-
|
674
|
-
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
|
675
|
-
var matchingParams, name, param, value, _i, _len, _ref, _ref1;
|
676
|
-
matchingParams = {};
|
677
|
-
_ref = this.parameters;
|
678
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
679
|
-
param = _ref[_i];
|
680
|
-
if ((jQuery.inArray(param.paramType, paramTypes) >= 0) && args[param.name]) {
|
681
|
-
matchingParams[param.name] = args[param.name];
|
682
|
-
}
|
683
|
-
}
|
684
|
-
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
|
685
|
-
matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
|
686
|
-
}
|
687
|
-
if (jQuery.inArray('header', paramTypes) >= 0) {
|
688
|
-
_ref1 = this.resource.api.headers;
|
689
|
-
for (name in _ref1) {
|
690
|
-
value = _ref1[name];
|
691
|
-
matchingParams[name] = value;
|
692
|
-
}
|
693
|
-
}
|
694
|
-
return matchingParams;
|
695
|
-
};
|
696
|
-
|
697
|
-
SwaggerOperation.prototype.help = function() {
|
698
|
-
var parameter, _i, _len, _ref;
|
699
|
-
_ref = this.parameters;
|
700
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
701
|
-
parameter = _ref[_i];
|
702
|
-
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
703
|
-
}
|
704
|
-
return this;
|
705
|
-
};
|
706
|
-
|
707
|
-
return SwaggerOperation;
|
708
|
-
|
709
|
-
})();
|
710
|
-
|
711
|
-
SwaggerRequest = (function() {
|
712
|
-
|
713
|
-
function SwaggerRequest(type, url, headers, body, successCallback, errorCallback, operation) {
|
714
|
-
var obj,
|
715
|
-
_this = this;
|
716
|
-
this.type = type;
|
717
|
-
this.url = url;
|
718
|
-
this.headers = headers;
|
719
|
-
this.body = body;
|
720
|
-
this.successCallback = successCallback;
|
721
|
-
this.errorCallback = errorCallback;
|
722
|
-
this.operation = operation;
|
723
|
-
if (this.type == null) {
|
724
|
-
throw "SwaggerRequest type is required (get/post/put/delete).";
|
725
|
-
}
|
726
|
-
if (this.url == null) {
|
727
|
-
throw "SwaggerRequest url is required.";
|
728
|
-
}
|
729
|
-
if (this.successCallback == null) {
|
730
|
-
throw "SwaggerRequest successCallback is required.";
|
731
|
-
}
|
732
|
-
if (this.errorCallback == null) {
|
733
|
-
throw "SwaggerRequest error callback is required.";
|
734
|
-
}
|
735
|
-
if (this.operation == null) {
|
736
|
-
throw "SwaggerRequest operation is required.";
|
737
|
-
}
|
738
|
-
if (this.operation.resource.api.verbose) {
|
739
|
-
console.log(this.asCurl());
|
740
|
-
}
|
741
|
-
this.headers || (this.headers = {});
|
742
|
-
if (this.operation.resource.api.api_key != null) {
|
743
|
-
this.headers[this.apiKeyName] = this.operation.resource.api.api_key;
|
744
|
-
}
|
745
|
-
if (this.headers.mock == null) {
|
746
|
-
obj = {
|
747
|
-
type: this.type,
|
748
|
-
url: this.url,
|
749
|
-
data: JSON.stringify(this.body),
|
750
|
-
dataType: 'json',
|
751
|
-
error: function(xhr, textStatus, error) {
|
752
|
-
return _this.errorCallback(xhr, textStatus, error);
|
753
|
-
},
|
754
|
-
success: function(data) {
|
755
|
-
return _this.successCallback(data);
|
756
|
-
}
|
757
|
-
};
|
758
|
-
if (obj.type.toLowerCase() === "post" || obj.type.toLowerCase() === "put") {
|
759
|
-
obj.contentType = "application/json";
|
760
|
-
}
|
761
|
-
jQuery.ajax(obj);
|
762
|
-
}
|
763
|
-
}
|
764
|
-
|
765
|
-
SwaggerRequest.prototype.asCurl = function() {
|
766
|
-
var header_args, k, v;
|
767
|
-
header_args = (function() {
|
768
|
-
var _ref, _results;
|
769
|
-
_ref = this.headers;
|
770
|
-
_results = [];
|
771
|
-
for (k in _ref) {
|
772
|
-
v = _ref[k];
|
773
|
-
_results.push("--header \"" + k + ": " + v + "\"");
|
774
|
-
}
|
775
|
-
return _results;
|
776
|
-
}).call(this);
|
777
|
-
return "curl " + (header_args.join(" ")) + " " + this.url;
|
778
|
-
};
|
779
|
-
|
780
|
-
return SwaggerRequest;
|
781
|
-
|
782
|
-
})();
|
783
|
-
|
784
|
-
window.SwaggerApi = SwaggerApi;
|
785
|
-
|
786
|
-
window.SwaggerResource = SwaggerResource;
|
787
|
-
|
788
|
-
window.SwaggerOperation = SwaggerOperation;
|
789
|
-
|
790
|
-
window.SwaggerRequest = SwaggerRequest;
|
791
|
-
|
792
|
-
window.SwaggerModelProperty = SwaggerModelProperty;
|
793
|
-
|
794
|
-
}).call(this);
|