Currently I am able to generate json schema without POJO as per json schema draft 3, this is causing some issue as it is not according to the latest standards.
Problem is as per old specification the value of required can be true if the property is compulsory. But now the required can be array of property names which are required.
code:
ObjectMapper mapper = new ObjectMapper();
ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setTitle("Name");
objectSchema.setDescription("Description");
NumberSchema prop1 = new NumberSchema();
prop1.setId("Prop1");
prop1.setRequired(true);
objectSchema.putProperty("Prop1", prop1 );
JsonSchema prop2 = new ObjectSchema();
prop2.setId("Prop2");
objectSchema.putProperty("Prop2", prop2 );
try{
System.out.println(mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(objectSchema));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
output:-
{
"type":"object",
"description":"Description",
"title":"Name",
"properties":{
"Prop1":{
"type":"number",
"id":"Prop1",
"required":true
},
"Prop2":{
"type":"object",
"id":"Prop2",
"required":true
}
}
}
But i require output in this manner :-
{
"type":"object",
"description":"Description",
"title":"Name",
"properties":{
"Prop1":{
"type":"number",
"id":"Prop1"
},
"Prop2":{
"type":"object",
"id":"Prop2"
}
},
"required":[
"Prop1","Prop2"
]
}
Please help me. Thanks in advance.