I want to generate JSON schema where "additionalProperties" : false
will be applied for all classes which I have.
Suppose I have following classes:
class A{
private String s;
private B b;
public String getS() {
return s;
}
public B getB() {
return b;
}
}
class B{
private BigDecimal bd;
public BigDecimal getBd() {
return bd;
}
}
When I am generating schema as following like below code the schema property "additionalProperties" : false
was applying only for the class A
.
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
ObjectSchema schema = schemaGen.generateSchema(A.class).asObjectSchema();
schema.rejectAdditionalProperties();
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
How can I generate the schema where "additionalProperties" : false
will be applied on all classes?
Example of schema
{
"type" : "object",
"id" : "urn:jsonschema:com.xxx.xxx:A",
"additionalProperties" : false,
"properties" : {
"s" : {
"type" : "string"
},
"b" : {
"type" : "object",
"id" : "urn:jsonschema:com.xxx.xxx:B",
"properties" : {
"bd" : {
"type" : "number"
}
}
}
}
}
Note: I don't want to generate schemes part by part.
For info: I have opened issue for this scenario if someone interested you can support fix of this issue. Generate json schema which should rejects all additional content