';
+ var stronger = '';
+ var strongClose = '';
+ var classOpen = strong + 'array' + ' {' + strongClose;
+ var classClose = strong + '}' + strongClose;
+ var returnVal = classOpen + '' + propertiesStr.join(',
') + '
' + 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 + ('
' + model.getMockSignature(modelsToIgnore));
+ }
+ }
+ return returnVal;
};
@@ -280,6 +301,206 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) {
}
return returnVal;
};
+/**
+ * Resolves a spec's remote references
+ */
+var Resolver = function (){};
+
+Resolver.prototype.resolve = function(spec, callback, scope) {
+ this.scope = (scope || this);
+ var host, name, path, property, propertyName, type;
+ var processedCalls = 0, resolvedRefs = {}, unresolvedRefs = {};
+
+ // store objects for dereferencing
+ var resolutionTable = {};
+
+ // models
+ for(name in spec.definitions) {
+ var model = spec.definitions[name];
+ for(propertyName in model.properties) {
+ property = model.properties[propertyName];
+ this.resolveTo(property, resolutionTable);
+ }
+ }
+ // operations
+ for(name in spec.paths) {
+ var method, operation, responseCode;
+ path = spec.paths[name];
+ for(method in path) {
+ operation = path[method];
+ var i, parameters = operation.parameters;
+ for(i in parameters) {
+ var parameter = parameters[i];
+ if(parameter.in === 'body' && parameter.schema) {
+ this.resolveTo(parameter.schema, resolutionTable);
+ }
+ if(parameter.$ref) {
+ this.resolveInline(spec, parameter, resolutionTable, unresolvedRefs);
+ }
+ }
+ for(responseCode in operation.responses) {
+ var response = operation.responses[responseCode];
+ if(response.schema) {
+ this.resolveTo(response.schema, resolutionTable);
+ }
+ }
+ }
+ }
+ // get hosts
+ var opts = {}, expectedCalls = 0;
+ for(name in resolutionTable) {
+ var parts = name.split('#');
+ if(parts.length == 2) {
+ host = parts[0]; path = parts[1];
+ if(!Array.isArray(opts[host])) {
+ opts[host] = [];
+ expectedCalls += 1;
+ }
+ opts[host].push(path);
+ }
+ }
+
+ for(name in opts) {
+ var self = this, opt = opts[name];
+ host = name;
+
+ var obj = {
+ useJQuery: false, // TODO
+ url: host,
+ method: "get",
+ headers: {
+ accept: this.scope.swaggerRequestHeaders || 'application/json'
+ },
+ on: {
+ error: function(response) {
+ processedCalls += 1;
+ var i;
+ for(i = 0; i < opt.length; i++) {
+ // fail all of these
+ var resolved = host + '#' + opt[i];
+ unresolvedRefs[resolved] = null;
+ }
+ if(processedCalls === expectedCalls)
+ self.finish(spec, resolutionTable, resolvedRefs, unresolvedRefs, callback);
+ },
+ response: function(response) {
+ var i, j, swagger = response.obj;
+ processedCalls += 1;
+ for(i = 0; i < opt.length; i++) {
+ var location = swagger, path = opt[i], parts = path.split('/');
+ for(j = 0; j < parts.length; j++) {
+ var segment = parts[j];
+ if(typeof location === 'undefined')
+ break;
+ if(segment.length > 0)
+ location = location[segment];
+ }
+ var resolved = host + '#' + path, resolvedName = parts[j-1];
+ if(typeof location !== 'undefined') {
+ resolvedRefs[resolved] = {
+ name: resolvedName,
+ obj: location
+ };
+ }
+ else unresolvedRefs[resolved] = null;
+ }
+ if(processedCalls === expectedCalls)
+ self.finish(spec, resolutionTable, resolvedRefs, unresolvedRefs, callback);
+ }
+ }
+ };
+ authorizations.apply(obj);
+ new SwaggerHttp().execute(obj);
+ }
+ if(Object.keys(opts).length === 0)
+ callback.call(this.scope, spec, unresolvedRefs);
+};
+
+Resolver.prototype.finish = function(spec, resolutionTable, resolvedRefs, unresolvedRefs, callback) {
+ // walk resolution table and replace with resolved refs
+ var ref;
+ for(ref in resolutionTable) {
+ var i, locations = resolutionTable[ref];
+ for(i = 0; i < locations.length; i++) {
+ var resolvedTo = resolvedRefs[locations[i].obj.$ref];
+ if(resolvedTo) {
+ if(!spec.definitions)
+ spec.definitions = {};
+ if(locations[i].resolveAs === '$ref') {
+ spec.definitions[resolvedTo.name] = resolvedTo.obj;
+ locations[i].obj.$ref = '#/definitions/' + resolvedTo.name;
+ }
+ else if (locations[i].resolveAs === 'inline') {
+ var key;
+ var targetObj = locations[i].obj;
+ delete targetObj.$ref;
+ for(key in resolvedTo.obj) {
+ targetObj[key] = resolvedTo.obj[key];
+ }
+ }
+ }
+ }
+ }
+ callback.call(this.scope, spec, unresolvedRefs);
+};
+
+/**
+ * immediately in-lines local refs, queues remote refs
+ * for inline resolution
+ */
+Resolver.prototype.resolveInline = function (spec, property, objs, unresolvedRefs) {
+ var ref = property.$ref;
+ if(ref) {
+ if(ref.indexOf('http') === 0) {
+ if(Array.isArray(objs[ref])) {
+ objs[ref].push({obj: property, resolveAs: 'inline'});
+ }
+ else {
+ objs[ref] = [{obj: property, resolveAs: 'inline'}];
+ }
+ }
+ else if (ref.indexOf('#') === 0) {
+ // local resolve
+ var shortenedRef = ref.substring(1);
+ var i, parts = shortenedRef.split('/'), location = spec;
+ for(i = 0; i < parts.length; i++) {
+ var part = parts[i];
+ if(part.length > 0) {
+ location = location[part];
+ }
+ }
+ if(location) {
+ delete property.$ref;
+ var key;
+ for(key in location) {
+ property[key] = location[key];
+ }
+ }
+ else unresolvedRefs[ref] = null;
+ }
+ }
+ else if(property.type === 'array') {
+ this.resolveTo(property.items, objs);
+ }
+};
+
+Resolver.prototype.resolveTo = function (property, objs) {
+ var ref = property.$ref;
+ if(ref) {
+ if(ref.indexOf('http') === 0) {
+ if(Array.isArray(objs[ref])) {
+ objs[ref].push({obj: property, resolveAs: '$ref'});
+ }
+ else {
+ objs[ref] = [{obj: property, resolveAs: '$ref'}];
+ }
+ }
+ }
+ else if(property.type === 'array') {
+ var items = property.items;
+ this.resolveTo(items, objs);
+ }
+};
var addModel = function(name, model) {
models[name] = model;
};
@@ -325,8 +546,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
if (options.authorizations) {
this.clientAuthorizations = options.authorizations;
} else {
- var e = (typeof window !== 'undefined' ? window : exports);
- this.clientAuthorizations = e.authorizations;
+ this.clientAuthorizations = authorizations;
}
this.supportedSubmitMethods = options.supportedSubmitMethods || [];
@@ -336,6 +556,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
this.options = options;
if (typeof options.success === 'function') {
+ this.ready = true;
this.build();
}
};
@@ -343,7 +564,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
SwaggerClient.prototype.build = function(mock) {
if (this.isBuilt) return this;
var self = this;
- this.progress('fetching resource list: ' + this.url);
+ this.progress('fetching resource list: ' + this.url);
var obj = {
useJQuery: this.useJQuery,
url: this.url,
@@ -354,11 +575,11 @@ SwaggerClient.prototype.build = function(mock) {
on: {
error: function(response) {
if (self.url.substring(0, 4) !== 'http')
- return self.fail('Please specify the protocol for ' + self.url);
+ return self.fail('Please specify the protocol for ' + self.url);
else if (response.status === 0)
- return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
+ return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
else if (response.status === 404)
- return self.fail('Can\'t read swagger JSON from ' + self.url);
+ return self.fail('Can\'t read swagger JSON from ' + self.url);
else
return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url);
},
@@ -368,7 +589,7 @@ SwaggerClient.prototype.build = function(mock) {
if(responseObj.swagger && parseInt(responseObj.swagger) === 2) {
self.swaggerVersion = responseObj.swagger;
- self.buildFromSpec(responseObj);
+ new Resolver().resolve(responseObj, self.buildFromSpec, self);
self.isValid = true;
}
else {
@@ -382,11 +603,12 @@ SwaggerClient.prototype.build = function(mock) {
}
};
if(this.spec) {
- setTimeout(function() { self.buildFromSpec(self.spec); }, 10);
+ setTimeout(function() {
+ new Resolver().resolve(self.spec, self.buildFromSpec, self);
+ }, 10);
}
else {
- var e = (typeof window !== 'undefined' ? window : exports);
- var status = e.authorizations.apply(obj);
+ authorizations.apply(obj);
if(mock)
return obj;
new SwaggerHttp().execute(obj);
@@ -411,8 +633,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
// legacy support
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') {
location = this.parseUri(this.url);
}
@@ -472,17 +702,32 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(i = 0; i < tags.length; i++) {
var tag = this.tagFromLabel(tags[i]);
var operationGroup = this[tag];
+ if(typeof this.apis[tag] === 'undefined')
+ this.apis[tag] = {};
if(typeof operationGroup === 'undefined') {
this[tag] = [];
operationGroup = this[tag];
operationGroup.operations = {};
operationGroup.label = tag;
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.apisArray.push(new OperationGroup(tag, operationObject));
+ this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
}
+ if(typeof this.apis[tag].help !== 'function')
+ this.apis[tag].help = this.help.bind(operationGroup);
+ // bind to the apis object
+ this.apis[tag][operationId] = operationObject.execute.bind(operationObject);
+ this.apis[tag][operationId].help = operationObject.help.bind(operationObject);
+ this.apis[tag][operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject);
+ operationGroup[operationId].asCurl = operationObject.asCurl.bind(operationObject);
+
operationGroup.apis.push(operationObject);
operationGroup.operations[operationId] = operationObject;
@@ -525,12 +770,18 @@ SwaggerClient.prototype.parseUri = function(uri) {
};
};
-SwaggerClient.prototype.help = function() {
+SwaggerClient.prototype.help = function(dontPrint) {
var i;
- log('operations for the "' + this.label + '" tag');
+ var output = 'operations for the "' + this.label + '" tag';
for(i = 0; i < this.apis.length; i++) {
var api = this.apis[i];
- log(' * ' + api.nickname + ': ' + api.operation.summary);
+ output += '\n * ' + api.nickname + ': ' + api.operation.summary;
+ }
+ if(dontPrint)
+ return output;
+ else {
+ log(output);
+ return output;
}
};
@@ -548,14 +799,14 @@ SwaggerClient.prototype.fail = function(message) {
throw message;
};
-var OperationGroup = function(tag, operation) {
+var OperationGroup = function(tag, description, externalDocs, operation) {
this.tag = tag;
this.path = tag;
+ this.description = description;
+ this.externalDocs = externalDocs;
this.name = tag;
this.operation = operation;
this.operationsArray = [];
-
- this.description = operation.description || "";
};
var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) {
@@ -720,10 +971,14 @@ Operation.prototype.getType = function (param) {
str = 'long';
else if(type === 'integer')
str = 'integer';
- else if(type === 'string' && format === 'date-time')
- str = 'date-time';
- else if(type === 'string' && format === 'date')
- str = 'date';
+ else if(type === 'string') {
+ if(format === 'date-time')
+ str = 'date-time';
+ else if(format === 'date')
+ str = 'date';
+ else
+ str = 'string';
+ }
else if(type === 'number' && format === 'float')
str = 'float';
else if(type === 'number' && format === 'double')
@@ -732,8 +987,6 @@ Operation.prototype.getType = function (param) {
str = 'double';
else if(type === 'boolean')
str = 'boolean';
- else if(type === 'string')
- str = 'string';
else if(type === 'array') {
isArray = true;
if(param.items)
@@ -780,7 +1033,7 @@ Operation.prototype.help = function(dontPrint) {
var out = this.nickname + ': ' + this.summary + '\n';
for(var i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
- var typeInfo = typeFromJsonSchema(param.type, param.format);
+ var typeInfo = param.signature;
out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description;
}
if(typeof dontPrint === 'undefined')
@@ -898,9 +1151,8 @@ Operation.prototype.getMissingParams = function(args) {
return missingParams;
};
-Operation.prototype.getBody = function(headers, args) {
- var formParams = {};
- var body;
+Operation.prototype.getBody = function(headers, args, opts) {
+ var formParams = {}, body, key;
for(var i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
@@ -916,7 +1168,6 @@ Operation.prototype.getBody = function(headers, args) {
// handle form params
if(headers['Content-Type'] === 'application/x-www-form-urlencoded') {
var encoded = "";
- var key;
for(key in formParams) {
value = formParams[key];
if(typeof value !== 'undefined'){
@@ -927,6 +1178,25 @@ Operation.prototype.getBody = function(headers, args) {
}
body = encoded;
}
+ else if (headers['Content-Type'] && headers['Content-Type'].indexOf('multipart/form-data') >= 0) {
+ if(opts.useJQuery) {
+ var bodyParam = new FormData();
+ bodyParam.type = 'formData';
+ for (key in formParams) {
+ value = args[key];
+ if (typeof value !== 'undefined') {
+ // required for jquery file upload
+ if(value.type === 'file' && value.value) {
+ delete headers['Content-Type'];
+ bodyParam.append(key, value.value);
+ }
+ else
+ bodyParam.append(key, value);
+ }
+ }
+ body = bodyParam;
+ }
+ }
return body;
};
@@ -989,9 +1259,8 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
success = (success||log);
error = (error||log);
- if(typeof opts.useJQuery === 'boolean') {
+ if(opts.useJQuery)
this.useJQuery = opts.useJQuery;
- }
var missingParams = this.getMissingParams(args);
if(missingParams.length > 0) {
@@ -1006,7 +1275,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
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, opts);
var url = this.urlify(args);
var obj = {
@@ -1024,18 +1293,17 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
}
}
};
- var status = e.authorizations.apply(obj, this.operation.security);
+ var status = authorizations.apply(obj, this.operation.security);
if(opts.mock === true)
return obj;
else
- new SwaggerHttp().execute(obj);
+ new SwaggerHttp().execute(obj, opts);
};
Operation.prototype.setContentTypes = function(args, opts) {
// default type
var accepts = 'application/json';
var consumes = args.parameterContentType || 'application/json';
-
var allDefinedParams = this.parameters;
var definedFormParams = [];
var definedFileParams = [];
@@ -1108,14 +1376,24 @@ Operation.prototype.setContentTypes = function(args, opts) {
};
Operation.prototype.asCurl = function (args) {
+ var obj = this.execute(args, {mock: true});
+ authorizations.apply(obj);
var results = [];
- var headers = this.getHeaderParams(args);
- if (headers) {
+ results.push('-X ' + this.method.toUpperCase());
+ if (obj.headers) {
var key;
- for (key in headers)
- results.push("--header \"" + key + ": " + headers[key] + "\"");
+ for (key in obj.headers)
+ results.push('--header "' + key + ': ' + obj.headers[key] + '"');
}
- return "curl " + (results.join(" ")) + " " + this.urlify(args);
+ if(obj.body) {
+ var body;
+ if(typeof obj.body === 'object')
+ body = JSON.stringify(obj.body);
+ else
+ body = obj.body;
+ results.push('-d "' + body.replace(/"/g, '\\"') + '"');
+ }
+ return 'curl ' + (results.join(' ')) + ' "' + obj.url + '"';
};
Operation.prototype.encodePathCollection = function(type, name, value) {
@@ -1223,12 +1501,12 @@ var Model = function(name, definition) {
};
Model.prototype.createJSONSample = function(modelsToIgnore) {
- var i, result = {};
+ var i, result = {}, representations = {};
modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
- var sample = prop.getSampleValue(modelsToIgnore);
+ var sample = prop.getSampleValue(modelsToIgnore, representations);
result[prop.name] = sample;
}
delete modelsToIgnore[this.name];
@@ -1236,10 +1514,10 @@ Model.prototype.createJSONSample = function(modelsToIgnore) {
};
Model.prototype.getSampleValue = function(modelsToIgnore) {
- var i, obj = {};
+ var i, obj = {}, representations = {};
for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i];
- obj[property.name] = property.sampleValue(false, modelsToIgnore);
+ obj[property.name] = property.sampleValue(false, modelsToIgnore, representations);
}
return obj;
};
@@ -1288,7 +1566,7 @@ var Property = function(name, obj, required) {
this.optional = true;
this.optional = !required;
this.default = obj.default || null;
- this.example = obj.example || null;
+ this.example = obj.example !== undefined ? obj.example : null;
this.collectionFormat = obj.collectionFormat || null;
this.maximum = obj.maximum || null;
this.exclusiveMaximum = obj.exclusiveMaximum || null;
@@ -1304,8 +1582,8 @@ var Property = function(name, obj, required) {
this.multipleOf = obj.multipleOf || null;
};
-Property.prototype.getSampleValue = function (modelsToIgnore) {
- return this.sampleValue(false, modelsToIgnore);
+Property.prototype.getSampleValue = function (modelsToIgnore, representations) {
+ return this.sampleValue(false, modelsToIgnore, representations);
};
Property.prototype.isArray = function () {
@@ -1316,21 +1594,29 @@ Property.prototype.isArray = function () {
return false;
};
-Property.prototype.sampleValue = function(isArray, ignoredModels) {
+Property.prototype.sampleValue = function(isArray, ignoredModels, representations) {
isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {});
+ // representations = (representations || {});
+
var type = getStringSignature(this.obj, true);
var output;
if(this.$ref) {
var refModelName = simpleRef(this.$ref);
var refModel = models[refModelName];
+ if(typeof representations[type] !== 'undefined') {
+ return representations[type];
+ }
+ else
+
if(refModel && typeof ignoredModels[type] === 'undefined') {
ignoredModels[type] = this;
- output = refModel.getSampleValue(ignoredModels);
+ output = refModel.getSampleValue(ignoredModels, representations);
+ representations[type] = output;
}
else {
- output = refModelName;
+ output = (representations[type] || refModelName);
}
}
else if(this.example)
@@ -1435,7 +1721,7 @@ Property.prototype.toString = function() {
}
- var options = '';
+ var options = '';
var isArray = this.schema.type === 'array';
var type;
@@ -1497,11 +1783,11 @@ Property.prototype.toString = function() {
}
options += optionHtml('Enum', enumString);
- }
+ }
if (options.length > 0)
str = '' + str + '| ' + this.name + ' |
' + options + '
';
-
+
return str;
};
@@ -1574,6 +1860,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
+ this.finish();
} else {
var k;
this.expectedResourceCount = response.apis.length;
@@ -1591,13 +1878,13 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
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) {
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)
@@ -1629,7 +1916,9 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
+ this.finish();
} else {
+ this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -1638,9 +1927,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
}
}
this.isValid = true;
- if (this.success) {
- this.success();
- }
return this;
};
@@ -1662,16 +1948,18 @@ SwaggerClient.prototype.convertInfo = function (resp) {
};
SwaggerClient.prototype.selfReflect = function () {
- var resource, resource_name, ref;
+ var resource, tag, ref;
if (this.apis === null) {
return false;
}
ref = this.apis;
- for (resource_name in ref) {
- resource = ref[resource_name];
- if (resource.ready === null) {
+ for (tag in ref) {
+ api = ref[tag];
+ if (api.ready === null) {
return false;
}
+ this[tag] = api;
+ this[tag].help = __bind(api.help, api);
}
this.setConsolidatedModels();
this.ready = true;
@@ -1707,7 +1995,6 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {});
-
var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
@@ -1729,7 +2016,7 @@ var SwaggerResource = function (resourceObj, api) {
} else {
this.url = this.api.basePath + this.path.replace('{format}', 'json');
}
- this.api.progress('fetching resource ' + this.name + ': ' + this.url);
+ this.api.progress('fetching resource ' + this.name + ': ' + this.url);
var obj = {
url: this.url,
method: 'GET',
@@ -1745,8 +2032,8 @@ var SwaggerResource = function (resourceObj, api) {
},
error: function (response) {
_this.api.resourceCount += 1;
- return _this.api.fail('Unable to read api \'' +
- _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
+ return _this.api.fail('Unable to read api \'' +
+ _this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
}
}
};
@@ -1756,6 +2043,21 @@ var SwaggerResource = function (resourceObj, api) {
}
};
+SwaggerResource.prototype.help = function (dontPrint) {
+ var i;
+ var output = 'operations for the "' + this.name + '" tag';
+ for(i = 0; i < this.operationsArray.length; i++) {
+ var api = this.operationsArray[i];
+ output += '\n * ' + api.nickname + ': ' + api.description;
+ }
+ if(dontPrint)
+ return output;
+ else {
+ log(output);
+ return output;
+ }
+};
+
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
var pos, url;
url = this.api.basePath;
@@ -1787,7 +2089,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
if (typeof response.consumes === 'string')
this.consumes = response.consumes;
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') !== 0 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
this.resourcePath = response.resourcePath;
this.addModels(response.models);
if (response.apis) {
@@ -1871,11 +2173,11 @@ SwaggerResource.prototype.addOperations = function (resource_path, ops, consumes
o.summary,
o.notes,
type,
- responseMessages,
- this,
- consumes,
- produces,
- o.authorizations,
+ responseMessages,
+ this,
+ consumes,
+ produces,
+ o.authorizations,
o.deprecated);
this.operations[op.nickname] = op;
@@ -2072,6 +2374,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.deprecated = deprecated;
this['do'] = __bind(this['do'], this);
+
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
@@ -2189,8 +2492,8 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback);
};
- this.resource[this.nickname].help = function () {
- return _this.help();
+ this.resource[this.nickname].help = function (dontPrint) {
+ return _this.help(dontPrint);
};
this.resource[this.nickname].asCurl = function (args) {
return _this.asCurl(args);
@@ -2357,7 +2660,7 @@ SwaggerOperation.prototype.urlify = function (args) {
if (param.paramType === 'path') {
if (typeof args[param.name] !== 'undefined') {
// 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]));
delete args[param.name];
}
@@ -2371,15 +2674,15 @@ SwaggerOperation.prototype.urlify = function (args) {
param = params[i];
if(param.paramType === 'query') {
if (queryParams !== '')
- queryParams += '&';
+ queryParams += '&';
if (Array.isArray(param)) {
- var output = '';
- for(j = 0; j < param.length; j++) {
- if(j > 0)
- output += ',';
- output += encodeURIComponent(param[j]);
- }
- queryParams += encodeURIComponent(param.name) + '=' + output;
+ var output = '';
+ for(j = 0; j < param.length; j++) {
+ if(j > 0)
+ output += ',';
+ output += encodeURIComponent(param[j]);
+ }
+ queryParams += encodeURIComponent(param.name) + '=' + output;
}
else {
if (typeof args[param.name] !== 'undefined') {
@@ -2429,23 +2732,26 @@ SwaggerOperation.prototype.getMatchingParams = function (paramTypes, args) {
return matchingParams;
};
-SwaggerOperation.prototype.help = function () {
- var msg = '';
+SwaggerOperation.prototype.help = function (dontPrint) {
+ var msg = this.nickname + ': ' + this.summary;
var params = this.parameters;
for (var i = 0; i < params.length; i++) {
var param = params[i];
- if (msg !== '')
- msg += '\n';
- msg += '* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
+ msg += '\n* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
+ }
+ if(dontPrint)
+ return msg;
+ else {
+ console.log(msg);
+ return msg;
}
- return msg;
};
SwaggerOperation.prototype.asCurl = function (args) {
var results = [];
var i;
- var headers = SwaggerRequest.prototype.setHeaders(args, {}, this);
+ var headers = SwaggerRequest.prototype.setHeaders(args, {}, this);
for(i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
if(param.paramType && param.paramType === 'header' && args[param.name]) {
@@ -2725,20 +3031,26 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) {
*/
var SwaggerHttp = function() {};
-SwaggerHttp.prototype.execute = function(obj) {
+SwaggerHttp.prototype.execute = function(obj, opts) {
if(obj && (typeof obj.useJQuery === 'boolean'))
this.useJQuery = obj.useJQuery;
else
this.useJQuery = this.isIE8();
if(obj && typeof obj.body === 'object') {
- obj.body = JSON.stringify(obj.body);
+ if(obj.body.type && obj.body.type !== 'formData')
+ obj.body = JSON.stringify(obj.body);
+ else {
+ obj.contentType = false;
+ obj.processData = false;
+ delete obj.headers['Content-Type'];
+ }
}
if(this.useJQuery)
- return new JQueryHttpClient().execute(obj);
+ return new JQueryHttpClient(opts).execute(obj);
else
- return new ShredHttpClient().execute(obj);
+ return new ShredHttpClient(opts).execute(obj);
};
SwaggerHttp.prototype.isIE8 = function() {
@@ -2773,7 +3085,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
obj.type = obj.method;
obj.cache = false;
+ delete obj.useJQuery;
+ /*
obj.beforeSend = function(xhr) {
var key, results;
if (obj.headers) {
@@ -2789,9 +3103,10 @@ JQueryHttpClient.prototype.execute = function(obj) {
}
return results;
}
- };
+ };*/
obj.data = obj.body;
+ delete obj.body;
obj.complete = function(response, textStatus, opts) {
var headers = {},
headerArray = response.getAllResponseHeaders().split("\n");
@@ -2815,6 +3130,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
url: request.url,
method: request.method,
status: response.status,
+ statusText: response.statusText,
data: response.responseText,
headers: headers
};
@@ -2846,8 +3162,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
/*
* ShredHttpClient is a light-weight, node or browser HTTP client
*/
-var ShredHttpClient = function(options) {
- this.options = (options||{});
+var ShredHttpClient = function(opts) {
+ this.opts = (opts||{});
this.isInitialized = false;
var identity, toString;
@@ -2858,7 +3174,7 @@ var ShredHttpClient = function(options) {
}
else
this.Shred = require("shred");
- this.shred = new this.Shred(options);
+ this.shred = new this.Shred(opts);
};
ShredHttpClient.prototype.initShred = function () {
@@ -2964,7 +3280,7 @@ ShredHttpClient.prototype.execute = function(obj) {
var e = (typeof window !== 'undefined' ? window : exports);
-e.authorizations = new SwaggerAuthorizations();
+e.authorizations = authorizations = new SwaggerAuthorizations();
e.ApiKeyAuthorization = ApiKeyAuthorization;
e.PasswordAuthorization = PasswordAuthorization;
e.CookieAuthorization = CookieAuthorization;
@@ -2973,5 +3289,5 @@ e.SwaggerApi = SwaggerClient;
e.Operation = Operation;
e.Model = Model;
e.addModel = addModel;
-
+e.Resolver = Resolver;
})();
\ No newline at end of file
diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js
index 5c3777e7..7fc3d5f3 100644
--- a/dist/swagger-ui.js
+++ b/dist/swagger-ui.js
@@ -1,210 +1,203 @@
/**
* swagger-ui - Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API
- * @version v2.1.4-M1
+ * @version v2.1.5-M1
* @link http://swagger.io
* @license Apache 2.0
*/
-
-// ругается
-if (typeof marked === 'undefined') {
- marked = function(text) {
- return text;
- }
-}
-
-$(function() {
- // Helper function for vertically aligning DOM elements
- // http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
- $.fn.vAlign = function() {
- return this.each(function(i){
- var ah = $(this).height();
- var ph = $(this).parent().height();
- var mh = (ph - ah) / 2;
- $(this).css('margin-top', mh);
- });
- };
-
- $.fn.stretchFormtasticInputWidthToParent = function() {
- return this.each(function(i){
- var p_width = $(this).closest("form").innerWidth();
- var p_padding = parseInt($(this).closest("form").css('padding-left') ,10) + parseInt($(this).closest("form").css('padding-right'), 10);
- var this_padding = parseInt($(this).css('padding-left'), 10) + parseInt($(this).css('padding-right'), 10);
- $(this).css('width', p_width - p_padding - this_padding);
- });
- };
-
- $('form.formtastic li.string input, form.formtastic textarea').stretchFormtasticInputWidthToParent();
-
- // Vertically center these paragraphs
- // Parent may need a min-height for this to work..
- $('ul.downplayed li div.content p').vAlign();
-
- // When a sandbox form is submitted..
- $("form.sandbox").submit(function(){
-
- var error_free = true;
-
- // Cycle through the forms required inputs
- $(this).find("input.required").each(function() {
-
- // Remove any existing error styles from the input
- $(this).removeClass('error');
-
- // Tack the error style on if the input is empty..
- if ($(this).val() == '') {
- $(this).addClass('error');
- $(this).wiggle();
- error_free = false;
- }
-
- });
-
- return error_free;
- });
-
-});
-
-function clippyCopiedCallback(a) {
- $('#api_key_copied').fadeIn().delay(1000).fadeOut();
-
- // var b = $("#clippy_tooltip_" + a);
- // b.length != 0 && (b.attr("title", "copied!").trigger("tipsy.reload"), setTimeout(function() {
- // b.attr("title", "copy to clipboard")
- // },
- // 500))
-}
-
-// Logging function that accounts for browsers that don't have window.console
-log = function(){
- log.history = log.history || [];
- log.history.push(arguments);
- if(this.console){
- console.log( Array.prototype.slice.call(arguments)[0] );
- }
-};
-
-// Handle browsers that do console incorrectly (IE9 and below, see http://stackoverflow.com/a/5539378/7913)
-if (Function.prototype.bind && console && typeof console.log == "object") {
- [
- "log","info","warn","error","assert","dir","clear","profile","profileEnd"
- ].forEach(function (method) {
- console[method] = this.bind(console[method], console);
- }, Function.prototype.call);
-}
-
-var Docs = {
-
- shebang: function() {
-
- // If shebang has an operation nickname in it..
- // e.g. /docs/#!/words/get_search
- var fragments = $.param.fragment().split('/');
- fragments.shift(); // get rid of the bang
-
- switch (fragments.length) {
- case 1:
- // Expand all operations for the resource and scroll to it
- var dom_id = 'resource_' + fragments[0];
-
- Docs.expandEndpointListForResource(fragments[0]);
- $("#"+dom_id).slideto({highlight: false});
- break;
- case 2:
- // Refer to the endpoint DOM element, e.g. #words_get_search
-
- // Expand Resource
- Docs.expandEndpointListForResource(fragments[0]);
- $("#"+dom_id).slideto({highlight: false});
-
- // Expand operation
- var li_dom_id = fragments.join('_');
- var li_content_dom_id = li_dom_id + "_content";
-
-
- Docs.expandOperation($('#'+li_content_dom_id));
- $('#'+li_dom_id).slideto({highlight: false});
- break;
- }
-
- },
-
- toggleEndpointListForResource: function(resource) {
- var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
- if (elem.is(':visible')) {
- Docs.collapseEndpointListForResource(resource);
- } else {
- Docs.expandEndpointListForResource(resource);
- }
- },
-
- // Expand resource
- expandEndpointListForResource: function(resource) {
- var resource = Docs.escapeResourceName(resource);
- if (resource == '') {
- $('.resource ul.endpoints').slideDown();
- return;
- }
-
- $('li#resource_' + resource).addClass('active');
-
- var elem = $('li#resource_' + resource + ' ul.endpoints');
- elem.slideDown();
- },
-
- // Collapse resource and mark as explicitly closed
- collapseEndpointListForResource: function(resource) {
- var resource = Docs.escapeResourceName(resource);
- if (resource == '') {
- $('.resource ul.endpoints').slideUp();
- return;
- }
-
- $('li#resource_' + resource).removeClass('active');
-
- var elem = $('li#resource_' + resource + ' ul.endpoints');
- elem.slideUp();
- },
-
- expandOperationsForResource: function(resource) {
- // Make sure the resource container is open..
- Docs.expandEndpointListForResource(resource);
-
- if (resource == '') {
- $('.resource ul.endpoints li.operation div.content').slideDown();
- return;
- }
-
- $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
- Docs.expandOperation($(this));
- });
- },
-
- collapseOperationsForResource: function(resource) {
- // Make sure the resource container is open..
- Docs.expandEndpointListForResource(resource);
-
- if (resource == '') {
- $('.resource ul.endpoints li.operation div.content').slideUp();
- return;
- }
-
- $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
- Docs.collapseOperation($(this));
- });
- },
-
- escapeResourceName: function(resource) {
- return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&");
- },
-
- expandOperation: function(elem) {
- elem.slideDown();
- },
-
- collapseOperation: function(elem) {
- elem.slideUp();
- }
-};
+$(function() {
+
+ // Helper function for vertically aligning DOM elements
+ // http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
+ $.fn.vAlign = function() {
+ return this.each(function(i){
+ var ah = $(this).height();
+ var ph = $(this).parent().height();
+ var mh = (ph - ah) / 2;
+ $(this).css('margin-top', mh);
+ });
+ };
+
+ $.fn.stretchFormtasticInputWidthToParent = function() {
+ return this.each(function(i){
+ var p_width = $(this).closest("form").innerWidth();
+ var p_padding = parseInt($(this).closest("form").css('padding-left') ,10) + parseInt($(this).closest("form").css('padding-right'), 10);
+ var this_padding = parseInt($(this).css('padding-left'), 10) + parseInt($(this).css('padding-right'), 10);
+ $(this).css('width', p_width - p_padding - this_padding);
+ });
+ };
+
+ $('form.formtastic li.string input, form.formtastic textarea').stretchFormtasticInputWidthToParent();
+
+ // Vertically center these paragraphs
+ // Parent may need a min-height for this to work..
+ $('ul.downplayed li div.content p').vAlign();
+
+ // When a sandbox form is submitted..
+ $("form.sandbox").submit(function(){
+
+ var error_free = true;
+
+ // Cycle through the forms required inputs
+ $(this).find("input.required").each(function() {
+
+ // Remove any existing error styles from the input
+ $(this).removeClass('error');
+
+ // Tack the error style on if the input is empty..
+ if ($(this).val() == '') {
+ $(this).addClass('error');
+ $(this).wiggle();
+ error_free = false;
+ }
+
+ });
+
+ return error_free;
+ });
+
+});
+
+function clippyCopiedCallback(a) {
+ $('#api_key_copied').fadeIn().delay(1000).fadeOut();
+
+ // var b = $("#clippy_tooltip_" + a);
+ // b.length != 0 && (b.attr("title", "copied!").trigger("tipsy.reload"), setTimeout(function() {
+ // b.attr("title", "copy to clipboard")
+ // },
+ // 500))
+}
+
+// Logging function that accounts for browsers that don't have window.console
+log = function(){
+ log.history = log.history || [];
+ log.history.push(arguments);
+ if(this.console){
+ console.log( Array.prototype.slice.call(arguments)[0] );
+ }
+};
+
+// Handle browsers that do console incorrectly (IE9 and below, see http://stackoverflow.com/a/5539378/7913)
+if (Function.prototype.bind && console && typeof console.log == "object") {
+ [
+ "log","info","warn","error","assert","dir","clear","profile","profileEnd"
+ ].forEach(function (method) {
+ console[method] = this.bind(console[method], console);
+ }, Function.prototype.call);
+}
+
+var Docs = {
+
+ shebang: function() {
+
+ // If shebang has an operation nickname in it..
+ // e.g. /docs/#!/words/get_search
+ var fragments = $.param.fragment().split('/');
+ fragments.shift(); // get rid of the bang
+
+ switch (fragments.length) {
+ case 1:
+ // Expand all operations for the resource and scroll to it
+ var dom_id = 'resource_' + fragments[0];
+
+ Docs.expandEndpointListForResource(fragments[0]);
+ $("#"+dom_id).slideto({highlight: false});
+ break;
+ case 2:
+ // Refer to the endpoint DOM element, e.g. #words_get_search
+
+ // Expand Resource
+ Docs.expandEndpointListForResource(fragments[0]);
+ $("#"+dom_id).slideto({highlight: false});
+
+ // Expand operation
+ var li_dom_id = fragments.join('_');
+ var li_content_dom_id = li_dom_id + "_content";
+
+
+ Docs.expandOperation($('#'+li_content_dom_id));
+ $('#'+li_dom_id).slideto({highlight: false});
+ break;
+ }
+
+ },
+
+ toggleEndpointListForResource: function(resource) {
+ var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
+ if (elem.is(':visible')) {
+ Docs.collapseEndpointListForResource(resource);
+ } else {
+ Docs.expandEndpointListForResource(resource);
+ }
+ },
+
+ // Expand resource
+ expandEndpointListForResource: function(resource) {
+ var resource = Docs.escapeResourceName(resource);
+ if (resource == '') {
+ $('.resource ul.endpoints').slideDown();
+ return;
+ }
+
+ $('li#resource_' + resource).addClass('active');
+
+ var elem = $('li#resource_' + resource + ' ul.endpoints');
+ elem.slideDown();
+ },
+
+ // Collapse resource and mark as explicitly closed
+ collapseEndpointListForResource: function(resource) {
+ var resource = Docs.escapeResourceName(resource);
+ if (resource == '') {
+ $('.resource ul.endpoints').slideUp();
+ return;
+ }
+
+ $('li#resource_' + resource).removeClass('active');
+
+ var elem = $('li#resource_' + resource + ' ul.endpoints');
+ elem.slideUp();
+ },
+
+ expandOperationsForResource: function(resource) {
+ // Make sure the resource container is open..
+ Docs.expandEndpointListForResource(resource);
+
+ if (resource == '') {
+ $('.resource ul.endpoints li.operation div.content').slideDown();
+ return;
+ }
+
+ $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
+ Docs.expandOperation($(this));
+ });
+ },
+
+ collapseOperationsForResource: function(resource) {
+ // Make sure the resource container is open..
+ Docs.expandEndpointListForResource(resource);
+
+ if (resource == '') {
+ $('.resource ul.endpoints li.operation div.content').slideUp();
+ return;
+ }
+
+ $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
+ Docs.collapseOperation($(this));
+ });
+ },
+
+ escapeResourceName: function(resource) {
+ return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&");
+ },
+
+ expandOperation: function(elem) {
+ elem.slideDown();
+ },
+
+ collapseOperation: function(elem) {
+ elem.slideUp();
+ }
+};
var SwaggerUi,
__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; },
@@ -291,7 +284,6 @@ SwaggerUi = (function(_super) {
}
this.options.url = url;
this.headerView.update(url);
-
return this.api = new SwaggerClient(this.options);
};
@@ -308,7 +300,7 @@ SwaggerUi = (function(_super) {
};
SwaggerUi.prototype.render = function() {
- this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
+ this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
this.mainView = new MainView({
model: this.api,
el: $('#' + this.dom_id),
@@ -323,11 +315,6 @@ SwaggerUi = (function(_super) {
this.listAll();
}
this.renderGFM();
-
- if (typeof SwaggerTranslator != 'undefined') {
- SwaggerTranslator.translate();
- }
-
if (this.options.onComplete) {
this.options.onComplete(this.api, this);
}
@@ -335,7 +322,7 @@ SwaggerUi = (function(_super) {
return function() {
return Docs.shebang();
};
- })(this), 4000);
+ })(this), 100);
};
SwaggerUi.prototype.buildUrl = function(base, url) {
@@ -366,14 +353,7 @@ SwaggerUi = (function(_super) {
}
$('#message-bar').removeClass('message-fail');
$('#message-bar').addClass('message-success');
-
- var result = $('#message-bar').html(data);
-
- if (typeof SwaggerTranslator != 'undefined') {
- SwaggerTranslator.translate();
- }
-
- return result;
+ return $('#message-bar').html(data);
};
SwaggerUi.prototype.onLoadFailure = function(data) {
@@ -387,12 +367,6 @@ SwaggerUi = (function(_super) {
if (this.options.onFailure != null) {
this.options.onFailure(data);
}
-
- if (typeof SwaggerTranslator != 'undefined') {
- SwaggerTranslator.translate();
- }
-
-
return val;
};
@@ -419,14 +393,14 @@ this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"co
+ escapeExpression(((helper = (helper = helpers.keyName || (depth0 != null ? depth0.keyName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"keyName","hash":{},"data":data}) : helper)))
+ "\n \n \n \n\n\n";
},"useData":true});
+this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
+ return "\n\n\n";
+ },"useData":true});
Handlebars.registerHelper('sanitize', function(html) {
html = html.replace(/