Search in sources :

Example 1 with MinimumItems

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;
}
Also used : MinimumItems(io.strimzi.crdgenerator.annotations.MinimumItems) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Method(java.lang.reflect.Method)

Example 2 with MinimumItems

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;
}
Also used : MinimumItems(io.strimzi.crdgenerator.annotations.MinimumItems) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Method(java.lang.reflect.Method)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 MinimumItems (io.strimzi.crdgenerator.annotations.MinimumItems)2 Method (java.lang.reflect.Method)2