This commit is contained in:
Tony Tam
2014-10-20 07:27:06 -07:00
parent 187dacd8e4
commit 97d23f61de
3 changed files with 98 additions and 93 deletions

3
dist/index.html vendored
View File

@@ -19,7 +19,7 @@
<script src='lib/swagger-client.js' type='text/javascript'></script> <script src='lib/swagger-client.js' type='text/javascript'></script>
<script src='swagger-ui.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 src='spec.js' type='text/javascript'></script>
<!-- enabling this will enable oauth2 implicit scope support --> <!-- enabling this will enable oauth2 implicit scope support -->
<script src='lib/swagger-oauth.js' type='text/javascript'></script> <script src='lib/swagger-oauth.js' type='text/javascript'></script>
<script type="text/javascript"> <script type="text/javascript">
@@ -32,6 +32,7 @@
} }
window.swaggerUi = new SwaggerUi({ window.swaggerUi = new SwaggerUi({
url: url, url: url,
spec: spec,
dom_id: "swagger-ui-container", dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){ onComplete: function(swaggerApi, swaggerUi){

View File

@@ -412,56 +412,58 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
var path; var path;
var operations = []; var operations = [];
for(path in response.paths) { for(path in response.paths) {
var httpMethod; if(typeof response.paths[path] === 'object') {
for(httpMethod in response.paths[path]) { var httpMethod;
var operation = response.paths[path][httpMethod]; for(httpMethod in response.paths[path]) {
var tags = operation.tags; var operation = response.paths[path][httpMethod];
if(typeof tags === 'undefined') { var tags = operation.tags;
operation.tags = [ 'default' ]; if(typeof tags === 'undefined') {
tags = operation.tags; operation.tags = [ 'default' ];
} tags = operation.tags;
var operationId = this.idFromOp(path, httpMethod, operation); }
var operationObject = new Operation ( var operationId = this.idFromOp(path, httpMethod, operation);
this, var operationObject = new Operation (
operationId, this,
httpMethod, operationId,
path, httpMethod,
operation, path,
this.definitions operation,
); this.definitions
// bind this operation's execute command to the api );
if(tags.length > 0) { // bind this operation's execute command to the api
var i; if(tags.length > 0) {
for(i = 0; i < tags.length; i++) { var i;
var tag = this.tagFromLabel(tags[i]); for(i = 0; i < tags.length; i++) {
var operationGroup = this[tag]; var tag = this.tagFromLabel(tags[i]);
if(typeof operationGroup === 'undefined') { var operationGroup = this[tag];
this[tag] = []; if(typeof operationGroup === 'undefined') {
operationGroup = this[tag]; this[tag] = [];
operationGroup.label = tag; operationGroup = this[tag];
operationGroup.apis = []; operationGroup.label = tag;
this[tag].help = this.help.bind(operationGroup); operationGroup.apis = [];
this.apisArray.push(new OperationGroup(tag, operationObject)); this[tag].help = this.help.bind(operationGroup);
} this.apisArray.push(new OperationGroup(tag, operationObject));
operationGroup[operationId] = operationObject.execute.bind(operationObject); }
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup.apis.push(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup.apis.push(operationObject);
// legacy UI feature // legacy UI feature
var j; var j;
var api; var api;
for(j = 0; j < this.apisArray.length; j++) { for(j = 0; j < this.apisArray.length; j++) {
if(this.apisArray[j].tag === tag) { if(this.apisArray[j].tag === tag) {
api = this.apisArray[j]; api = this.apisArray[j];
}
}
if(api) {
api.operationsArray.push(operationObject);
} }
} }
if(api) {
api.operationsArray.push(operationObject);
}
} }
} else {
else { log('no group to bind to');
log('no group to bind to'); }
} }
} }
} }

View File

@@ -412,56 +412,58 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
var path; var path;
var operations = []; var operations = [];
for(path in response.paths) { for(path in response.paths) {
var httpMethod; if(typeof response.paths[path] === 'object') {
for(httpMethod in response.paths[path]) { var httpMethod;
var operation = response.paths[path][httpMethod]; for(httpMethod in response.paths[path]) {
var tags = operation.tags; var operation = response.paths[path][httpMethod];
if(typeof tags === 'undefined') { var tags = operation.tags;
operation.tags = [ 'default' ]; if(typeof tags === 'undefined') {
tags = operation.tags; operation.tags = [ 'default' ];
} tags = operation.tags;
var operationId = this.idFromOp(path, httpMethod, operation); }
var operationObject = new Operation ( var operationId = this.idFromOp(path, httpMethod, operation);
this, var operationObject = new Operation (
operationId, this,
httpMethod, operationId,
path, httpMethod,
operation, path,
this.definitions operation,
); this.definitions
// bind this operation's execute command to the api );
if(tags.length > 0) { // bind this operation's execute command to the api
var i; if(tags.length > 0) {
for(i = 0; i < tags.length; i++) { var i;
var tag = this.tagFromLabel(tags[i]); for(i = 0; i < tags.length; i++) {
var operationGroup = this[tag]; var tag = this.tagFromLabel(tags[i]);
if(typeof operationGroup === 'undefined') { var operationGroup = this[tag];
this[tag] = []; if(typeof operationGroup === 'undefined') {
operationGroup = this[tag]; this[tag] = [];
operationGroup.label = tag; operationGroup = this[tag];
operationGroup.apis = []; operationGroup.label = tag;
this[tag].help = this.help.bind(operationGroup); operationGroup.apis = [];
this.apisArray.push(new OperationGroup(tag, operationObject)); this[tag].help = this.help.bind(operationGroup);
} this.apisArray.push(new OperationGroup(tag, operationObject));
operationGroup[operationId] = operationObject.execute.bind(operationObject); }
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup.apis.push(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup.apis.push(operationObject);
// legacy UI feature // legacy UI feature
var j; var j;
var api; var api;
for(j = 0; j < this.apisArray.length; j++) { for(j = 0; j < this.apisArray.length; j++) {
if(this.apisArray[j].tag === tag) { if(this.apisArray[j].tag === tag) {
api = this.apisArray[j]; api = this.apisArray[j];
}
}
if(api) {
api.operationsArray.push(operationObject);
} }
} }
if(api) {
api.operationsArray.push(operationObject);
}
} }
} else {
else { log('no group to bind to');
log('no group to bind to'); }
} }
} }
} }