如何在Swagger(OpenAPI)中发布文件? [英] How to post files in Swagger (OpenAPI)?
问题描述
我正在使用Swagger记录我的REST服务.我的一项服务要求上传CSV文件.我在JSON API定义的parameters
部分中添加了以下内容:
I am using Swagger to document my REST services. One of my services requires a CSV file to be uploaded. I added the following to the parameters
section in my JSON API definition:
{
"name": "File",
"description": "The file in zip format.",
"paramType": "body",
"required": true,
"allowMultiple": false,
"dataType": "file"
}
,现在我在Swagger UI页面上看到了文件上传选项.但是,当我选择一个文件并单击试用"时,出现以下错误:
and now I see the file upload option on my Swagger UI page. But when I select a file and click "try it out", I get the following error:
NS_ERROR_XPC_BAD_OP_ON_WN_PROTO:对jquery-1.8.0.min.js中的WrappedNative原型对象进行非法操作(第2行)
NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object in jquery-1.8.0.min.js (line 2)
页面正在持续处理,但没有收到任何答复.
The page is continuously processing and I am not getting any response.
任何想法可能有什么问题吗?
Any ideas what could be wrong?
推荐答案
我终于找到了答案,实际上以前以前不支持文件上传,现在他们更新了 swagger-ui.js 文件.您需要用新的替换旧的,并且还必须在参数"下为特定参数定义以下属性:
finally i found answer for this, actually previously there is no support for file upload, now they updated swagger-ui.js file. You need to replace your old one with new and also you have to define these properties under Parameters for particular parameter:
"paramType": "body",
"dataType": "file",
这篇关于如何在Swagger(OpenAPI)中发布文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!