Java SpringDataREST:如何使json模式属性成为必需的?
通过阅读,我了解到SpringDataREST在以下位置公开了一个JSON模式:Java SpringDataREST:如何使json模式属性成为必需的?,java,json,jackson,jsonschema,spring-data-rest,Java,Json,Jackson,Jsonschema,Spring Data Rest,通过阅读,我了解到SpringDataREST在以下位置公开了一个JSON模式:/{resourceName}/schema。例: GET http://localhost:8080/members/schema Accept : application/schema+json 得到http://localhost:8080/members/schema 接受:应用程序/schema+json { “名称”:“org.jxc876.model.Member”, “description”:“re
/{resourceName}/schema
。例:
GET http://localhost:8080/members/schema
Accept : application/schema+json
得到http://localhost:8080/members/schema
接受:应用程序/schema+json
{
“名称”:“org.jxc876.model.Member”,
“description”:“rest.description.member”,
“链接”:[],
“财产”:{
“id”:{
“类型”:“长”,
“description”:“rest.description.member.id”,
“必需”:false
},
“别名”:{
“类型”:“字符串”,
“description”:“rest.description.member.alias”,
“必需”:false
},
“姓名”:{
“类型”:“字符串”,
“description”:“rest.description.member.name”,
“必需”:false
}
}
}
我想指出某些字段是必需的。我最初尝试使用Bean验证注释(@NotNull)和Jackson(@JacksonProperty)注释,但这两种注释似乎都没有触发标志
注意:我使用的是Spring数据Rest 2.2.1我查看了源代码,发现:
- -映射到/{repository}/schema
-
- 包含一个convert(Object、TypeDescriptor、TypeDescriptor)方法,用于创建Json模式
- 使用另一个类及其嵌套的内部类(属性)
- 该属性包含3个字段:类型、说明、必填项
- 构造函数调用似乎被硬编码为始终使用false:
new属性(type,message,false)
我想我应该扩展PersistentEntityToJsonSchemaConverter并重写convert方法,然后重写控制器并调用我的自定义JsonSchemaConverter SDR生成的架构不符合JSON架构。然而,有人要求支持JSON模式和超模式,这是正确的选择。我建议你投票/评论这张票,把它排在队伍前面。你好,迈克,你试过了吗?如果是这样,请告诉我们你的经历,这是否可能。 { "name": "org.jxc876.model.Member", "description": "rest.description.member", "links": [], "properties": { "id": { "type": "long", "description": "rest.description.member.id", "required": false }, "alias": { "type": "string", "description": "rest.description.member.alias", "required": false }, "name": { "type": "string", "description": "rest.description.member.name", "required": false } } }