我正在尝试使用Swagger 2.0定义API。在我的模型中,我有一些具有可选属性的对象,所以我试图插入Swagger标签“required:false”。
当我插入“required”标签时,我在编辑器中收到错误,我无法理解为什么......
我的Swagger定义是:
window.onload = function(){
document.getElementById("demo").innerHTML =
typeof "john" + "<br>" +
typeof 3.14 + "<br>" +
typeof false + "<br>" +
typeof [1,2,3,4] + "<br>" +
typeof {name:'john', age:34};
};
这非常有效。现在我想指定'message'参数(例如)是可选的。所以我尝试以下方法:
definitions:
Error:
type: object
properties:
code:
type: integer
message:
type: string
fields:
type: string
现在我在Swagger编辑器中出错:
definitions:
Error:
type: object
properties:
code:
type: integer
message:
type: string
required: false
fields:
type: string
错误详情如下:
Swagger Error
Expected type array but found type boolean
行:
Details
Object
code: "INVALID_TYPE"
message: "Expected type array but found type boolean"
path: Array [5]
0: "definitions"
1: "Error"
2: "properties"
3: "message"
4: "required"
level: 900
type: "Swagger Error"
description: "Expected type array but found type boolean"
lineNumber: 41
有人知道我做错了什么吗?
答案 0 :(得分:12)
如果只有代码和字段是强制性的,您可以执行以下操作:
definitions:
Error:
type: object
required: [code, fields]
properties:
code:
type: integer
message:
type: string
fields:
type: string