use of io.strimzi.crdgenerator.annotations.MinimumItems in project strimzi by strimzi.
the class CrdGenerator method buildArraySchema.
@SuppressWarnings("unchecked")
private ObjectNode buildArraySchema(ApiVersion crApiVersion, Property property, PropertyType propertyType, boolean description) {
int arrayDimension = propertyType.arrayDimension();
ObjectNode result = nf.objectNode();
ObjectNode itemResult = result;
for (int i = 0; i < arrayDimension; i++) {
itemResult.put("type", "array");
MinimumItems minimumItems = selectVersion(crApiVersion, property, MinimumItems.class);
if (minimumItems != null) {
result.put("minItems", minimumItems.value());
}
itemResult = itemResult.putObject("items");
}
Class<?> elementType = propertyType.arrayBase();
if (String.class.equals(elementType)) {
itemResult.put("type", "string");
} else if (Integer.class.equals(elementType) || int.class.equals(elementType) || Long.class.equals(elementType) || long.class.equals(elementType)) {
itemResult.put("type", "integer");
} else if (Map.class.equals(elementType)) {
preserveUnknownFields(itemResult);
itemResult.put("type", "object");
} else if (elementType.isEnum()) {
itemResult.put("type", "string");
try {
Method valuesMethod = elementType.getMethod("values");
itemResult.set("enum", enumCaseArray((Enum[]) valuesMethod.invoke(null)));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} else {
buildObjectSchema(crApiVersion, itemResult, elementType, true, description);
}
return result;
}
use of io.strimzi.crdgenerator.annotations.MinimumItems in project strimzi-kafka-operator by strimzi.
the class CrdGenerator method buildArraySchema.
@SuppressWarnings("unchecked")
private ObjectNode buildArraySchema(ApiVersion crApiVersion, Property property, PropertyType propertyType, boolean description) {
int arrayDimension = propertyType.arrayDimension();
ObjectNode result = nf.objectNode();
ObjectNode itemResult = result;
for (int i = 0; i < arrayDimension; i++) {
itemResult.put("type", "array");
MinimumItems minimumItems = selectVersion(crApiVersion, property, MinimumItems.class);
if (minimumItems != null) {
result.put("minItems", minimumItems.value());
}
itemResult = itemResult.putObject("items");
}
Class<?> elementType = propertyType.arrayBase();
if (String.class.equals(elementType)) {
itemResult.put("type", "string");
} else if (Integer.class.equals(elementType) || int.class.equals(elementType) || Long.class.equals(elementType) || long.class.equals(elementType)) {
itemResult.put("type", "integer");
} else if (Map.class.equals(elementType)) {
preserveUnknownFields(itemResult);
itemResult.put("type", "object");
} else if (elementType.isEnum()) {
itemResult.put("type", "string");
try {
Method valuesMethod = elementType.getMethod("values");
itemResult.set("enum", enumCaseArray((Enum[]) valuesMethod.invoke(null)));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} else {
buildObjectSchema(crApiVersion, itemResult, elementType, true, description);
}
return result;
}
Aggregations