我创建了一个招摇规范
/config/download:
post:
summary: Download config
consumes:
- application/json
produces:
- application/zip
parameters:
- in: body
name: config
schema:
type: array
items:
title: config files
description: All config file name that need to be downloaded
type: string
minItems: 0
maxItems: 1024
responses:
200:
description:
schema:
type: string
format: binary
我正在通过 go-swagger 编译这个 swagger 规范,我也为此实现了后端
但是当我尝试卷曲这个请求时,我得到了
curl -i http://127.0.0.1:<port>/config/download -X "POST" -d '{"config": ["config1.json", "config.json"]}' -H "Content-Type: application/json"
HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Tue, 02 Feb 2021 07:36:06 GMT
Content-Length: 132
Connection: close
{"code":400,"message":"parsing config body from \"\" failed, because json: cannot unmarshal object into Go value of type []string"}
我认为 curl 没有问题,但 swagger 规范似乎也是正确的,那么可能是什么问题。从 curl 错误消息中可以清楚地看出,服务器没有正确处理这个请求,甚至没有到达后端实现代码。
任何建议表示赞赏。