我正在使用Jackson jsonSchema(https://github.com/FasterXML/jackson-module-jsonSchema)来自动化我的数据模型的模式创建。
根据http://json-schema.org/和jsonSchema中提供的示例,json shema使用的格式包含链接
{
"name":"Product",
"properties":{
"id":{
"type":"number",
"description":"Product identifier",
"required":true
},
"name":{
"description":"Name of the product",
"type":"string",
"required":true
},
"price":{
"required":true,
"type": "number",
"minimum":0,
"required":true
},
"tags":{
"type":"array",
"items":{
"type":"string"
}
}
},
"links":[
{
"rel":"full",
"href":"{id}"
},
{
"rel":"comments",
"href":"comments/?id={id}"
}
]
}
但我无法找到将其添加到生成的架构的方法,尽管有一个HyperSchema对象,这似乎是我需要的,但我找不到如何使用它。
答案 0 :(得分:1)
在json-schema项目中出现问题,并在表单中基于注释支持HyperSchema的拉取请求
https://github.com/FasterXML/jackson-module-jsonSchema/issues/35
public class Pet {
public String genus;
}
@JsonHyperSchema(pathStart = "/persons/", links = {
@Link(href = "{name}", rel = "self"),
@Link(href = "{name}/pet", rel = "pet", targetSchema = Pet.class)
})
public class Person {
public String name;
public String hat;
}