Merge branch 'bodnia-issue-1186'

This commit is contained in:
Tony Tam
2016-02-22 09:45:58 -08:00
12 changed files with 790 additions and 665 deletions

12
dist/css/print.css vendored
View File

@@ -82,7 +82,7 @@
.swagger-section pre .vhdl .attribute,
.swagger-section pre .clojure .attribute,
.swagger-section pre .coffeescript .property {
color: #88F;
color: #8888ff;
}
.swagger-section pre .keyword,
.swagger-section pre .id,
@@ -124,11 +124,11 @@
display: block;
overflow-x: auto;
padding: 0.5em;
background: #F0F0F0;
background: #f0f0f0;
}
.swagger-section .hljs,
.swagger-section .hljs-subst {
color: #444;
color: #444444;
}
.swagger-section .hljs-keyword,
.swagger-section .hljs-attribute,
@@ -143,7 +143,7 @@
.swagger-section .hljs-bullet,
.swagger-section .hljs-code,
.swagger-section .hljs-addition {
color: #1F811F;
color: #1f811f;
}
.swagger-section .hljs-regexp,
.swagger-section .hljs-symbol,
@@ -152,7 +152,7 @@
.swagger-section .hljs-link,
.swagger-section .hljs-selector-attr,
.swagger-section .hljs-selector-pseudo {
color: #BC6060;
color: #bc6060;
}
.swagger-section .hljs-type,
.swagger-section .hljs-string,
@@ -173,7 +173,7 @@
color: #888888;
}
.swagger-section .hljs-meta {
color: #2B6EA1;
color: #2b6ea1;
}
.swagger-section .hljs-emphasis {
font-style: italic;

12
dist/css/screen.css vendored
View File

@@ -82,7 +82,7 @@
.swagger-section pre .vhdl .attribute,
.swagger-section pre .clojure .attribute,
.swagger-section pre .coffeescript .property {
color: #88F;
color: #8888ff;
}
.swagger-section pre .keyword,
.swagger-section pre .id,
@@ -124,11 +124,11 @@
display: block;
overflow-x: auto;
padding: 0.5em;
background: #F0F0F0;
background: #f0f0f0;
}
.swagger-section .hljs,
.swagger-section .hljs-subst {
color: #444;
color: #444444;
}
.swagger-section .hljs-keyword,
.swagger-section .hljs-attribute,
@@ -143,7 +143,7 @@
.swagger-section .hljs-bullet,
.swagger-section .hljs-code,
.swagger-section .hljs-addition {
color: #1F811F;
color: #1f811f;
}
.swagger-section .hljs-regexp,
.swagger-section .hljs-symbol,
@@ -152,7 +152,7 @@
.swagger-section .hljs-link,
.swagger-section .hljs-selector-attr,
.swagger-section .hljs-selector-pseudo {
color: #BC6060;
color: #bc6060;
}
.swagger-section .hljs-type,
.swagger-section .hljs-string,
@@ -173,7 +173,7 @@
color: #888888;
}
.swagger-section .hljs-meta {
color: #2B6EA1;
color: #2b6ea1;
}
.swagger-section .hljs-emphasis {
font-style: italic;

1299
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -82,7 +82,7 @@
.swagger-section pre .vhdl .attribute,
.swagger-section pre .clojure .attribute,
.swagger-section pre .coffeescript .property {
color: #88F;
color: #8888ff;
}
.swagger-section pre .keyword,
.swagger-section pre .id,
@@ -124,11 +124,11 @@
display: block;
overflow-x: auto;
padding: 0.5em;
background: #F0F0F0;
background: #f0f0f0;
}
.swagger-section .hljs,
.swagger-section .hljs-subst {
color: #444;
color: #444444;
}
.swagger-section .hljs-keyword,
.swagger-section .hljs-attribute,
@@ -143,7 +143,7 @@
.swagger-section .hljs-bullet,
.swagger-section .hljs-code,
.swagger-section .hljs-addition {
color: #1F811F;
color: #1f811f;
}
.swagger-section .hljs-regexp,
.swagger-section .hljs-symbol,
@@ -152,7 +152,7 @@
.swagger-section .hljs-link,
.swagger-section .hljs-selector-attr,
.swagger-section .hljs-selector-pseudo {
color: #BC6060;
color: #bc6060;
}
.swagger-section .hljs-type,
.swagger-section .hljs-string,
@@ -173,7 +173,7 @@
color: #888888;
}
.swagger-section .hljs-meta {
color: #2B6EA1;
color: #2b6ea1;
}
.swagger-section .hljs-emphasis {
font-style: italic;

View File

@@ -82,7 +82,7 @@
.swagger-section pre .vhdl .attribute,
.swagger-section pre .clojure .attribute,
.swagger-section pre .coffeescript .property {
color: #88F;
color: #8888ff;
}
.swagger-section pre .keyword,
.swagger-section pre .id,
@@ -124,11 +124,11 @@
display: block;
overflow-x: auto;
padding: 0.5em;
background: #F0F0F0;
background: #f0f0f0;
}
.swagger-section .hljs,
.swagger-section .hljs-subst {
color: #444;
color: #444444;
}
.swagger-section .hljs-keyword,
.swagger-section .hljs-attribute,
@@ -143,7 +143,7 @@
.swagger-section .hljs-bullet,
.swagger-section .hljs-code,
.swagger-section .hljs-addition {
color: #1F811F;
color: #1f811f;
}
.swagger-section .hljs-regexp,
.swagger-section .hljs-symbol,
@@ -152,7 +152,7 @@
.swagger-section .hljs-link,
.swagger-section .hljs-selector-attr,
.swagger-section .hljs-selector-pseudo {
color: #BC6060;
color: #bc6060;
}
.swagger-section .hljs-type,
.swagger-section .hljs-string,
@@ -173,7 +173,7 @@
color: #888888;
}
.swagger-section .hljs-meta {
color: #2B6EA1;
color: #2b6ea1;
}
.swagger-section .hljs-emphasis {
font-style: italic;

View File

@@ -183,6 +183,10 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(value.definition, value.models) : false,
signature: SwaggerUi.partials.signature.getModelSignature(value.name, value.definition, value.models, value.modelPropertyMacro)
};
} else {
signatureModel = {
signature: SwaggerUi.partials.signature.getPrimitiveSignature(value)
};
}
}
} else if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') {

View File

@@ -21,6 +21,7 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
var modelDefinitions = this.model.modelSignature.definitions;
var schema = this.model.schema || {};
var consumes = this.model.consumes || [];
var sampleJSON, signatureView;
if (typeof type === 'undefined') {
@@ -53,20 +54,21 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
var isXML = this.contains(consumes, 'xml');
var isJSON = isXML ? this.contains(consumes, 'json') : true;
sampleJSON = SwaggerUi.partials.signature.createParameterJSONSample(modelType, modelDefinitions);
var template = this.template();
$(this.el).html(template(this.model));
var signatureModel = {
sampleJSON: isJSON ? SwaggerUi.partials.signature.createParameterJSONSample(modelType, modelDefinitions) : false,
sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions, true) : false,
sampleJSON: isJSON ? sampleJSON : false,
sampleXML: sampleJSON && isXML ? SwaggerUi.partials.signature.createXMLSample(schema, modelDefinitions, true) : false,
isParam: true,
signature: SwaggerUi.partials.signature.getParameterModelSignature(modelType, modelDefinitions),
defaultRendering: this.model.defaultRendering
};
if (this.model.sampleJSON) {
var signatureView = new SwaggerUi.Views.SignatureView({model: signatureModel, tagName: 'div'});
if (sampleJSON) {
signatureView = new SwaggerUi.Views.SignatureView({model: signatureModel, tagName: 'div'});
$('.model-signature', $(this.el)).append(signatureView.render().el);
}
else {

View File

@@ -7,23 +7,26 @@ SwaggerUi.Views.StatusCodeView = Backbone.View.extend({
},
render: function(){
var responseModel, responseModelView;
var value = this.router.api.models[this.model.responseModel];
$(this.el).html(Handlebars.templates.status_code(this.model));
if (this.router.api.models.hasOwnProperty(this.model.responseModel)) {
var responseModel = {
responseModel = {
sampleJSON: JSON.stringify(SwaggerUi.partials.signature.createJSONSample(value), void 0, 2),
sampleXML: this.model.isXML ? SwaggerUi.partials.signature.createXMLSample(this.model.schema, value.models) : false,
sampleXML: this.model.isXML ? SwaggerUi.partials.signature.createXMLSample(this.model.schema, this.router.api.models) : false,
isParam: false,
signature: SwaggerUi.partials.signature.getModelSignature(this.model.responseModel, value, this.router.api.models),
defaultRendering: this.model.defaultRendering
};
var responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'});
$('.model-signature', this.$el).append(responseModelView.render().el);
} else {
$('.model-signature', this.$el).html('');
responseModel = {
signature: SwaggerUi.partials.signature.getPrimitiveSignature(this.model.schema)
};
}
responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'});
$('.model-signature', this.$el).append(responseModelView.render().el);
return this;
}
});

View File

@@ -736,6 +736,20 @@ SwaggerUi.partials.signature = (function () {
return value;
};
var getPrimitiveSignature = function (schema) {
var type, items;
schema = schema || {};
items = schema.items || {};
type = schema.type || '';
switch (type) {
case 'object': return 'Object is not a primitive';
case 'array' : return 'Array[' + (items.format || items.type) + ']';
default: return schema.format || type;
}
};
var createPrimitiveXML = function (descriptor) {
var name = descriptor.name;
var definition = descriptor.definition;
@@ -924,7 +938,8 @@ SwaggerUi.partials.signature = (function () {
getParameterModelSignature: getParameterModelSignature,
createParameterJSONSample: createParameterJSONSample,
createSchemaXML: createSchemaXML,
createXMLSample: createXMLSample
createXMLSample: createXMLSample,
getPrimitiveSignature: getPrimitiveSignature
};
})();

View File

@@ -1,3 +1,5 @@
{{#ifCond sampleJSON "||" sampleXML}}
<div>
<ul class="signature-nav">
<li><a class="description-link" href="#" data-sw-translate>Model</a></li>
@@ -25,3 +27,6 @@
{{/if}}
</div>
</div>
{{else}}
{{signature}}
{{/ifCond}}

View File

@@ -650,4 +650,39 @@ describe('SwaggerUi.partials.signature tests', function () {
});
});
});
describe('method getPrimitiveSignature', function () {
it('returns warning message when type is object', function () {
expect(sut.getPrimitiveSignature({type: 'object'})).to.equal('Object is not a primitive');
});
it('returns array with items.format when passing array', function () {
var schema = {
type: 'array',
items: {
format: 'format',
type: 'type'
}
};
expect(sut.getPrimitiveSignature(schema)).to.equal('Array[format]');
});
it('returns array with items.type when passing array without items.format', function () {
var schema = {
type: 'array',
items: {
type: 'type'
}
};
expect(sut.getPrimitiveSignature(schema)).to.equal('Array[type]');
});
it('returns format of primitive', function () {
expect(sut.getPrimitiveSignature({type: 'type', format: 'format'})).to.equal('format');
});
it('returns type of primitive if format is not passed', function () {
expect(sut.getPrimitiveSignature({type: 'type'})).to.equal('type');
});
});
});