我想在Swagger 2.0 中声明类型模型的定义属性
这个定义正确吗?(特别是类型:StatusObject部分)
definitions:
MyObject:
type: "object"
properties:
id:
type: "number"
country:
type: "string"
status:
type: StatusObject
StatusObject:
type: "object"
properties:
code:
type: "number"
shortMessage:
type: "string"
message:
type: "string"
谢谢!
引用其他模型/定义是使用"$ref"完成的。
上面的片段应该是这样的:
definitions:
MyObject:
type: "object"
properties:
id:
type: "number"
country:
type: "string"
status:
$ref: StatusObject
StatusObject:
type: "object"
properties:
code:
type: "number"
shortMessage:
type: "string"
message:
type: "string"
另一个注释-您使用"number"作为id和代码的类型。"数字"也可以有一个小数点,我不确定你是否想要(尤其是id)。如果只需要整数,可以考虑使用"integer"。
在Swagger 2.0中:
definitions:
MyObject:
properties:
id:
type: "number"
country:
type: "string"
status:
$ref: "#/definitions/StatusObject"
StatusObject:
properties:
code:
type: "number"
shortMessage:
type: "string"
message:
type: "string"