jsonschema2pojo
jsonschema2pojo copied to clipboard
How to resolve $ref in a CustomAnnotator?
Hello,
Given the following schema:
"some_object": {
"description": "Some description",
"items": {
"$ref": "#/definitions/max70text"
},
"maxItems": 7,
"type": "array"
}
and the following CustomAnnotator:
public class CustomAnnotator extends AbstractAnnotator {
public CustomAnnotator() {
}
public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
super.propertyField(field, clazz, propertyName, propertyNode);
}
}
I would like to be able to resolve the schema of items.$ref
so that I can annotate this property with some custom validation annotators. If I can resolve the $ref, I will be able to add a @Size
annotation, or another custom annotation based on the $ref
's values. Is it possible to resolve the $ref within this method? I tried looking into JsonNode propertyNode
but I'm unable to access the schema.
Any pointers are much appreciated!
Hi
I'm not sure if that would be possible to achieve with custom annotator.
Implementing custom rule factory might be the way to achieve that.
MinItemsMaxItemsRule/MinLengthMaxLengthRule are already applying @Size
annotation to fields, which are invoked by PropertyRule
Judging by sample schema provided what You're might be looking for has been requested in https://github.com/joelittlejohn/jsonschema2pojo/issues/1362