updated from master

This commit is contained in:
Tony Tam
2015-02-18 21:18:53 -08:00
parent f1263cac9b
commit 2dad51f6b1
14 changed files with 579 additions and 363 deletions

View File

@@ -19,6 +19,4 @@ WORKDIR /build
ADD package.json /build/package.json ADD package.json /build/package.json
RUN npm install RUN npm install
ADD . /build ADD . /build
CMD PATH=$PATH:node_modules/.bin cake dist CMD ./node_modules/gulp/bin/gulp.js serve
=======
CMD PATH=$PATH:node_modules/.bin cake dist

View File

@@ -1,6 +1,6 @@
# Swagger UI # Swagger UI
[![Build Status](https://travis-ci.org/swagger-api/swagger-ui.svg?branch=develop_2.0)](https://travis-ci.org/swagger-api/swagger-ui) [![Build Status](https://travis-ci.org/swagger-api/swagger-ui.svg)](https://travis-ci.org/swagger-api/swagger-ui)
Swagger UI is part of the Swagger project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way. Swagger UI is part of the Swagger project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way.
@@ -20,7 +20,7 @@ The Swagger Specification has undergone 4 revisions since initial creation in 20
Swagger UI Version | Release Date | Swagger Spec compatibility | Notes | Status Swagger UI Version | Release Date | Swagger Spec compatibility | Notes | Status
------------------ | ------------ | -------------------------- | ----- | ------ ------------------ | ------------ | -------------------------- | ----- | ------
2.1.0-M1 | 2015-01-31 | 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-ui) | 2.1.5-M1 | 2015-02-18 | 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-ui) |
2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) | 2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) |
1.0.13 | 2013-03-08 | 1.1, 1.2 | [tag v1.0.13](https://github.com/swagger-api/swagger-ui/tree/v1.0.13) | 1.0.13 | 2013-03-08 | 1.1, 1.2 | [tag v1.0.13](https://github.com/swagger-api/swagger-ui/tree/v1.0.13) |
1.0.1 | 2011-10-11 | 1.0, 1.1 | [tag v1.0.1](https://github.com/swagger-api/swagger-ui/tree/v1.0.1) | 1.0.1 | 2011-10-11 | 1.0, 1.1 | [tag v1.0.1](https://github.com/swagger-api/swagger-ui/tree/v1.0.1) |
@@ -46,20 +46,12 @@ To build swagger-ui using a docker container:
``` ```
docker build -t swagger-ui-builder . docker build -t swagger-ui-builder .
docker run -v $PWD/dist:/build/dist swagger-ui-builder docker run -p 127.0.0.1:8080:8080 swagger-ui-builder
```
### Build using Docker
To build swagger-ui using a docker container:
```
docker build -t swagger-ui-builder .
docker run -v $PWD/dist:/build/dist swagger-ui-builder
``` ```
This will start Swagger UI at `http://localhost:8080`.
### Use ### Use
Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.wordnik.com/v2/swagger.json) service and show its APIs. You can enter your own server url and click explore to view the API. Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.io/v2/swagger.json) service and show its APIs. You can enter your own server url and click explore to view the API.
### Customize ### Customize
You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories: You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories:
@@ -78,7 +70,7 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
```javascript ```javascript
window.swaggerUi = new SwaggerUi({ window.swaggerUi = new SwaggerUi({
url:"http://petstore.swagger.wordnik.com/v2/swagger.json", url:"http://petstore.swagger.io/v2/swagger.json",
dom_id:"swagger-ui-container" dom_id:"swagger-ui-container"
}); });
@@ -154,7 +146,7 @@ You can verify CORS support with one of three techniques:
- Curl your API and inspect the headers. For instance: - Curl your API and inspect the headers. For instance:
```bash ```bash
$ curl -I "http://petstore.swagger.wordnik.com/v2/swagger.json" $ curl -I "http://petstore.swagger.io/v2/swagger.json"
HTTP/1.1 200 OK HTTP/1.1 200 OK
Date: Sat, 31 Jan 2015 23:05:44 GMT Date: Sat, 31 Jan 2015 23:05:44 GMT
Access-Control-Allow-Origin: * Access-Control-Allow-Origin: *

View File

@@ -1,6 +1,6 @@
/** /**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.0-alpha.7 * @version v2.1.5-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -31,7 +31,13 @@ ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
} }
else if (this.ref) { else if (this.ref) {
var name = simpleRef(this.ref); var name = simpleRef(this.ref);
result = models[name].createJSONSample(); if(typeof modelsToIgnore[name] === 'undefined') {
modelsToIgnore[name] = this;
result = models[name].createJSONSample(modelsToIgnore);
}
else {
return name;
}
} }
return [ result ]; return [ result ];
}; };
@@ -51,10 +57,31 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var propertiesStr = [];
var i, prop;
if(this.ref) { for (i = 0; i < this.properties.length; i++) {
return models[simpleRef(this.ref)].getMockSignature(); prop = this.properties[i];
propertiesStr.push(prop.toString());
} }
var strong = '<span class="strong">';
var stronger = '<span class="stronger">';
var strongClose = '</span>';
var classOpen = strong + 'array' + ' {' + strongClose;
var classClose = strong + '}' + strongClose;
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
if (!modelsToIgnore)
modelsToIgnore = {};
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
var ref = prop.$ref;
var model = models[ref];
if (model && typeof modelsToIgnore[ref] === 'undefined') {
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
}
}
return returnVal;
}; };
@@ -76,10 +103,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) { SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
var status = null; var status = null;
var key, value, result; var key, name, value, result;
// if the "authorizations" key is undefined, or has an empty array, add all keys // if the "authorizations" key is undefined, or has an empty array, add all keys
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) { if (typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
for (key in this.authz) { for (key in this.authz) {
value = this.authz[key]; value = this.authz[key];
result = value.apply(obj, authorizations); result = value.apply(obj, authorizations);
@@ -90,6 +117,7 @@ SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
else { else {
// 2.0 support // 2.0 support
if (Array.isArray(authorizations)) { if (Array.isArray(authorizations)) {
for (var i = 0; i < authorizations.length; i++) { for (var i = 0; i < authorizations.length; i++) {
var auth = authorizations[i]; var auth = authorizations[i];
for (name in auth) { for (name in auth) {
@@ -273,6 +301,10 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) {
} }
return returnVal; return returnVal;
}; };
var addModel = function(name, model) {
models[name] = model;
};
var SwaggerClient = function(url, options) { var SwaggerClient = function(url, options) {
this.isBuilt = false; this.isBuilt = false;
this.url = null; this.url = null;
@@ -284,13 +316,14 @@ var SwaggerClient = function(url, options) {
this.isValid = false; this.isValid = false;
this.info = null; this.info = null;
this.useJQuery = false; this.useJQuery = false;
this.resourceCount = 0;
if(typeof url !== 'undefined') if(typeof url !== 'undefined')
return this.initialize(url, options); return this.initialize(url, options);
}; };
SwaggerClient.prototype.initialize = function (url, options) { SwaggerClient.prototype.initialize = function (url, options) {
this.models = models; this.models = models = {};
options = (options||{}); options = (options||{});
@@ -324,6 +357,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
this.options = options; this.options = options;
if (typeof options.success === 'function') { if (typeof options.success === 'function') {
this.ready = true;
this.build(); this.build();
} }
}; };
@@ -379,7 +413,6 @@ SwaggerClient.prototype.build = function(mock) {
return obj; return obj;
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj);
} }
return this; return this;
}; };
@@ -400,8 +433,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
// legacy support // legacy support
this.authSchemes = response.securityDefinitions; this.authSchemes = response.securityDefinitions;
var location; var definedTags = {};
if(Array.isArray(response.tags)) {
definedTags = {};
for(k = 0; k < response.tags.length; k++) {
var t = response.tags[k];
definedTags[t.name] = t;
}
}
var location;
if(typeof this.url === 'string') { if(typeof this.url === 'string') {
location = this.parseUri(this.url); location = this.parseUri(this.url);
} }
@@ -467,8 +508,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
operationGroup.operations = {}; operationGroup.operations = {};
operationGroup.label = tag; operationGroup.label = tag;
operationGroup.apis = []; operationGroup.apis = [];
var tagObject = definedTags[tag];
if(typeof tagObject === 'object') {
operationGroup.description = tagObject.description;
operationGroup.externalDocs = tagObject.externalDocs;
}
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationObject)); this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
} }
operationGroup[operationId] = operationObject.execute.bind(operationObject); operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -495,8 +541,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
} }
} }
this.isBuilt = true; this.isBuilt = true;
if (this.success) if (this.success) {
this.isValid = true;
this.isBuilt = true;
this.success(); this.success();
}
return this; return this;
}; };
@@ -534,14 +583,14 @@ SwaggerClient.prototype.fail = function(message) {
throw message; throw message;
}; };
var OperationGroup = function(tag, operation) { var OperationGroup = function(tag, description, externalDocs, operation) {
this.tag = tag; this.tag = tag;
this.path = tag; this.path = tag;
this.description = description;
this.externalDocs = externalDocs;
this.name = tag; this.name = tag;
this.operation = operation; this.operation = operation;
this.operationsArray = []; this.operationsArray = [];
this.description = operation.description || "";
}; };
var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) {
@@ -571,18 +620,32 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
this.description = args.description; this.description = args.description;
this.useJQuery = parent.useJQuery; this.useJQuery = parent.useJQuery;
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}
var i, model;
if(definitions) { if(definitions) {
// add to global models // add to global models
var key; var key;
for(key in this.definitions) { for(key in this.definitions) {
var model = new Model(key, definitions[key]); model = new Model(key, definitions[key]);
if(model) { if(model) {
models[key] = model; models[key] = model;
} }
} }
} }
var i;
for(i = 0; i < this.parameters.length; i++) { for(i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i]; var param = this.parameters[i];
if(param.type === 'array') { if(param.type === 'array') {
@@ -607,17 +670,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
} }
} }
if(param.type === 'array' && typeof param.allowableValues === 'undefined') { if(param.type === 'array') {
// can't show as a list if no values to select from innerType = [innerType];
delete param.isList; if(typeof param.allowableValues === 'undefined') {
delete param.allowMultiple; // can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
}
} }
param.signature = this.getModelSignature(innerType, models); param.signature = this.getModelSignature(innerType, models).toString();
param.sampleJSON = this.getModelSampleJSON(innerType, models); param.sampleJSON = this.getModelSampleJSON(innerType, models);
param.responseClassSignature = param.signature; param.responseClassSignature = param.signature;
} }
var defaultResponseCode, response, model, responses = this.responses; var defaultResponseCode, response, responses = this.responses;
if(responses['200']) { if(responses['200']) {
response = responses['200']; response = responses['200'];
@@ -689,10 +755,14 @@ Operation.prototype.getType = function (param) {
str = 'long'; str = 'long';
else if(type === 'integer') else if(type === 'integer')
str = 'integer'; str = 'integer';
else if(type === 'string' && format === 'date-time') else if(type === 'string') {
str = 'date-time'; if(format === 'date-time')
else if(type === 'string' && format === 'date') str = 'date-time';
str = 'date'; else if(format === 'date')
str = 'date';
else
str = 'string';
}
else if(type === 'number' && format === 'float') else if(type === 'number' && format === 'float')
str = 'float'; str = 'float';
else if(type === 'number' && format === 'double') else if(type === 'number' && format === 'double')
@@ -701,8 +771,6 @@ Operation.prototype.getType = function (param) {
str = 'double'; str = 'double';
else if(type === 'boolean') else if(type === 'boolean')
str = 'boolean'; str = 'boolean';
else if(type === 'string')
str = 'string';
else if(type === 'array') { else if(type === 'array') {
isArray = true; isArray = true;
if(param.items) if(param.items)
@@ -764,16 +832,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true; listType = true;
type = type[0]; type = type[0];
} }
else if(typeof type === 'undefined')
type = 'undefined';
if(type === 'string') if(type === 'string')
isPrimitive = true; isPrimitive = true;
else else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return type; if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else { } else {
if (listType) if (listType)
return definitions[type].getMockSignature(); return 'Array[' + definitions[type].getMockSignature() + ']';
else else
return definitions[type].getMockSignature(); return definitions[type].getMockSignature();
} }
@@ -795,9 +868,7 @@ Operation.prototype.getHeaderParams = function (args) {
if (param.in === 'header') { if (param.in === 'header') {
var value = args[param.name]; var value = args[param.name];
if(Array.isArray(value)) if(Array.isArray(value))
value = this.encodePathCollection(param.collectionFormat, param.name, value); value = value.toString();
else
value = this.encodePathParam(value);
headers[param.name] = value; headers[param.name] = value;
} }
} }
@@ -965,8 +1036,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
fail(message); fail(message);
return; return;
} }
var headers = this.getHeaderParams(args); var allHeaders = this.getHeaderParams(args);
headers = this.setContentTypes(args, opts); var contentTypeHeaders = this.setContentTypes(args, opts);
var headers = {}, attrname;
for (attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
for (attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
var body = this.getBody(headers, args); var body = this.getBody(headers, args);
var url = this.urlify(args); var url = this.urlify(args);
@@ -989,14 +1065,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
if(opts.mock === true) if(opts.mock === true)
return obj; return obj;
else else
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj, opts);
}; };
Operation.prototype.setContentTypes = function(args, opts) { Operation.prototype.setContentTypes = function(args, opts) {
// default type // default type
var accepts = 'application/json'; var accepts = 'application/json';
var consumes = args.parameterContentType || 'application/json'; var consumes = args.parameterContentType || 'application/json';
var allDefinedParams = this.parameters; var allDefinedParams = this.parameters;
var definedFormParams = []; var definedFormParams = [];
var definedFileParams = []; var definedFileParams = [];
@@ -1013,10 +1088,10 @@ Operation.prototype.setContentTypes = function(args, opts) {
else else
definedFormParams.push(param); definedFormParams.push(param);
} }
else if(param.in === 'header' && this.headers) { else if(param.in === 'header' && opts) {
var key = param.name; var key = param.name;
var headerValue = this.headers[param.name]; var headerValue = opts[param.name];
if(typeof this.headers[param.name] !== 'undefined') if(typeof opts[param.name] !== 'undefined')
headers[key] = headerValue; headers[key] = headerValue;
} }
else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { else if(param.in === 'body' && typeof args[param.name] !== 'undefined') {
@@ -1184,21 +1259,20 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var result = {}; var i, result = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
var i;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
result[prop.name] = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore);
result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
return result; return result;
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i; var i, obj = {};
var obj = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore);
@@ -1207,8 +1281,7 @@ Model.prototype.getSampleValue = function(modelsToIgnore) {
}; };
Model.prototype.getMockSignature = function(modelsToIgnore) { Model.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var i, prop, propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
propertiesStr.push(prop.toString()); propertiesStr.push(prop.toString());
@@ -1251,7 +1324,7 @@ var Property = function(name, obj, required) {
this.optional = true; this.optional = true;
this.optional = !required; this.optional = !required;
this.default = obj.default || null; this.default = obj.default || null;
this.example = obj.example || null; this.example = obj.example !== undefined ? obj.example : null;
this.collectionFormat = obj.collectionFormat || null; this.collectionFormat = obj.collectionFormat || null;
this.maximum = obj.maximum || null; this.maximum = obj.maximum || null;
this.exclusiveMaximum = obj.exclusiveMaximum || null; this.exclusiveMaximum = obj.exclusiveMaximum || null;
@@ -1282,7 +1355,7 @@ Property.prototype.isArray = function () {
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
var type = getStringSignature(this.obj); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
@@ -1292,8 +1365,9 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels);
} }
else else {
type = refModel; output = refModelName;
}
} }
else if(this.example) else if(this.example)
output = this.example; output = this.example;
@@ -1301,6 +1375,8 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
output = this.default; output = this.default;
else if(type === 'date-time') else if(type === 'date-time')
output = new Date().toISOString(); output = new Date().toISOString();
else if(type === 'date')
output = new Date().toISOString().split("T")[0];
else if(type === 'string') else if(type === 'string')
output = 'string'; output = 'string';
else if(type === 'integer') else if(type === 'integer')
@@ -1322,16 +1398,20 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
return output; return output;
}; };
getStringSignature = function(obj) { getStringSignature = function(obj, baseComponent) {
var str = ''; var str = '';
if(typeof obj.$ref !== 'undefined') if(typeof obj.$ref !== 'undefined')
str += simpleRef(obj.$ref); str += simpleRef(obj.$ref);
else if(typeof obj.type === 'undefined') else if(typeof obj.type === 'undefined')
str += 'object'; str += 'object';
else if(obj.type === 'array') { else if(obj.type === 'array') {
str += 'Array['; if(baseComponent)
str += getStringSignature((obj.items || obj.$ref || {})); str += getStringSignature((obj.items || obj.$ref || {}));
str += ']'; else {
str += 'Array[';
str += getStringSignature((obj.items || obj.$ref || {}));
str += ']';
}
} }
else if(obj.type === 'integer' && obj.format === 'int32') else if(obj.type === 'integer' && obj.format === 'int32')
str += 'integer'; str += 'integer';
@@ -1402,7 +1482,7 @@ Property.prototype.toString = function() {
type = ''; type = '';
} }
else { else {
this.schema.type; type = this.schema.type;
} }
if (this.default) if (this.default)
@@ -1463,7 +1543,7 @@ Property.prototype.toString = function() {
optionHtml = function(label, value) { optionHtml = function(label, value) {
return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>'; return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
} };
typeFromJsonSchema = function(type, format) { typeFromJsonSchema = function(type, format) {
var str; var str;
@@ -1496,7 +1576,7 @@ var cookies = {};
var models = {}; var models = {};
SwaggerClient.prototype.buildFrom1_2Spec = function (response) { SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
if (response.apiVersion != null) { if (response.apiVersion !== null) {
this.apiVersion = response.apiVersion; this.apiVersion = response.apiVersion;
} }
this.apis = {}; this.apis = {};
@@ -1532,6 +1612,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
this.apisArray.push(res); this.apisArray.push(res);
} else { } else {
var k; var k;
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) { for (k = 0; k < response.apis.length; k++) {
var resource = response.apis[k]; var resource = response.apis[k];
res = new SwaggerResource(resource, this); res = new SwaggerResource(resource, this);
@@ -1540,15 +1621,22 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
} }
} }
this.isValid = true; this.isValid = true;
if (typeof this.success === 'function') {
this.success();
}
return this; return this;
}; };
SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
this.isValid = true;
this.ready = true;
this.isBuilt = true;
this.selfReflect();
this.success();
}
};
SwaggerClient.prototype.buildFrom1_1Spec = function (response) { SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info'); log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info');
if (response.apiVersion != null) if (response.apiVersion !== null)
this.apiVersion = response.apiVersion; this.apiVersion = response.apiVersion;
this.apis = {}; this.apis = {};
this.apisArray = []; this.apisArray = [];
@@ -1594,7 +1682,7 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
SwaggerClient.prototype.convertInfo = function (resp) { SwaggerClient.prototype.convertInfo = function (resp) {
if(typeof resp == 'object') { if(typeof resp == 'object') {
var info = {} var info = {};
info.title = resp.title; info.title = resp.title;
info.description = resp.description; info.description = resp.description;
@@ -1623,9 +1711,6 @@ SwaggerClient.prototype.selfReflect = function () {
} }
this.setConsolidatedModels(); this.setConsolidatedModels();
this.ready = true; this.ready = true;
if (typeof this.success === 'function') {
return this.success();
}
}; };
SwaggerClient.prototype.setConsolidatedModels = function () { SwaggerClient.prototype.setConsolidatedModels = function () {
@@ -1658,13 +1743,14 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description; this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {}); this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/'); var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', ''); this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath; this.basePath = this.api.basePath;
this.operations = {}; this.operations = {};
this.operationsArray = []; this.operationsArray = [];
this.modelsArray = []; this.modelsArray = [];
this.models = {}; this.models = api.models || {};
this.rawModels = {}; this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null; this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null;
@@ -1690,9 +1776,11 @@ var SwaggerResource = function (resourceObj, api) {
on: { on: {
response: function (resp) { response: function (resp) {
var responseObj = resp.obj || JSON.parse(resp.data); var responseObj = resp.obj || JSON.parse(resp.data);
_this.api.resourceCount += 1;
return _this.addApiDeclaration(responseObj); return _this.addApiDeclaration(responseObj);
}, },
error: function (response) { error: function (response) {
_this.api.resourceCount += 1;
return _this.api.fail('Unable to read api \'' + return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')'); _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
} }
@@ -1736,7 +1824,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
this.consumes = response.consumes; this.consumes = response.consumes;
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0) if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath; this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
this.resourcePath = response.resourcePath;
this.addModels(response.models); this.addModels(response.models);
if (response.apis) { if (response.apis) {
for (var i = 0 ; i < response.apis.length; i++) { for (var i = 0 ; i < response.apis.length; i++) {
@@ -1746,7 +1834,9 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
} }
this.api[this.name] = this; this.api[this.name] = this;
this.ready = true; this.ready = true;
return this.api.selfReflect(); if(this.api.resourceCount === this.api.expectedResourceCount)
this.api.finish();
return this;
}; };
SwaggerResource.prototype.addModels = function (models) { SwaggerResource.prototype.addModels = function (models) {
@@ -2015,9 +2105,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.consumes = consumes; this.consumes = consumes;
this.produces = produces; this.produces = produces;
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations; this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated); this.deprecated = deprecated;
this['do'] = __bind(this['do'], this); this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}
if (errors.length > 0) { if (errors.length > 0) {
console.error('SwaggerOperation errors', errors, arguments); console.error('SwaggerOperation errors', errors, arguments);
this.resource.api.fail(errors); this.resource.api.fail(errors);
@@ -2025,7 +2129,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.path = this.path.replace('{format}', 'json'); this.path = this.path.replace('{format}', 'json');
this.method = this.method.toLowerCase(); this.method = this.method.toLowerCase();
this.isGetMethod = this.method === 'GET'; this.isGetMethod = this.method === 'get';
var i, j, v; var i, j, v;
this.resourceName = this.resource.name; this.resourceName = this.resource.name;
@@ -2076,17 +2180,17 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
} }
} }
} }
else if (param.allowableValues != null) { else if (param.allowableValues) {
if (param.allowableValues.valueType === 'RANGE') if (param.allowableValues.valueType === 'RANGE')
param.isRange = true; param.isRange = true;
else else
param.isList = true; param.isList = true;
if (param.allowableValues != null) { if (param.allowableValues) {
param.allowableValues.descriptiveValues = []; param.allowableValues.descriptiveValues = [];
if (param.allowableValues.values) { if (param.allowableValues.values) {
for (j = 0; j < param.allowableValues.values.length; j++) { for (j = 0; j < param.allowableValues.values.length; j++) {
v = param.allowableValues.values[j]; v = param.allowableValues.values[j];
if (param.defaultValue != null) { if (param.defaultValue !== null) {
param.allowableValues.descriptiveValues.push({ param.allowableValues.descriptiveValues.push({
value: String(v), value: String(v),
isDefault: (v === param.defaultValue) isDefault: (v === param.defaultValue)
@@ -2156,7 +2260,7 @@ SwaggerOperation.prototype.getSampleJSON = function (type, models) {
var isPrimitive, listType, val; var isPrimitive, listType, val;
listType = this.isListType(type); listType = this.isListType(type);
isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true; isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true;
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample()); val = isPrimitive ? void 0 : (listType ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) { if (val) {
val = listType ? [val] : val; val = listType ? [val] : val;
if (typeof val == 'string') if (typeof val == 'string')
@@ -2191,7 +2295,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
callback = function (response) { callback = function (response) {
var content; var content;
content = null; content = null;
if (response != null) { if (response !== null) {
content = response.data; content = response.data;
} else { } else {
content = 'no data'; content = 'no data';
@@ -2202,7 +2306,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
params = {}; params = {};
params.headers = []; params.headers = [];
if (args.headers != null) { if (args.headers) {
params.headers = args.headers; params.headers = args.headers;
delete args.headers; delete args.headers;
} }
@@ -2289,7 +2393,7 @@ SwaggerOperation.prototype.urlify = function (args) {
if (param.paramType === 'path') { if (param.paramType === 'path') {
if (typeof args[param.name] !== 'undefined') { if (typeof args[param.name] !== 'undefined') {
// apply path params and remove from args // apply path params and remove from args
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi'); var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
url = url.replace(reg, this.encodePathParam(args[param.name])); url = url.replace(reg, this.encodePathParam(args[param.name]));
delete args[param.name]; delete args[param.name];
} }
@@ -2323,7 +2427,7 @@ SwaggerOperation.prototype.urlify = function (args) {
} }
} }
} }
if ((queryParams != null) && queryParams.length > 0) if ((queryParams) && queryParams.length > 0)
url += '?' + queryParams; url += '?' + queryParams;
return url; return url;
}; };
@@ -2532,7 +2636,7 @@ var SwaggerRequest = function (type, url, params, opts, successCallback, errorCa
} }
var obj; var obj;
if (!((this.headers != null) && (this.headers.mock != null))) { if (!((this.headers) && (this.headers.mock))) {
obj = { obj = {
url: this.url, url: this.url,
method: this.type, method: this.type,
@@ -2657,7 +2761,7 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) {
*/ */
var SwaggerHttp = function() {}; var SwaggerHttp = function() {};
SwaggerHttp.prototype.execute = function(obj) { SwaggerHttp.prototype.execute = function(obj, opts) {
if(obj && (typeof obj.useJQuery === 'boolean')) if(obj && (typeof obj.useJQuery === 'boolean'))
this.useJQuery = obj.useJQuery; this.useJQuery = obj.useJQuery;
else else
@@ -2668,9 +2772,9 @@ SwaggerHttp.prototype.execute = function(obj) {
} }
if(this.useJQuery) if(this.useJQuery)
return new JQueryHttpClient().execute(obj); return new JQueryHttpClient(opts).execute(obj);
else else
return new ShredHttpClient().execute(obj); return new ShredHttpClient(opts).execute(obj);
}; };
SwaggerHttp.prototype.isIE8 = function() { SwaggerHttp.prototype.isIE8 = function() {
@@ -2755,7 +2859,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
if(contentType) { if(contentType) {
if(contentType.indexOf("application/json") === 0 || contentType.indexOf("+json") > 0) { if(contentType.indexOf("application/json") === 0 || contentType.indexOf("+json") > 0) {
try { try {
out.obj = response.responseJSON || {}; out.obj = response.responseJSON || JSON.parse(out.data) || {};
} catch (ex) { } catch (ex) {
// do not set out.obj // do not set out.obj
log("unable to parse JSON content"); log("unable to parse JSON content");
@@ -2778,8 +2882,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
/* /*
* ShredHttpClient is a light-weight, node or browser HTTP client * ShredHttpClient is a light-weight, node or browser HTTP client
*/ */
var ShredHttpClient = function(options) { var ShredHttpClient = function(opts) {
this.options = (options||{}); this.opts = (opts||{});
this.isInitialized = false; this.isInitialized = false;
var identity, toString; var identity, toString;
@@ -2790,7 +2894,7 @@ var ShredHttpClient = function(options) {
} }
else else
this.Shred = require("shred"); this.Shred = require("shred");
this.shred = new this.Shred(options); this.shred = new this.Shred(opts);
}; };
ShredHttpClient.prototype.initShred = function () { ShredHttpClient.prototype.initShred = function () {
@@ -2901,7 +3005,9 @@ e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization; e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization; e.CookieAuthorization = CookieAuthorization;
e.SwaggerClient = SwaggerClient; e.SwaggerClient = SwaggerClient;
e.SwaggerApi = SwaggerClient;
e.Operation = Operation; e.Operation = Operation;
e.Model = Model; e.Model = Model;
e.models = models; e.addModel = addModel;
})(); })();

View File

@@ -14,8 +14,8 @@ function handleLogin() {
var defs = auths; var defs = auths;
for(key in defs) { for(key in defs) {
var auth = defs[key]; var auth = defs[key];
oauth2KeyName = key;
if(auth.type === 'oauth2' && auth.scopes) { if(auth.type === 'oauth2' && auth.scopes) {
oauth2KeyName = key;
var scope; var scope;
if(Array.isArray(auth.scopes)) { if(Array.isArray(auth.scopes)) {
// 1.2 support // 1.2 support

278
dist/swagger-ui.js vendored
View File

@@ -393,27 +393,6 @@ Handlebars.registerHelper('sanitize', function(html) {
this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n"; return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"2":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, buffer = " <option value=\"";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"contentType\"></label>\n<select name=\"contentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true});
var ApiKeyButton, var ApiKeyButton,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@@ -467,6 +446,82 @@ ApiKeyButton = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"2":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, buffer = " <option value=\"";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"contentType\"></label>\n<select name=\"contentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true});
var BasicAuthButton,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty;
BasicAuthButton = (function(_super) {
__extends(BasicAuthButton, _super);
function BasicAuthButton() {
return BasicAuthButton.__super__.constructor.apply(this, arguments);
}
BasicAuthButton.prototype.initialize = function() {};
BasicAuthButton.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
return this;
};
BasicAuthButton.prototype.events = {
"click #basic_auth_button": "togglePasswordContainer",
"click #apply_basic_auth": "applyPassword"
};
BasicAuthButton.prototype.applyPassword = function() {
var elem, password, username;
username = $(".input_username").val();
password = $(".input_password").val();
window.authorizations.add(this.model.type, new PasswordAuthorization("basic", username, password));
window.swaggerUi.load();
return elem = $('#basic_auth_container').hide();
};
BasicAuthButton.prototype.togglePasswordContainer = function() {
var elem;
if ($('#basic_auth_container').length > 0) {
elem = $('#basic_auth_container').show();
if (elem.is(':visible')) {
return elem.slideUp();
} else {
$('.auth_container').hide();
return elem.show();
}
}
};
BasicAuthButton.prototype.template = function() {
return Handlebars.templates.basic_auth_button_view;
};
return BasicAuthButton;
})(Backbone.View);
this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">" var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">"
+ escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0)) + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0))
@@ -550,61 +605,6 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + " </h4>\n </div>\n</div>\n"; return buffer + " </h4>\n </div>\n</div>\n";
},"useData":true}); },"useData":true});
var BasicAuthButton,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty;
BasicAuthButton = (function(_super) {
__extends(BasicAuthButton, _super);
function BasicAuthButton() {
return BasicAuthButton.__super__.constructor.apply(this, arguments);
}
BasicAuthButton.prototype.initialize = function() {};
BasicAuthButton.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
return this;
};
BasicAuthButton.prototype.events = {
"click #basic_auth_button": "togglePasswordContainer",
"click #apply_basic_auth": "applyPassword"
};
BasicAuthButton.prototype.applyPassword = function() {
var elem, password, username;
username = $(".input_username").val();
password = $(".input_password").val();
window.authorizations.add(this.model.type, new PasswordAuthorization("basic", username, password));
window.swaggerUi.load();
return elem = $('#basic_auth_container').hide();
};
BasicAuthButton.prototype.togglePasswordContainer = function() {
var elem;
if ($('#basic_auth_container').length > 0) {
elem = $('#basic_auth_container').show();
if (elem.is(':visible')) {
return elem.slideUp();
} else {
$('.auth_container').hide();
return elem.show();
}
}
};
BasicAuthButton.prototype.template = function() {
return Handlebars.templates.basic_auth_button_view;
};
return BasicAuthButton;
})(Backbone.View);
var ContentTypeView, var ContentTypeView,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@@ -1034,6 +1034,39 @@ this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":functio
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>"; return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' name='"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "'>"
+ escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ "</textarea>\n";
},"3":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"4":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " "
+ escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ "\n";
},"6":function(depth0,helpers,partials,data) {
return " (empty)\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code'>"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "</td>\n<td>\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data});
if (stack1 != null) { buffer += stack1; }
buffer += "</td>\n<td class=\"markdown\">";
stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
buffer += "</td>\n<td>";
stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
},"useData":true});
var OperationView, var OperationView,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@@ -1645,9 +1678,9 @@ OperationView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' name='" return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "'>" + "'>"
+ escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
@@ -1665,7 +1698,7 @@ this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":fun
},"6":function(depth0,helpers,partials,data) { },"6":function(depth0,helpers,partials,data) {
return " (empty)\n"; return " (empty)\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code'>" var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code required'>"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "</td>\n<td>\n"; + "</td>\n<td>\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}); stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data});
@@ -1707,39 +1740,6 @@ ParameterContentTypeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "'>"
+ escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ "</textarea>\n";
},"3":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"4":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " "
+ escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper)))
+ "\n";
},"6":function(depth0,helpers,partials,data) {
return " (empty)\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td class='code required'>"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
+ "</td>\n<td>\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data});
if (stack1 != null) { buffer += stack1; }
buffer += "</td>\n<td class=\"markdown\">";
stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
buffer += "</td>\n<td>";
stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
},"useData":true});
var ParameterView, var ParameterView,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@@ -2076,6 +2076,27 @@ this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(
+ escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ "_endpoint_list' style='display:none'>\n\n</ul>\n"; + "_endpoint_list' style='display:none'>\n\n</ul>\n";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"2":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, buffer = " <option value=\"";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true});
var SignatureView, var SignatureView,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty; __hasProp = {}.hasOwnProperty;
@@ -2148,26 +2169,13 @@ SignatureView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n ";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer; return buffer + "\n </div>\n\n <div class=\"snippet\">\n <pre><code>"
},"2":function(depth0,helpers,partials,data) { + escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
var stack1, lambda=this.lambda, buffer = " <option value=\""; + "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true}); },"useData":true});
var StatusCodeView, var StatusCodeView,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
@@ -2211,14 +2219,6 @@ StatusCodeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n ";
stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </div>\n\n <div class=\"snippet\">\n <pre><code>"
+ escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
},"useData":true});
this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>" var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>"
+ escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper)))

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
/** /**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.0-alpha.7 * @version v2.1.5-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -31,7 +31,13 @@ ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
} }
else if (this.ref) { else if (this.ref) {
var name = simpleRef(this.ref); var name = simpleRef(this.ref);
result = models[name].createJSONSample(); if(typeof modelsToIgnore[name] === 'undefined') {
modelsToIgnore[name] = this;
result = models[name].createJSONSample(modelsToIgnore);
}
else {
return name;
}
} }
return [ result ]; return [ result ];
}; };
@@ -51,10 +57,31 @@ ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var propertiesStr = [];
var i, prop;
if(this.ref) { for (i = 0; i < this.properties.length; i++) {
return models[simpleRef(this.ref)].getMockSignature(); prop = this.properties[i];
propertiesStr.push(prop.toString());
} }
var strong = '<span class="strong">';
var stronger = '<span class="stronger">';
var strongClose = '</span>';
var classOpen = strong + 'array' + ' {' + strongClose;
var classClose = strong + '}' + strongClose;
var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
if (!modelsToIgnore)
modelsToIgnore = {};
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
var ref = prop.$ref;
var model = models[ref];
if (model && typeof modelsToIgnore[ref] === 'undefined') {
returnVal = returnVal + ('<br>' + model.getMockSignature(modelsToIgnore));
}
}
return returnVal;
}; };
@@ -76,10 +103,10 @@ SwaggerAuthorizations.prototype.remove = function(name) {
SwaggerAuthorizations.prototype.apply = function (obj, authorizations) { SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
var status = null; var status = null;
var key, value, result; var key, name, value, result;
// if the "authorizations" key is undefined, or has an empty array, add all keys // if the "authorizations" key is undefined, or has an empty array, add all keys
if (typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) { if (typeof authorizations === 'undefined' || Object.keys(authorizations).length === 0) {
for (key in this.authz) { for (key in this.authz) {
value = this.authz[key]; value = this.authz[key];
result = value.apply(obj, authorizations); result = value.apply(obj, authorizations);
@@ -90,6 +117,7 @@ SwaggerAuthorizations.prototype.apply = function (obj, authorizations) {
else { else {
// 2.0 support // 2.0 support
if (Array.isArray(authorizations)) { if (Array.isArray(authorizations)) {
for (var i = 0; i < authorizations.length; i++) { for (var i = 0; i < authorizations.length; i++) {
var auth = authorizations[i]; var auth = authorizations[i];
for (name in auth) { for (name in auth) {
@@ -273,6 +301,10 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) {
} }
return returnVal; return returnVal;
}; };
var addModel = function(name, model) {
models[name] = model;
};
var SwaggerClient = function(url, options) { var SwaggerClient = function(url, options) {
this.isBuilt = false; this.isBuilt = false;
this.url = null; this.url = null;
@@ -284,13 +316,14 @@ var SwaggerClient = function(url, options) {
this.isValid = false; this.isValid = false;
this.info = null; this.info = null;
this.useJQuery = false; this.useJQuery = false;
this.resourceCount = 0;
if(typeof url !== 'undefined') if(typeof url !== 'undefined')
return this.initialize(url, options); return this.initialize(url, options);
}; };
SwaggerClient.prototype.initialize = function (url, options) { SwaggerClient.prototype.initialize = function (url, options) {
this.models = models; this.models = models = {};
options = (options||{}); options = (options||{});
@@ -324,6 +357,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
this.options = options; this.options = options;
if (typeof options.success === 'function') { if (typeof options.success === 'function') {
this.ready = true;
this.build(); this.build();
} }
}; };
@@ -379,7 +413,6 @@ SwaggerClient.prototype.build = function(mock) {
return obj; return obj;
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj);
} }
return this; return this;
}; };
@@ -400,8 +433,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
// legacy support // legacy support
this.authSchemes = response.securityDefinitions; this.authSchemes = response.securityDefinitions;
var location; var definedTags = {};
if(Array.isArray(response.tags)) {
definedTags = {};
for(k = 0; k < response.tags.length; k++) {
var t = response.tags[k];
definedTags[t.name] = t;
}
}
var location;
if(typeof this.url === 'string') { if(typeof this.url === 'string') {
location = this.parseUri(this.url); location = this.parseUri(this.url);
} }
@@ -467,8 +508,13 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
operationGroup.operations = {}; operationGroup.operations = {};
operationGroup.label = tag; operationGroup.label = tag;
operationGroup.apis = []; operationGroup.apis = [];
var tagObject = definedTags[tag];
if(typeof tagObject === 'object') {
operationGroup.description = tagObject.description;
operationGroup.externalDocs = tagObject.externalDocs;
}
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationObject)); this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
} }
operationGroup[operationId] = operationObject.execute.bind(operationObject); operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
@@ -495,8 +541,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
} }
} }
this.isBuilt = true; this.isBuilt = true;
if (this.success) if (this.success) {
this.isValid = true;
this.isBuilt = true;
this.success(); this.success();
}
return this; return this;
}; };
@@ -534,14 +583,14 @@ SwaggerClient.prototype.fail = function(message) {
throw message; throw message;
}; };
var OperationGroup = function(tag, operation) { var OperationGroup = function(tag, description, externalDocs, operation) {
this.tag = tag; this.tag = tag;
this.path = tag; this.path = tag;
this.description = description;
this.externalDocs = externalDocs;
this.name = tag; this.name = tag;
this.operation = operation; this.operation = operation;
this.operationsArray = []; this.operationsArray = [];
this.description = operation.description || "";
}; };
var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) {
@@ -571,18 +620,32 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
this.description = args.description; this.description = args.description;
this.useJQuery = parent.useJQuery; this.useJQuery = parent.useJQuery;
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}
var i, model;
if(definitions) { if(definitions) {
// add to global models // add to global models
var key; var key;
for(key in this.definitions) { for(key in this.definitions) {
var model = new Model(key, definitions[key]); model = new Model(key, definitions[key]);
if(model) { if(model) {
models[key] = model; models[key] = model;
} }
} }
} }
var i;
for(i = 0; i < this.parameters.length; i++) { for(i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i]; var param = this.parameters[i];
if(param.type === 'array') { if(param.type === 'array') {
@@ -607,17 +670,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault});
} }
} }
if(param.type === 'array' && typeof param.allowableValues === 'undefined') { if(param.type === 'array') {
// can't show as a list if no values to select from innerType = [innerType];
delete param.isList; if(typeof param.allowableValues === 'undefined') {
delete param.allowMultiple; // can't show as a list if no values to select from
delete param.isList;
delete param.allowMultiple;
}
} }
param.signature = this.getModelSignature(innerType, models); param.signature = this.getModelSignature(innerType, models).toString();
param.sampleJSON = this.getModelSampleJSON(innerType, models); param.sampleJSON = this.getModelSampleJSON(innerType, models);
param.responseClassSignature = param.signature; param.responseClassSignature = param.signature;
} }
var defaultResponseCode, response, model, responses = this.responses; var defaultResponseCode, response, responses = this.responses;
if(responses['200']) { if(responses['200']) {
response = responses['200']; response = responses['200'];
@@ -689,10 +755,14 @@ Operation.prototype.getType = function (param) {
str = 'long'; str = 'long';
else if(type === 'integer') else if(type === 'integer')
str = 'integer'; str = 'integer';
else if(type === 'string' && format === 'date-time') else if(type === 'string') {
str = 'date-time'; if(format === 'date-time')
else if(type === 'string' && format === 'date') str = 'date-time';
str = 'date'; else if(format === 'date')
str = 'date';
else
str = 'string';
}
else if(type === 'number' && format === 'float') else if(type === 'number' && format === 'float')
str = 'float'; str = 'float';
else if(type === 'number' && format === 'double') else if(type === 'number' && format === 'double')
@@ -701,8 +771,6 @@ Operation.prototype.getType = function (param) {
str = 'double'; str = 'double';
else if(type === 'boolean') else if(type === 'boolean')
str = 'boolean'; str = 'boolean';
else if(type === 'string')
str = 'string';
else if(type === 'array') { else if(type === 'array') {
isArray = true; isArray = true;
if(param.items) if(param.items)
@@ -764,16 +832,21 @@ Operation.prototype.getModelSignature = function(type, definitions) {
listType = true; listType = true;
type = type[0]; type = type[0];
} }
else if(typeof type === 'undefined')
type = 'undefined';
if(type === 'string') if(type === 'string')
isPrimitive = true; isPrimitive = true;
else else
isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true;
if (isPrimitive) { if (isPrimitive) {
return type; if(listType)
return 'Array[' + type + ']';
else
return type.toString();
} else { } else {
if (listType) if (listType)
return definitions[type].getMockSignature(); return 'Array[' + definitions[type].getMockSignature() + ']';
else else
return definitions[type].getMockSignature(); return definitions[type].getMockSignature();
} }
@@ -795,9 +868,7 @@ Operation.prototype.getHeaderParams = function (args) {
if (param.in === 'header') { if (param.in === 'header') {
var value = args[param.name]; var value = args[param.name];
if(Array.isArray(value)) if(Array.isArray(value))
value = this.encodePathCollection(param.collectionFormat, param.name, value); value = value.toString();
else
value = this.encodePathParam(value);
headers[param.name] = value; headers[param.name] = value;
} }
} }
@@ -965,8 +1036,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
fail(message); fail(message);
return; return;
} }
var headers = this.getHeaderParams(args); var allHeaders = this.getHeaderParams(args);
headers = this.setContentTypes(args, opts); var contentTypeHeaders = this.setContentTypes(args, opts);
var headers = {}, attrname;
for (attrname in allHeaders) { headers[attrname] = allHeaders[attrname]; }
for (attrname in contentTypeHeaders) { headers[attrname] = contentTypeHeaders[attrname]; }
var body = this.getBody(headers, args); var body = this.getBody(headers, args);
var url = this.urlify(args); var url = this.urlify(args);
@@ -989,14 +1065,13 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
if(opts.mock === true) if(opts.mock === true)
return obj; return obj;
else else
new SwaggerHttp().execute(obj); new SwaggerHttp().execute(obj, opts);
}; };
Operation.prototype.setContentTypes = function(args, opts) { Operation.prototype.setContentTypes = function(args, opts) {
// default type // default type
var accepts = 'application/json'; var accepts = 'application/json';
var consumes = args.parameterContentType || 'application/json'; var consumes = args.parameterContentType || 'application/json';
var allDefinedParams = this.parameters; var allDefinedParams = this.parameters;
var definedFormParams = []; var definedFormParams = [];
var definedFileParams = []; var definedFileParams = [];
@@ -1013,10 +1088,10 @@ Operation.prototype.setContentTypes = function(args, opts) {
else else
definedFormParams.push(param); definedFormParams.push(param);
} }
else if(param.in === 'header' && this.headers) { else if(param.in === 'header' && opts) {
var key = param.name; var key = param.name;
var headerValue = this.headers[param.name]; var headerValue = opts[param.name];
if(typeof this.headers[param.name] !== 'undefined') if(typeof opts[param.name] !== 'undefined')
headers[key] = headerValue; headers[key] = headerValue;
} }
else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { else if(param.in === 'body' && typeof args[param.name] !== 'undefined') {
@@ -1184,21 +1259,20 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var result = {}; var i, result = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
var i;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
result[prop.name] = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore);
result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
return result; return result;
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i; var i, obj = {};
var obj = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore);
@@ -1207,8 +1281,7 @@ Model.prototype.getSampleValue = function(modelsToIgnore) {
}; };
Model.prototype.getMockSignature = function(modelsToIgnore) { Model.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = []; var i, prop, propertiesStr = [];
var i, prop;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
propertiesStr.push(prop.toString()); propertiesStr.push(prop.toString());
@@ -1251,7 +1324,7 @@ var Property = function(name, obj, required) {
this.optional = true; this.optional = true;
this.optional = !required; this.optional = !required;
this.default = obj.default || null; this.default = obj.default || null;
this.example = obj.example || null; this.example = obj.example !== undefined ? obj.example : null;
this.collectionFormat = obj.collectionFormat || null; this.collectionFormat = obj.collectionFormat || null;
this.maximum = obj.maximum || null; this.maximum = obj.maximum || null;
this.exclusiveMaximum = obj.exclusiveMaximum || null; this.exclusiveMaximum = obj.exclusiveMaximum || null;
@@ -1282,7 +1355,7 @@ Property.prototype.isArray = function () {
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
var type = getStringSignature(this.obj); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
@@ -1292,8 +1365,9 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels);
} }
else else {
type = refModel; output = refModelName;
}
} }
else if(this.example) else if(this.example)
output = this.example; output = this.example;
@@ -1301,6 +1375,8 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
output = this.default; output = this.default;
else if(type === 'date-time') else if(type === 'date-time')
output = new Date().toISOString(); output = new Date().toISOString();
else if(type === 'date')
output = new Date().toISOString().split("T")[0];
else if(type === 'string') else if(type === 'string')
output = 'string'; output = 'string';
else if(type === 'integer') else if(type === 'integer')
@@ -1322,16 +1398,20 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
return output; return output;
}; };
getStringSignature = function(obj) { getStringSignature = function(obj, baseComponent) {
var str = ''; var str = '';
if(typeof obj.$ref !== 'undefined') if(typeof obj.$ref !== 'undefined')
str += simpleRef(obj.$ref); str += simpleRef(obj.$ref);
else if(typeof obj.type === 'undefined') else if(typeof obj.type === 'undefined')
str += 'object'; str += 'object';
else if(obj.type === 'array') { else if(obj.type === 'array') {
str += 'Array['; if(baseComponent)
str += getStringSignature((obj.items || obj.$ref || {})); str += getStringSignature((obj.items || obj.$ref || {}));
str += ']'; else {
str += 'Array[';
str += getStringSignature((obj.items || obj.$ref || {}));
str += ']';
}
} }
else if(obj.type === 'integer' && obj.format === 'int32') else if(obj.type === 'integer' && obj.format === 'int32')
str += 'integer'; str += 'integer';
@@ -1402,7 +1482,7 @@ Property.prototype.toString = function() {
type = ''; type = '';
} }
else { else {
this.schema.type; type = this.schema.type;
} }
if (this.default) if (this.default)
@@ -1463,7 +1543,7 @@ Property.prototype.toString = function() {
optionHtml = function(label, value) { optionHtml = function(label, value) {
return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>'; return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
} };
typeFromJsonSchema = function(type, format) { typeFromJsonSchema = function(type, format) {
var str; var str;
@@ -1496,7 +1576,7 @@ var cookies = {};
var models = {}; var models = {};
SwaggerClient.prototype.buildFrom1_2Spec = function (response) { SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
if (response.apiVersion != null) { if (response.apiVersion !== null) {
this.apiVersion = response.apiVersion; this.apiVersion = response.apiVersion;
} }
this.apis = {}; this.apis = {};
@@ -1532,6 +1612,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
this.apisArray.push(res); this.apisArray.push(res);
} else { } else {
var k; var k;
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) { for (k = 0; k < response.apis.length; k++) {
var resource = response.apis[k]; var resource = response.apis[k];
res = new SwaggerResource(resource, this); res = new SwaggerResource(resource, this);
@@ -1540,15 +1621,22 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
} }
} }
this.isValid = true; this.isValid = true;
if (typeof this.success === 'function') {
this.success();
}
return this; return this;
}; };
SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
this.isValid = true;
this.ready = true;
this.isBuilt = true;
this.selfReflect();
this.success();
}
};
SwaggerClient.prototype.buildFrom1_1Spec = function (response) { SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info'); log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info');
if (response.apiVersion != null) if (response.apiVersion !== null)
this.apiVersion = response.apiVersion; this.apiVersion = response.apiVersion;
this.apis = {}; this.apis = {};
this.apisArray = []; this.apisArray = [];
@@ -1594,7 +1682,7 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
SwaggerClient.prototype.convertInfo = function (resp) { SwaggerClient.prototype.convertInfo = function (resp) {
if(typeof resp == 'object') { if(typeof resp == 'object') {
var info = {} var info = {};
info.title = resp.title; info.title = resp.title;
info.description = resp.description; info.description = resp.description;
@@ -1623,9 +1711,6 @@ SwaggerClient.prototype.selfReflect = function () {
} }
this.setConsolidatedModels(); this.setConsolidatedModels();
this.ready = true; this.ready = true;
if (typeof this.success === 'function') {
return this.success();
}
}; };
SwaggerClient.prototype.setConsolidatedModels = function () { SwaggerClient.prototype.setConsolidatedModels = function () {
@@ -1658,13 +1743,14 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description; this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {}); this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/'); var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', ''); this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath; this.basePath = this.api.basePath;
this.operations = {}; this.operations = {};
this.operationsArray = []; this.operationsArray = [];
this.modelsArray = []; this.modelsArray = [];
this.models = {}; this.models = api.models || {};
this.rawModels = {}; this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null; this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null;
@@ -1690,9 +1776,11 @@ var SwaggerResource = function (resourceObj, api) {
on: { on: {
response: function (resp) { response: function (resp) {
var responseObj = resp.obj || JSON.parse(resp.data); var responseObj = resp.obj || JSON.parse(resp.data);
_this.api.resourceCount += 1;
return _this.addApiDeclaration(responseObj); return _this.addApiDeclaration(responseObj);
}, },
error: function (response) { error: function (response) {
_this.api.resourceCount += 1;
return _this.api.fail('Unable to read api \'' + return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')'); _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
} }
@@ -1736,7 +1824,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
this.consumes = response.consumes; this.consumes = response.consumes;
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0) if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath; this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
this.resourcePath = response.resourcePath;
this.addModels(response.models); this.addModels(response.models);
if (response.apis) { if (response.apis) {
for (var i = 0 ; i < response.apis.length; i++) { for (var i = 0 ; i < response.apis.length; i++) {
@@ -1746,7 +1834,9 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
} }
this.api[this.name] = this; this.api[this.name] = this;
this.ready = true; this.ready = true;
return this.api.selfReflect(); if(this.api.resourceCount === this.api.expectedResourceCount)
this.api.finish();
return this;
}; };
SwaggerResource.prototype.addModels = function (models) { SwaggerResource.prototype.addModels = function (models) {
@@ -2015,9 +2105,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.consumes = consumes; this.consumes = consumes;
this.produces = produces; this.produces = produces;
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations; this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated); this.deprecated = deprecated;
this['do'] = __bind(this['do'], this); this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}
if (errors.length > 0) { if (errors.length > 0) {
console.error('SwaggerOperation errors', errors, arguments); console.error('SwaggerOperation errors', errors, arguments);
this.resource.api.fail(errors); this.resource.api.fail(errors);
@@ -2025,7 +2129,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.path = this.path.replace('{format}', 'json'); this.path = this.path.replace('{format}', 'json');
this.method = this.method.toLowerCase(); this.method = this.method.toLowerCase();
this.isGetMethod = this.method === 'GET'; this.isGetMethod = this.method === 'get';
var i, j, v; var i, j, v;
this.resourceName = this.resource.name; this.resourceName = this.resource.name;
@@ -2076,17 +2180,17 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
} }
} }
} }
else if (param.allowableValues != null) { else if (param.allowableValues) {
if (param.allowableValues.valueType === 'RANGE') if (param.allowableValues.valueType === 'RANGE')
param.isRange = true; param.isRange = true;
else else
param.isList = true; param.isList = true;
if (param.allowableValues != null) { if (param.allowableValues) {
param.allowableValues.descriptiveValues = []; param.allowableValues.descriptiveValues = [];
if (param.allowableValues.values) { if (param.allowableValues.values) {
for (j = 0; j < param.allowableValues.values.length; j++) { for (j = 0; j < param.allowableValues.values.length; j++) {
v = param.allowableValues.values[j]; v = param.allowableValues.values[j];
if (param.defaultValue != null) { if (param.defaultValue !== null) {
param.allowableValues.descriptiveValues.push({ param.allowableValues.descriptiveValues.push({
value: String(v), value: String(v),
isDefault: (v === param.defaultValue) isDefault: (v === param.defaultValue)
@@ -2156,7 +2260,7 @@ SwaggerOperation.prototype.getSampleJSON = function (type, models) {
var isPrimitive, listType, val; var isPrimitive, listType, val;
listType = this.isListType(type); listType = this.isListType(type);
isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true; isPrimitive = ((typeof listType !== 'undefined') && models[listType]) || (typeof models[type] !== 'undefined') ? false : true;
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample()); val = isPrimitive ? void 0 : (listType ? models[listType].createJSONSample() : models[type].createJSONSample());
if (val) { if (val) {
val = listType ? [val] : val; val = listType ? [val] : val;
if (typeof val == 'string') if (typeof val == 'string')
@@ -2191,7 +2295,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
callback = function (response) { callback = function (response) {
var content; var content;
content = null; content = null;
if (response != null) { if (response !== null) {
content = response.data; content = response.data;
} else { } else {
content = 'no data'; content = 'no data';
@@ -2202,7 +2306,7 @@ SwaggerOperation.prototype['do'] = function (args, opts, callback, error) {
params = {}; params = {};
params.headers = []; params.headers = [];
if (args.headers != null) { if (args.headers) {
params.headers = args.headers; params.headers = args.headers;
delete args.headers; delete args.headers;
} }
@@ -2289,7 +2393,7 @@ SwaggerOperation.prototype.urlify = function (args) {
if (param.paramType === 'path') { if (param.paramType === 'path') {
if (typeof args[param.name] !== 'undefined') { if (typeof args[param.name] !== 'undefined') {
// apply path params and remove from args // apply path params and remove from args
var reg = new RegExp('\\{\\s*?' + param.name + '.*?\\}(?=\\s*?(\\/?|$))', 'gi'); var reg = new RegExp('\\{\\s*?' + param.name + '[^\\{\\}\\/]*(?:\\{.*?\\}[^\\{\\}\\/]*)*\\}(?=(\\/?|$))', 'gi');
url = url.replace(reg, this.encodePathParam(args[param.name])); url = url.replace(reg, this.encodePathParam(args[param.name]));
delete args[param.name]; delete args[param.name];
} }
@@ -2323,7 +2427,7 @@ SwaggerOperation.prototype.urlify = function (args) {
} }
} }
} }
if ((queryParams != null) && queryParams.length > 0) if ((queryParams) && queryParams.length > 0)
url += '?' + queryParams; url += '?' + queryParams;
return url; return url;
}; };
@@ -2532,7 +2636,7 @@ var SwaggerRequest = function (type, url, params, opts, successCallback, errorCa
} }
var obj; var obj;
if (!((this.headers != null) && (this.headers.mock != null))) { if (!((this.headers) && (this.headers.mock))) {
obj = { obj = {
url: this.url, url: this.url,
method: this.type, method: this.type,
@@ -2657,7 +2761,7 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) {
*/ */
var SwaggerHttp = function() {}; var SwaggerHttp = function() {};
SwaggerHttp.prototype.execute = function(obj) { SwaggerHttp.prototype.execute = function(obj, opts) {
if(obj && (typeof obj.useJQuery === 'boolean')) if(obj && (typeof obj.useJQuery === 'boolean'))
this.useJQuery = obj.useJQuery; this.useJQuery = obj.useJQuery;
else else
@@ -2668,9 +2772,9 @@ SwaggerHttp.prototype.execute = function(obj) {
} }
if(this.useJQuery) if(this.useJQuery)
return new JQueryHttpClient().execute(obj); return new JQueryHttpClient(opts).execute(obj);
else else
return new ShredHttpClient().execute(obj); return new ShredHttpClient(opts).execute(obj);
}; };
SwaggerHttp.prototype.isIE8 = function() { SwaggerHttp.prototype.isIE8 = function() {
@@ -2755,7 +2859,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
if(contentType) { if(contentType) {
if(contentType.indexOf("application/json") === 0 || contentType.indexOf("+json") > 0) { if(contentType.indexOf("application/json") === 0 || contentType.indexOf("+json") > 0) {
try { try {
out.obj = response.responseJSON || {}; out.obj = response.responseJSON || JSON.parse(out.data) || {};
} catch (ex) { } catch (ex) {
// do not set out.obj // do not set out.obj
log("unable to parse JSON content"); log("unable to parse JSON content");
@@ -2778,8 +2882,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
/* /*
* ShredHttpClient is a light-weight, node or browser HTTP client * ShredHttpClient is a light-weight, node or browser HTTP client
*/ */
var ShredHttpClient = function(options) { var ShredHttpClient = function(opts) {
this.options = (options||{}); this.opts = (opts||{});
this.isInitialized = false; this.isInitialized = false;
var identity, toString; var identity, toString;
@@ -2790,7 +2894,7 @@ var ShredHttpClient = function(options) {
} }
else else
this.Shred = require("shred"); this.Shred = require("shred");
this.shred = new this.Shred(options); this.shred = new this.Shred(opts);
}; };
ShredHttpClient.prototype.initShred = function () { ShredHttpClient.prototype.initShred = function () {
@@ -2901,7 +3005,9 @@ e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization; e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization; e.CookieAuthorization = CookieAuthorization;
e.SwaggerClient = SwaggerClient; e.SwaggerClient = SwaggerClient;
e.SwaggerApi = SwaggerClient;
e.Operation = Operation; e.Operation = Operation;
e.Model = Model; e.Model = Model;
e.models = models; e.addModel = addModel;
})(); })();

View File

@@ -4,6 +4,7 @@ var popupDialog;
var clientId; var clientId;
var realm; var realm;
var oauth2KeyName; var oauth2KeyName;
var redirect_uri;
function handleLogin() { function handleLogin() {
var scopes = []; var scopes = [];
@@ -14,8 +15,8 @@ function handleLogin() {
var defs = auths; var defs = auths;
for(key in defs) { for(key in defs) {
var auth = defs[key]; var auth = defs[key];
oauth2KeyName = key;
if(auth.type === 'oauth2' && auth.scopes) { if(auth.type === 'oauth2' && auth.scopes) {
oauth2KeyName = key;
var scope; var scope;
if(Array.isArray(auth.scopes)) { if(Array.isArray(auth.scopes)) {
// 1.2 support // 1.2 support
@@ -141,6 +142,8 @@ function handleLogin() {
window.enabledScopes=scopes; window.enabledScopes=scopes;
redirect_uri = redirectUrl;
url += '&redirect_uri=' + encodeURIComponent(redirectUrl); url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
url += '&realm=' + encodeURIComponent(realm); url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId); url += '&client_id=' + encodeURIComponent(clientId);
@@ -199,7 +202,8 @@ function processOAuthCode(data) {
var params = { var params = {
'client_id': clientId, 'client_id': clientId,
'code': data.code, 'code': data.code,
'grant_type': 'authorization_code' 'grant_type': 'authorization_code',
'redirect_uri': redirect_uri
} }
$.ajax( $.ajax(
{ {

View File

@@ -1,7 +1,10 @@
{ {
"name": "swagger-ui", "name": "swagger-ui",
"version": "2.1.0-M1", "author": "Tony Tam <fehguy@gmail.com>",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API", "description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"version": "2.1.5-M1",
"homepage": "http://swagger.io",
"license": "Apache 2.0",
"scripts": { "scripts": {
"build": "./node_modules/gulp/bin/gulp.js;", "build": "./node_modules/gulp/bin/gulp.js;",
"serve": "./node_modules/gulp/bin/gulp.js serve;", "serve": "./node_modules/gulp/bin/gulp.js serve;",
@@ -11,17 +14,11 @@
"type": "git", "type": "git",
"url": "https://github.com/swagger-api/swagger-ui.git" "url": "https://github.com/swagger-api/swagger-ui.git"
}, },
"author": {
"name": "Tony Tam",
"email": "fehguy@gmail.com",
"url": "http://swagger.io"
},
"license": "Apache",
"readmeFilename": "README.md", "readmeFilename": "README.md",
"dependencies": { "dependencies": {
"shred": "0.8.10", "shred": "0.8.10",
"btoa": "1.1.1", "btoa": "1.1.1",
"swagger-client": "2.1.0-M1" "swagger-client": "2.1.5-M1"
}, },
"devDependencies": { "devDependencies": {
"chai": "^1.10.0", "chai": "^1.10.0",
@@ -36,6 +33,7 @@
"gulp-connect": "^2.2.0", "gulp-connect": "^2.2.0",
"gulp-declare": "^0.3.0", "gulp-declare": "^0.3.0",
"gulp-handlebars": "^3.0.1", "gulp-handlebars": "^3.0.1",
"gulp-header": "1.2.2",
"gulp-less": "^2.0.1", "gulp-less": "^2.0.1",
"gulp-rename": "^1.2.0", "gulp-rename": "^1.2.0",
"gulp-uglify": "^1.1.0", "gulp-uglify": "^1.1.0",

View File

@@ -16,6 +16,9 @@ class SwaggerUi extends Backbone.Router
@dom_id = options.dom_id @dom_id = options.dom_id
delete options.dom_id delete options.dom_id
if not options.supportedSubmitMethods?
options.supportedSubmitMethods = ['get','put','post','delete','head','options','patch']
# Create an empty div which contains the dom_id # Create an empty div which contains the dom_id
$('body').append('<div id="' + @dom_id + '"></div>') if not $('#' + @dom_id)? $('body').append('<div id="' + @dom_id + '"></div>') if not $('#' + @dom_id)?
@@ -59,7 +62,6 @@ class SwaggerUi extends Backbone.Router
@headerView.update(url) @headerView.update(url)
@api = new SwaggerClient(@options) @api = new SwaggerClient(@options)
@api.build()
# collapse all sections # collapse all sections
collapseAll:() -> collapseAll:() ->
@@ -87,7 +89,7 @@ class SwaggerUi extends Backbone.Router
setTimeout( setTimeout(
=> =>
Docs.shebang() Docs.shebang()
400 100
) )
buildUrl: (base, url) -> buildUrl: (base, url) ->

View File

@@ -12,7 +12,8 @@ class OperationView extends Backbone.View
initialize: (opts={}) -> initialize: (opts={}) ->
@auths = opts.auths @auths = opts.auths
@parentId = @model.parentId
@nickname = @model.nickname
@ @
mouseEnter: (e) -> mouseEnter: (e) ->
@@ -44,7 +45,7 @@ class OperationView extends Backbone.View
$(e.currentTarget.parentNode).find('#api_information_panel').hide() $(e.currentTarget.parentNode).find('#api_information_panel').hide()
render: -> render: ->
isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0 isMethodSubmissionSupported = jQuery.inArray(@model.method, @model.supportedSubmitMethods()) >= 0
@model.isReadOnly = true unless isMethodSubmissionSupported @model.isReadOnly = true unless isMethodSubmissionSupported
# 1.2 syntax for description was `notes` # 1.2 syntax for description was `notes`
@@ -452,5 +453,5 @@ class OperationView extends Backbone.View
if opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold then response_body_el else hljs.highlightBlock(response_body_el) if opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold then response_body_el else hljs.highlightBlock(response_body_el)
toggleOperationContent: -> toggleOperationContent: ->
elem = $('#' + Docs.escapeResourceName(@model.parentId + "_" + @model.nickname + "_content")) elem = $('#' + Docs.escapeResourceName(@parentId + "_" + @nickname + "_content"))
if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem) if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem)

View File

@@ -1,16 +1,17 @@
class ResourceView extends Backbone.View class ResourceView extends Backbone.View
initialize: (opts={}) -> initialize: (opts={}) ->
@auths = opts.auths @auths = opts.auths
if "" is @model.description if "" is @model.description
@model.description = null @model.description = null
if @model.description?
@model.summary = @model.description
render: -> render: ->
$(@el).html(Handlebars.templates.resource(@model))
methods = {} methods = {}
if @model.description
@model.summary = @model.description $(@el).html(Handlebars.templates.resource(@model))
# Render each operation # Render each operation
for operation in @model.operationsArray for operation in @model.operationsArray
counter = 0 counter = 0

View File

@@ -28,12 +28,12 @@
if (url && url.length > 1) { if (url && url.length > 1) {
url = decodeURIComponent(url[1]); url = decodeURIComponent(url[1]);
} else { } else {
url = "http://petstore.swagger.wordnik.com/v2/swagger.json"; url = "http://petstore.swagger.io/v2/swagger.json";
} }
window.swaggerUi = new SwaggerUi({ window.swaggerUi = new SwaggerUi({
url: url, url: url,
dom_id: "swagger-ui-container", dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){ onComplete: function(swaggerApi, swaggerUi){
if(typeof initOAuth == "function") { if(typeof initOAuth == "function") {
/* /*

View File

@@ -24,7 +24,7 @@ var elements = [
]; ];
describe('swagger 1.x spec tests', function (done) { describe('swagger 1.x spec tests', function (done) {
this.timeout(10 * 10000); this.timeout(10 * 1000);
var swaggerUI, specServer, driver; var swaggerUI, specServer, driver;
before(function () { before(function () {
@@ -89,6 +89,14 @@ describe('swagger 1.x spec tests', function (done) {
}); });
}); });
it('should find the pet resource description', function(done){
var locator = webdriver.By.xpath("//div[contains(., 'Operations about pets')]");
driver.findElements(locator).then(function (elements) {
expect(elements.length).to.not.equal(0);
done();
});
});
it('should find the user link', function(done){ it('should find the user link', function(done){
var locator = webdriver.By.xpath("//*[@data-id='user']"); var locator = webdriver.By.xpath("//*[@data-id='user']");
driver.isElementPresent(locator).then(function (isPresent) { driver.isElementPresent(locator).then(function (isPresent) {