Compare commits

...
2 Commits
Author SHA1 Message Date
Tony Tam 4fb5b86db1 updated swagger-js to address sample schema issues 2013-08-29 17:15:50 -07:00
Tony Tam f22efb66de fix for #279, empty boolean drop-downs 2013-08-20 12:48:14 -07:00
5 changed files with 228 additions and 103 deletions
+1 -2
View File
@@ -3,7 +3,7 @@
<head>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script type="text/javascript" src="lib/shred.bundle.js" /></script>
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
@@ -16,7 +16,6 @@
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
+113 -50
View File
@@ -33,13 +33,11 @@
if (options.url != null) {
this.url = options.url;
}
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) {
this.success = options.success;
}
this.failure = options.failure != null ? options.failure : function() {};
this.progress = options.progress != null ? options.progress : function() {};
this.defaultHeaders = options.headers != null ? options.headers : {};
if (options.success != null) {
this.build();
}
@@ -66,55 +64,14 @@
}
},
response: function(rawResponse) {
var api, isApi, newName, operation, res, resource, response, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
var response;
response = JSON.parse(rawResponse.content.data);
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
_this.apis = {};
_this.apisArray = [];
_this.produces = response.produces;
if (response.info != null) {
_this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
_this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, _this);
_this.apis[newName] = res;
_this.apisArray.push(res);
_this.swaggerVersion = response.swaggerVersion;
if (_this.swaggerVersion === "1.2") {
return _this.buildFromSpec(response);
} else {
if (response.basePath) {
_this.basePath = response.basePath;
} else if (_this.url.indexOf('?') > 0) {
_this.basePath = _this.url.substring(0, _this.url.lastIndexOf('?'));
} else {
_this.basePath = _this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, _this);
_this.apis[res.name] = res;
_this.apisArray.push(res);
}
return _this.buildFrom1_1Spec(response);
}
if (_this.success) {
_this.success();
}
return _this;
}
}
};
@@ -129,6 +86,109 @@
return this;
};
SwaggerApi.prototype.buildFromSpec = function(response) {
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (response.apiVersion != null) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
this.apisArray = [];
this.produces = response.produces;
if (response.info != null) {
this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
} else {
if (response.basePath) {
this.basePath = response.basePath;
} else if (this.url.indexOf('?') > 0) {
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
} else {
this.basePath = this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, this);
this.apis[res.name] = res;
this.apisArray.push(res);
}
}
if (this.success) {
this.success();
}
return this;
};
SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
console.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) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
this.apisArray = [];
this.produces = response.produces;
if (response.info != null) {
this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
} else {
if (response.basePath) {
this.basePath = response.basePath;
} else if (this.url.indexOf('?') > 0) {
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
} else {
this.basePath = this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, this);
this.apis[res.name] = res;
this.apisArray.push(res);
}
}
if (this.success) {
this.success();
}
return this;
};
SwaggerApi.prototype.selfReflect = function() {
var resource, resource_name, _ref;
if (this.apis == null) {
@@ -448,6 +508,7 @@
SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
var prop, result, _i, _len, _ref;
console.log("creating json sample for " + this);
result = {};
modelsToIgnore = modelsToIgnore || [];
modelsToIgnore.push(this.name);
@@ -456,6 +517,7 @@
prop = _ref[_i];
result[prop.name] = prop.getSampleValue(modelsToIgnore);
}
modelsToIgnore.pop(this.name);
return result;
};
@@ -467,7 +529,8 @@
function SwaggerModelProperty(name, obj) {
this.name = name;
this.dataType = obj.type;
this.dataType = obj.type || obj.dataType || obj["$ref"];
console.log(this.name + " has data type " + this.dataType);
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
this.descr = obj.description;
this.required = obj.required;
@@ -576,7 +639,7 @@
type = parameter.type || parameter.dataType;
if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {};
parameter.allowableValues.values = this.resource.api.booleanValues;
parameter.allowableValues.values = ["true", "false"];
}
parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
+113 -50
View File
@@ -33,13 +33,11 @@
if (options.url != null) {
this.url = options.url;
}
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) {
this.success = options.success;
}
this.failure = options.failure != null ? options.failure : function() {};
this.progress = options.progress != null ? options.progress : function() {};
this.defaultHeaders = options.headers != null ? options.headers : {};
if (options.success != null) {
this.build();
}
@@ -66,55 +64,14 @@
}
},
response: function(rawResponse) {
var api, isApi, newName, operation, res, resource, response, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
var response;
response = JSON.parse(rawResponse.content.data);
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
_this.apis = {};
_this.apisArray = [];
_this.produces = response.produces;
if (response.info != null) {
_this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
_this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, _this);
_this.apis[newName] = res;
_this.apisArray.push(res);
_this.swaggerVersion = response.swaggerVersion;
if (_this.swaggerVersion === "1.2") {
return _this.buildFromSpec(response);
} else {
if (response.basePath) {
_this.basePath = response.basePath;
} else if (_this.url.indexOf('?') > 0) {
_this.basePath = _this.url.substring(0, _this.url.lastIndexOf('?'));
} else {
_this.basePath = _this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, _this);
_this.apis[res.name] = res;
_this.apisArray.push(res);
}
return _this.buildFrom1_1Spec(response);
}
if (_this.success) {
_this.success();
}
return _this;
}
}
};
@@ -129,6 +86,109 @@
return this;
};
SwaggerApi.prototype.buildFromSpec = function(response) {
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (response.apiVersion != null) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
this.apisArray = [];
this.produces = response.produces;
if (response.info != null) {
this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
} else {
if (response.basePath) {
this.basePath = response.basePath;
} else if (this.url.indexOf('?') > 0) {
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
} else {
this.basePath = this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, this);
this.apis[res.name] = res;
this.apisArray.push(res);
}
}
if (this.success) {
this.success();
}
return this;
};
SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
console.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) {
this.apiVersion = response.apiVersion;
}
this.apis = {};
this.apisArray = [];
this.produces = response.produces;
if (response.info != null) {
this.info = response.info;
}
isApi = false;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
api = _ref[_i];
if (api.operations) {
_ref1 = api.operations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
operation = _ref1[_j];
isApi = true;
}
}
}
if (isApi) {
newName = response.resourcePath.replace(/\//g, '');
this.resourcePath = response.resourcePath;
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
} else {
if (response.basePath) {
this.basePath = response.basePath;
} else if (this.url.indexOf('?') > 0) {
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
} else {
this.basePath = this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
resource = _ref2[_k];
res = new SwaggerResource(resource, this);
this.apis[res.name] = res;
this.apisArray.push(res);
}
}
if (this.success) {
this.success();
}
return this;
};
SwaggerApi.prototype.selfReflect = function() {
var resource, resource_name, _ref;
if (this.apis == null) {
@@ -448,6 +508,7 @@
SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
var prop, result, _i, _len, _ref;
console.log("creating json sample for " + this);
result = {};
modelsToIgnore = modelsToIgnore || [];
modelsToIgnore.push(this.name);
@@ -456,6 +517,7 @@
prop = _ref[_i];
result[prop.name] = prop.getSampleValue(modelsToIgnore);
}
modelsToIgnore.pop(this.name);
return result;
};
@@ -467,7 +529,8 @@
function SwaggerModelProperty(name, obj) {
this.name = name;
this.dataType = obj.type;
this.dataType = obj.type || obj.dataType || obj["$ref"];
console.log(this.name + " has data type " + this.dataType);
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
this.descr = obj.description;
this.required = obj.required;
@@ -576,7 +639,7 @@
type = parameter.type || parameter.dataType;
if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {};
parameter.allowableValues.values = this.resource.api.booleanValues;
parameter.allowableValues.values = ["true", "false"];
}
parameter.signature = this.getSignature(type, this.resource.models);
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "swagger-ui",
"version": "2.0.0",
"version": "2.0.1",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"scripts": {
"build": "PATH=$PATH:./node_modules/.bin cake dist",