我使用Swagger编辑器构建上传文件的帖子请求。我的swagger json文件定义如下。
swagger: '2.0'
info:
version: 0.0.0
title: '<enter your title>'
host: 'localhost:11235'
paths:
/form/upload:
post:
description: |
Post files.
consumes:
- multipart/form-data
produces:
- application/octet-stream
parameters:
- name: file
in: formData
description: upload file
required: true
type: file
- name: text
description: additional info
in: formData
type: string
responses:
'200':
description: Successful response
schema:
type: file
然后在编辑器的右侧。我单击“尝试此操作”。我选择了一个文件。构造的请求看起来像这样。
POST http://localhost:11235/form/upload HTTP/1.1
....
Content-Length: 40
Content-Type: multipart/form-data
file: C:\fakepath\swagger.json
text: 123
文件内容不会在请求中传输。只有文件名写入请求。这是因为招摇编辑器不支持文件上传或我的招摇json是错误的吗?有人可以帮我这个吗?感谢。
答案 0 :(得分:1)
swagger-editor仍有一个未解决的问题: https://github.com/swagger-api/swagger-editor/issues/599
据报道,它已在swagger-api中修复: https://github.com/swagger-api/swagger-ui/issues/838
使用swagger-ui进行文件上传,它正在运行:
- in: formData
name: document
description: Documento Fiscal
required: true
type: file