SwaggerUI 不会在 POST 正文参数中显示用于集合的模型架构 [英] SwaggerUI doesn't show model schema for collection in POST body parameter

查看:42
本文介绍了SwaggerUI 不会在 POST 正文参数中显示用于集合的模型架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 2014 年 6 月下载了 SwaggerUI,因为我刚刚下载了 dist 文件夹,所以不太容易找到它的版本.

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.

在这几个月里,我一直在使用 Swagger 来记录我正在用 Jersey 构建的 REST API,我发现 UI 没有在数据类型列中显示模型和模型架构,用于在我的情况下作为集合的主体参数一个列表,它只显示数组"这个词.

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.

推荐答案

我发现我的swagger.js版本中需要更新的部分是:

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:

我在 SwaggerUI github 项目问题跟踪器中发布了同样的发现:https://github.com/wordnik/swagger-ui/issues/400

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

这篇关于SwaggerUI 不会在 POST 正文参数中显示用于集合的模型架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆