private String getAttributeType()

in karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionGenerator.java [99:131]


    private String getAttributeType(String stepName, JsonObject attribute, boolean required, JsonObject definitions, String generatedValue) {
        if (attribute.containsKey("$ref")) {
            String classFullName = attribute.getString("$ref");
            JsonObject clazz = getDefinition(definitions, classFullName);
            String oneOfString = (clazz.containsKey("oneOf") && clazz.getJsonArray("oneOf").getJsonObject(0).getString("type").equals("string")) ? " | string" : "";
            String className = classSimple(classFullName);
            if (className.equals("SagaActionUriDefinition")) return "string" + (required ? " = ''" : ""); // exception for SagaActionUriDefinition
            if (className.equals("ToDefinition")) return "string" + (required ? " = ''" : ""); // exception for ToDefinition (in REST Methods)
            if (className.equals("ToDynamicDefinition")) return "string" + (required ? " = ''" : ""); // exception for ToDynamicDefinition (in REST Methods)
            return className + (required ? " = new " + className + "()" : oneOfString);
        } else if (attribute.containsKey("type") && attribute.getString("type").equals("array")) {
            JsonObject items = attribute.getJsonObject("items");
            if (items.containsKey("$ref") && items.getString("$ref").equals("#/items/definitions/org.apache.camel.model.ProcessorDefinition")) {
                return "CamelElement[] = []";
            } else if (items.containsKey("$ref")) {
                String className = classSimple(items.getString("$ref"));
                return className + "[] = []";
            } else if (items.containsKey("properties") && items.getJsonObject("properties").containsKey(stepName)) {
                String className = classSimple(items.getJsonObject("properties").getJsonObject(stepName).getString("$ref"));
                return className + "[] = []";
            } else {
                return items.getString("type") + "[] = []";
            }
        } else if (attribute.containsKey("type") && attribute.getString("type").equals("object")) {
            return "any = {}";
        } else if (attribute.containsKey("type") && attribute.getString("type").equals("number")) {
            String defaultValue = generatedValue != null ? " = " + generatedValue : (required ? " = 0" : "");
            return attribute.getString("type") + defaultValue;
        } else {
            String defaultValue = generatedValue != null ? " = " + generatedValue : (required ? " = ''" : "");
            return attribute.getString("type") + defaultValue;
        }
    }