Search in sources :

Example 1 with Alternative

use of io.strimzi.crdgenerator.annotations.Alternative in project strimzi by strimzi.

the class CrdGenerator method buildSchemaOneOf.

private ArrayNode buildSchemaOneOf(Class<?> crdClass) {
    ArrayNode alternatives;
    OneOf oneOf = crdClass.getAnnotation(OneOf.class);
    if (oneOf != null && oneOf.value().length > 0) {
        alternatives = nf.arrayNode();
        for (OneOf.Alternative alt : oneOf.value()) {
            ObjectNode alternative = alternatives.addObject();
            ObjectNode properties = alternative.putObject("properties");
            for (OneOf.Alternative.Property prop : alt.value()) {
                properties.putObject(prop.value());
            }
            ArrayNode required = alternative.putArray("required");
            for (OneOf.Alternative.Property prop : alt.value()) {
                if (prop.required()) {
                    required.add(prop.value());
                }
            }
        }
    } else {
        alternatives = null;
    }
    return alternatives;
}
Also used : OneOf(io.strimzi.crdgenerator.annotations.OneOf) Alternative(io.strimzi.crdgenerator.annotations.Alternative) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Alternative

use of io.strimzi.crdgenerator.annotations.Alternative in project strimzi-kafka-operator by strimzi.

the class CrdGenerator method buildSchemaOneOf.

private ArrayNode buildSchemaOneOf(Class<?> crdClass) {
    ArrayNode alternatives;
    OneOf oneOf = crdClass.getAnnotation(OneOf.class);
    if (oneOf != null && oneOf.value().length > 0) {
        alternatives = nf.arrayNode();
        for (OneOf.Alternative alt : oneOf.value()) {
            ObjectNode alternative = alternatives.addObject();
            ObjectNode properties = alternative.putObject("properties");
            for (OneOf.Alternative.Property prop : alt.value()) {
                properties.putObject(prop.value());
            }
            ArrayNode required = alternative.putArray("required");
            for (OneOf.Alternative.Property prop : alt.value()) {
                if (prop.required()) {
                    required.add(prop.value());
                }
            }
        }
    } else {
        alternatives = null;
    }
    return alternatives;
}
Also used : OneOf(io.strimzi.crdgenerator.annotations.OneOf) Alternative(io.strimzi.crdgenerator.annotations.Alternative) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Alternative (io.strimzi.crdgenerator.annotations.Alternative)2 OneOf (io.strimzi.crdgenerator.annotations.OneOf)2