我对json说道.在定义我的RESTful API结果的格式(即JSON)时,我觉得将它作为我自己的JSON模式进行记录会更容易.写一篇文章的时候我几乎没有问题:
$schema属性?$schema.[忽略这一行,这是为了让格式化为后面的json ..]
{
"date":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
},
"personInfo":{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"dateOfBirth":{
"type":"date"
}
}
},
"student":{
"type":"object",
"properties":{
"id":{
"type":"personInfo"
},
"pass_out_year":{
"type":"date"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
而不是在多个地方提供"日期"的属性,如下所示:
{
"personInfo":{
"type":"object",
"properties":{
"name":{
"type":"string"
},
"dateOfBirth":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
}
}
},
"student":{
"type":"object",
"properties":{
"id":{
"type":"personInfo"
},
"pass_out_year":{
"type":"object",
"properties":{
"month":{
"type":"integer",
"minimum":1,
"maximum":12
},
"year":{
"type":"integer",
"minimum":0
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
根据规范中的 5.1类型,它是不可能的,但它似乎是这样一个基本的用例!
| 归档时间: |
|
| 查看次数: |
7142 次 |
| 最近记录: |