Pojo to Json Schema

Viewed 1024

I have the below Json string

{
"name": "Mr Xyz"
}

Java model class for the above JSON looks like below

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"name"
})
public class Test {

@JsonProperty("name")
@JsonPropertyDescription("Non Zero Length String")
@Size(min = 1)
@NotNull
private String name;

Jackson API for the below Test.class Java object generates the below json schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Test",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "name": {
            "type": "string",
            "minLength": 1,
            "description": "Non Zero Length String"
        }
    },
    "required": [
        "name"
    ]
}

My question is how do i change my Java pojo object so it can generate the schema like below

{
    "$id": "test id",
    "$schema": "http://json-schema.org/draft-07/schema",
    "title": "Test title",
    "description": "test description",
    "type": "object",
    "properties": {
        "name": {
            "$ref": "#/definitions/d_NonZeroLengthString"
        }
    },
    "definitions": {
        "d_NonZeroLengthString": {
            "description": "Non Zero Length String",
            "type": "string",
            "minLength": 1
        }
    }
}
1 Answers
Related