implement option to control whether models are displayed as valid JSON schema or the docs rendering (with descriptions) by default
This commit is contained in:
@@ -98,6 +98,7 @@ booleanValues | SwaggerUI renders boolean data types as a dropdown. By default i
|
|||||||
docExpansion | Controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details).
|
docExpansion | Controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details).
|
||||||
apisSorter | Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
apisSorter | Apply a sort to the API/tags list. It can be 'alpha' (sort by name) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
||||||
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
operationsSorter | Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged.
|
||||||
|
defaultModelRendering | Controls how models are shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Model Schema' links.) It can be set to 'model' or 'schema', and the default is 'schema'.
|
||||||
onComplete | This is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
|
onComplete | This is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
|
||||||
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
|
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
|
||||||
highlightSizeThreshold | Any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses.
|
highlightSizeThreshold | Any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses.
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
},
|
},
|
||||||
docExpansion: "none",
|
docExpansion: "none",
|
||||||
apisSorter: "alpha",
|
apisSorter: "alpha",
|
||||||
|
defaultModelRendering: 'schema',
|
||||||
showRequestHeaders: false
|
showRequestHeaders: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ window.SwaggerUi = Backbone.Router.extend({
|
|||||||
// SwaggerUi accepts all the same options as SwaggerApi
|
// SwaggerUi accepts all the same options as SwaggerApi
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
if (options.defaultModelRendering !== 'model') {
|
||||||
|
options.defaultModelRendering = 'schema';
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.highlightSizeThreshold) {
|
if (!options.highlightSizeThreshold) {
|
||||||
options.highlightSizeThreshold = 100000;
|
options.highlightSizeThreshold = 100000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
this.parentId = this.model.parentId;
|
this.parentId = this.model.parentId;
|
||||||
this.nickname = this.model.nickname;
|
this.nickname = this.model.nickname;
|
||||||
this.model.encodedParentId = encodeURIComponent(this.parentId);
|
this.model.encodedParentId = encodeURIComponent(this.parentId);
|
||||||
|
|
||||||
|
if (opts.swaggerOptions) {
|
||||||
|
this.model.defaultRendering = opts.swaggerOptions.defaultModelRendering;
|
||||||
|
|
||||||
|
if (opts.swaggerOptions.showRequestHeaders) {
|
||||||
|
this.model.showRequestHeaders = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -174,12 +182,9 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
signature: this.model.responseClassSignature
|
signature: this.model.responseClassSignature
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var opts = this.options.swaggerOptions;
|
|
||||||
if (opts.showRequestHeaders) {
|
|
||||||
this.model.showRequestHeaders = true;
|
|
||||||
}
|
|
||||||
$(this.el).html(Handlebars.templates.operation(this.model));
|
$(this.el).html(Handlebars.templates.operation(this.model));
|
||||||
if (signatureModel) {
|
if (signatureModel) {
|
||||||
|
signatureModel.defaultRendering = this.model.defaultRendering;
|
||||||
responseSignatureView = new SwaggerUi.Views.SignatureView({
|
responseSignatureView = new SwaggerUi.Views.SignatureView({
|
||||||
model: signatureModel,
|
model: signatureModel,
|
||||||
router: this.router,
|
router: this.router,
|
||||||
@@ -238,6 +243,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
addParameter: function(param, consumes) {
|
addParameter: function(param, consumes) {
|
||||||
// Render a parameter
|
// Render a parameter
|
||||||
param.consumes = consumes;
|
param.consumes = consumes;
|
||||||
|
param.defaultRendering = this.model.defaultRendering;
|
||||||
var paramView = new SwaggerUi.Views.ParameterView({
|
var paramView = new SwaggerUi.Views.ParameterView({
|
||||||
model: param,
|
model: param,
|
||||||
tagName: 'tr',
|
tagName: 'tr',
|
||||||
@@ -248,6 +254,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
|
|||||||
|
|
||||||
addStatusCode: function(statusCode) {
|
addStatusCode: function(statusCode) {
|
||||||
// Render status codes
|
// Render status codes
|
||||||
|
statusCode.defaultRendering = this.model.defaultRendering;
|
||||||
var statusCodeView = new SwaggerUi.Views.StatusCodeView({
|
var statusCodeView = new SwaggerUi.Views.StatusCodeView({
|
||||||
model: statusCode,
|
model: statusCode,
|
||||||
tagName: 'tr',
|
tagName: 'tr',
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({
|
|||||||
var signatureModel = {
|
var signatureModel = {
|
||||||
sampleJSON: this.model.sampleJSON,
|
sampleJSON: this.model.sampleJSON,
|
||||||
isParam: true,
|
isParam: true,
|
||||||
signature: this.model.signature
|
signature: this.model.signature,
|
||||||
|
defaultRendering: this.model.defaultRendering
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.model.sampleJSON) {
|
if (this.model.sampleJSON) {
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({
|
|||||||
|
|
||||||
$(this.el).html(Handlebars.templates.signature(this.model));
|
$(this.el).html(Handlebars.templates.signature(this.model));
|
||||||
|
|
||||||
|
if (this.model.defaultRendering === 'model') {
|
||||||
|
this.switchToDescription();
|
||||||
|
} else {
|
||||||
this.switchToSnippet();
|
this.switchToSnippet();
|
||||||
|
}
|
||||||
|
|
||||||
this.isParam = this.model.isParam;
|
this.isParam = this.model.isParam;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ SwaggerUi.Views.StatusCodeView = Backbone.View.extend({
|
|||||||
sampleJSON: JSON.stringify(this.router.api.models[this.model.responseModel].createJSONSample(), null, 2),
|
sampleJSON: JSON.stringify(this.router.api.models[this.model.responseModel].createJSONSample(), null, 2),
|
||||||
isParam: false,
|
isParam: false,
|
||||||
signature: this.router.api.models[this.model.responseModel].getMockSignature(),
|
signature: this.router.api.models[this.model.responseModel].getMockSignature(),
|
||||||
|
defaultRendering: this.model.defaultRendering
|
||||||
};
|
};
|
||||||
|
|
||||||
var responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'});
|
var responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'});
|
||||||
|
|||||||
Reference in New Issue
Block a user