从阅读another question开始,我了解到Spring Data Rest在/{resourceName}/schema
公开了一个JSON模式。例如:
GET http://localhost:8080/members/schema Accept : application/schema+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 } } }
我想表明某些字段是必需的。我最初尝试使用Bean Validation注释(@NotNull)和Jackson(@JacksonProperty)注释,但似乎都没有触发标记。
注意:我使用的是Spring Data Rest 2.2.1
答案 0 :(得分:1)
我查看了源代码,发现:
new Property(type, message, false)
我想我应该扩展PersistentEntityToJsonSchemaConverter并覆盖convert方法,然后覆盖控制器并调用我的自定义JsonSchemaConverter。