Browse Source

added check for schema

bubble
Tony Tam 10 years ago
parent
commit
4d2ad25a10
6 changed files with 67 additions and 17 deletions
  1. +31
    -6
      dist/lib/swagger-client.js
  2. +2
    -2
      dist/swagger-ui.js
  3. +1
    -1
      dist/swagger-ui.min.js
  4. +31
    -6
      lib/swagger-client.js
  5. +1
    -1
      src/main/coffeescript/view/OperationView.coffee
  6. +1
    -1
      src/main/coffeescript/view/ParameterView.coffee

+ 31
- 6
dist/lib/swagger-client.js View File

@@ -305,7 +305,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
tags = operation.tags; tags = operation.tags;
} }
var operationId = this.idFromOp(path, httpMethod, operation); var operationId = this.idFromOp(path, httpMethod, operation);
var operation = new Operation (
var operationObject = new Operation (
this, this,
operationId, operationId,
httpMethod, httpMethod,
@@ -325,11 +325,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
operationGroup.label = tag; operationGroup.label = tag;
operationGroup.apis = []; operationGroup.apis = [];
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operation));
this.apisArray.push(new OperationGroup(tag, operationObject));
} }
operationGroup[operationId] = operation.execute.bind(operation);
operationGroup[operationId].help = operation.help.bind(operation);
operationGroup.apis.push(operation);
operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup.apis.push(operationObject);


// legacy UI feature // legacy UI feature
var j; var j;
@@ -340,7 +340,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
} }
} }
if(api) { if(api) {
api.operationsArray.push(operation);
api.operationsArray.push(operationObject);
} }
} }
} }
@@ -405,6 +405,7 @@ var OperationGroup = function(tag, operation) {
var Operation = function(parent, operationId, httpMethod, path, args, definitions) { var Operation = function(parent, operationId, httpMethod, path, args, definitions) {
var errors = []; var errors = [];
this.operation = args; this.operation = args;
this.deprecated = args.deprecated;
this.consumes = args.consumes; this.consumes = args.consumes;
this.produces = args.produces; this.produces = args.produces;
this.parent = parent; this.parent = parent;
@@ -439,6 +440,30 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
response = responses['200']; response = responses['200'];
defaultResponseCode = '200'; defaultResponseCode = '200';
} }
else if(responses['201']) {
response = responses['201'];
defaultResponseCode = '201';
}
else if(responses['202']) {
response = responses['202'];
defaultResponseCode = '202';
}
else if(responses['203']) {
response = responses['203'];
defaultResponseCode = '203';
}
else if(responses['204']) {
response = responses['204'];
defaultResponseCode = '204';
}
else if(responses['205']) {
response = responses['205'];
defaultResponseCode = '205';
}
else if(responses['206']) {
response = responses['206'];
defaultResponseCode = '206';
}
else if(responses['default']) { else if(responses['default']) {
response = responses['default']; response = responses['default'];
defaultResponseCode = 'default'; defaultResponseCode = 'default';


+ 2
- 2
dist/swagger-ui.js View File

@@ -1755,7 +1755,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
type = param.type || param.dataType; type = param.type || param.dataType;
if (typeof type === 'undefined') { if (typeof type === 'undefined') {
schema = param.schema; schema = param.schema;
if (schema['$ref']) {
if (schema && schema['$ref']) {
ref = schema['$ref']; ref = schema['$ref'];
if (ref.indexOf('#/definitions/') === 0) { if (ref.indexOf('#/definitions/') === 0) {
type = ref.substring('#/definitions/'.length); type = ref.substring('#/definitions/'.length);
@@ -2209,7 +2209,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
type = this.model.type || this.model.dataType; type = this.model.type || this.model.dataType;
if (typeof type === 'undefined') { if (typeof type === 'undefined') {
schema = this.model.schema; schema = this.model.schema;
if (schema['$ref']) {
if (schema && schema['$ref']) {
ref = schema['$ref']; ref = schema['$ref'];
if (ref.indexOf('#/definitions/') === 0) { if (ref.indexOf('#/definitions/') === 0) {
type = ref.substring('#/definitions/'.length); type = ref.substring('#/definitions/'.length);


+ 1
- 1
dist/swagger-ui.min.js
File diff suppressed because it is too large
View File


+ 31
- 6
lib/swagger-client.js View File

@@ -305,7 +305,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
tags = operation.tags; tags = operation.tags;
} }
var operationId = this.idFromOp(path, httpMethod, operation); var operationId = this.idFromOp(path, httpMethod, operation);
var operation = new Operation (
var operationObject = new Operation (
this, this,
operationId, operationId,
httpMethod, httpMethod,
@@ -325,11 +325,11 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
operationGroup.label = tag; operationGroup.label = tag;
operationGroup.apis = []; operationGroup.apis = [];
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operation));
this.apisArray.push(new OperationGroup(tag, operationObject));
} }
operationGroup[operationId] = operation.execute.bind(operation);
operationGroup[operationId].help = operation.help.bind(operation);
operationGroup.apis.push(operation);
operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup.apis.push(operationObject);


// legacy UI feature // legacy UI feature
var j; var j;
@@ -340,7 +340,7 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
} }
} }
if(api) { if(api) {
api.operationsArray.push(operation);
api.operationsArray.push(operationObject);
} }
} }
} }
@@ -405,6 +405,7 @@ var OperationGroup = function(tag, operation) {
var Operation = function(parent, operationId, httpMethod, path, args, definitions) { var Operation = function(parent, operationId, httpMethod, path, args, definitions) {
var errors = []; var errors = [];
this.operation = args; this.operation = args;
this.deprecated = args.deprecated;
this.consumes = args.consumes; this.consumes = args.consumes;
this.produces = args.produces; this.produces = args.produces;
this.parent = parent; this.parent = parent;
@@ -439,6 +440,30 @@ var Operation = function(parent, operationId, httpMethod, path, args, definition
response = responses['200']; response = responses['200'];
defaultResponseCode = '200'; defaultResponseCode = '200';
} }
else if(responses['201']) {
response = responses['201'];
defaultResponseCode = '201';
}
else if(responses['202']) {
response = responses['202'];
defaultResponseCode = '202';
}
else if(responses['203']) {
response = responses['203'];
defaultResponseCode = '203';
}
else if(responses['204']) {
response = responses['204'];
defaultResponseCode = '204';
}
else if(responses['205']) {
response = responses['205'];
defaultResponseCode = '205';
}
else if(responses['206']) {
response = responses['206'];
defaultResponseCode = '206';
}
else if(responses['default']) { else if(responses['default']) {
response = responses['default']; response = responses['default'];
defaultResponseCode = 'default'; defaultResponseCode = 'default';


+ 1
- 1
src/main/coffeescript/view/OperationView.coffee View File

@@ -97,7 +97,7 @@ class OperationView extends Backbone.View
type = param.type || param.dataType type = param.type || param.dataType
if typeof type is 'undefined' if typeof type is 'undefined'
schema = param.schema schema = param.schema
if schema['$ref']
if schema and schema['$ref']
ref = schema['$ref'] ref = schema['$ref']
if ref.indexOf('#/definitions/') is 0 if ref.indexOf('#/definitions/') is 0
type = ref.substring('#/definitions/'.length) type = ref.substring('#/definitions/'.length)


+ 1
- 1
src/main/coffeescript/view/ParameterView.coffee View File

@@ -12,7 +12,7 @@ class ParameterView extends Backbone.View


if typeof type is 'undefined' if typeof type is 'undefined'
schema = @model.schema schema = @model.schema
if schema['$ref']
if schema and schema['$ref']
ref = schema['$ref'] ref = schema['$ref']
if ref.indexOf('#/definitions/') is 0 if ref.indexOf('#/definitions/') is 0
type = ref.substring('#/definitions/'.length) type = ref.substring('#/definitions/'.length)


Loading…
Cancel
Save