Swagger Integer类型会导致一个预期的错误`falue for Value,get`1`
我正在尝试描述身体参数,但有错误。这是我的swagger.json
文件:
{
"swagger": "2.0",
"info": {
"title": "Simple API overview",
"version": "v2"
},
"host": "localhost:4000",
"basePath": "/",
"paths": {
"/user/register": {
"post": {
"operationId": "register",
"summary": "User registration",
"parameters": [{
"in": "body",
"name": "role",
"required": true,
"schema": {
"type": "integer",
"example": 1
}
}]
}
}
}
}
当我尝试运行它时,我会发现一个错误:
Error: Expected `string` for value, got `1`
如果删除示例
字段,我在示例值部分中得到了此信息:
{}
看起来像类型定义是不正确的,但是我无法弄清楚我的代码和Swagger文档示例有什么区别。
I'm trying to describe body parameters, but got an error. Here is my swagger.json
file:
{
"swagger": "2.0",
"info": {
"title": "Simple API overview",
"version": "v2"
},
"host": "localhost:4000",
"basePath": "/",
"paths": {
"/user/register": {
"post": {
"operationId": "register",
"summary": "User registration",
"parameters": [{
"in": "body",
"name": "role",
"required": true,
"schema": {
"type": "integer",
"example": 1
}
}]
}
}
}
}
When I try to run it, I got an error:
Error: Expected `string` for value, got `1`
If I remove example
field, I got this in Example Value section:
{}
Looks like the type definition is incorrect, but I couldn't figure out what's the difference between my code and examples from swagger docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现原因是:应该有
消耗
字段定义为text/plain
。默认情况下,它是application/json
。完整代码:
I found the reason: there should be
consumes
field defined astext/plain
. By default it isapplication/json
.The full code:
解决此错误的一种方法是将类型从整数更改为字符串。
One way to get around this error is to change type from integer to string.