How to setup schema for entity in Spring Data Rest
Currently, I can get the JSON schema of a resource by making a GET request to / {resource} / schema (with accept: application / schema + json).
It looks like this:
{
"name" : "{java_package}.{resource_class_name}",
"description" : "rest.description.{resource_class_name}",
"links" : [ ],
"properties" : {
"{property name}" : {
"type" : "{property_type}",
"description" : "rest.description.{resource_class_name}.{property_name}",
"required" : false
}
}
}
I can't figure out how to change the name, description, or if the property is required or not. I want to look like this:
{
"name" : "{resource_name}",
"description" : "{custom_description}",
"links" : [ ],
"properties" : {
"{property_name}" : {
"type" : "{property_type}",
"description" : "{custom_property_description}",
"required" : {true or false}
}
}
}
I tried to annotate the entity class like this:
@JsonPropertyDescription(value = "{custom_property_description}")
@JsonProperty(required = {true or false})
private {property_type} {property_name};
But the end results were the same. Does anyone know how to customize the SDR return scheme?
source to share
As of SDR 2.2.X, annotate the class and domain fields with org.springframework.data.rest.core.annotation.Description
to see the description property. The "name" properties are connected to your domain class name and the "required" property is set to "false".
Example
package com.test;
@Description("Application")
public class App {
@Description("Application Name")
private String name;
}
will give
{
"name" : "com.test.App",
"description" : "Application",
"links" : [ ],
"properties" : {
"name" : {
"type" : "string",
"description" : "Application Name",
"required" : false
}
}
}
Having said that, the ticket is to validate the JSON Schema Schema that hasn't been implemented yet.
source to share