我想在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"
谢谢!
答案 0 :(得分:26)
参考其他模型/定义是使用" $ 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"
另一条评论 - 您正在使用"数字"作为id和代码的类型。 "数"还可以有一个小数点,我不确定你想要的(尤其是id)。如果您只想要整数,请考虑使用"整数"。
答案 1 :(得分:14)
在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"