How to solve when using configpart.withInstanceAttributeOverride() on array field, the new Node will be added to items Node #270
-
configPart.withInstanceAttributeOverride(((objectNode, fieldScope, context) -> {
final JsonSchemaProperty arraySchema = fieldScope.getAnnotationConsideringFieldAndGetter(JsonSchemaProperty.class);
if (arraySchema != null) {
if (arraySchema.prefixItems().length != ZERO) {
PrefixItems[] items = arraySchema.prefixItems();
final ArrayNode node = objectNode.withArray(MoyeSchemaKeyword.PREFIX_ITEMS);
for (PrefixItems item : items) {
final String name = item.name();
final String value = item.value();
ObjectNode itemNode = createObjectNode();
itemNode.put(name, value);
node.add(itemNode);
}
objectNode.put(MoyeSchemaKeyword.ITEMS, "false");
}
if (arraySchema.maxContains() != -1) {
objectNode.put(MoyeSchemaKeyword.MAX_CONTAINS, arraySchema.maxContains());
}
if (arraySchema.minContains() != -1) {
objectNode.put(MoyeSchemaKeyword.MIN_CONTAINS, arraySchema.minContains());
}
}
})) the schema is shown below. the "prefixItems" is added "items" node {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"oneTest": {
"prefixItems": [
{
"type": "String.class"
},
{
"enum": "NW, NE, SW, SE"
}
],
"items": {
"type": "integer",
"prefixItems": [
{
"type": "String.class"
},
{
"enum": "NW, NE, SW, SE"
}
],
"items": "false"
},
"type": "array"
}
}
} thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The corresponding part from the documentation is this (point 3 in the yellow box):
The schema generation will be triggered twice on a field/method with a collection type.
In your case, you should only consider your annotation's Further notes to your example:
|
Beta Was this translation helpful? Give feedback.
Hi @manchuanxingmengyaxinhe,
The corresponding part from the documentation is this (point 3 in the yellow box):
https://victools.github.io/jsonschema-generator/#generator-individual-configurations
The schema generation will be triggered twice on a field/method with a collection type.
FieldScope
in your case would return:get…