我正在尝试使用Swagger 2.0定义API.在我的模型中,我有一些具有可选属性的对象,所以我试图插入Swagger标签"required:false".
当我插入"required"标签时,我在编辑器中收到错误,我无法理解为什么..
我的Swagger定义是:
definitions: Error: type: object properties: code: type: integer message: type: string fields: type: string
这非常有效.现在我想指定'message'参数(例如)是可选的.所以我尝试以下方法:
definitions: Error: type: object properties: code: type: integer message: type: string required: false fields: type: string
现在我在Swagger编辑器中出错:
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
行:
[40] message: [41] type: string [42] required: false
有人知道我做错了什么吗?
如果只有代码和字段是强制性的,您可以执行以下操作:
definitions: Error: type: object required: [code, fields] properties: code: type: integer message: type: string fields: type: string