SwaggerUI doesn't show model schema for collec

2019-07-22 15:39发布

问题:

I downloaded SwaggerUI in June 2014, it is not easy for me to find out what version it was as I just downloaded the dist folder.

In these months I've been using Swagger for documenting the REST API I am building with Jersey, I found that the UI was not showing the model and model schema in the Data Type column for body parameters that are collections in my case a List, it only shows the word "array".

It seems that this issue is solved in newer versions, however I made several customization to the code and downloading the new version is not an option for me.

I want to know what part of the code I should modify to make this work.

回答1:

I found the part that needs to be updated in my version of swagger.js is:

SwaggerOperation = (function() {
...
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i];
parameter.name = parameter.name || parameter.type || parameter.dataType;
type = parameter.type || parameter.dataType;

// ++++ Add this:
if(type === 'array') {
type = 'array[' + parameter.items.$ref + ']';
}
// ++++

if (type.toLowerCase() === 'boolean') {
parameter.allowableValues = {};
parameter.allowableValues.values = ["true", "false"];
}
...

After that the parameter view looks like this:

I posted this same finding in the SwaggerUI github project issue tracker: https://github.com/wordnik/swagger-ui/issues/400