private static Json.Builder.Object generateJsonSchemaForFieldValue(DataType fieldType) {
        var field = Json.Builder.newObject();

        if (fieldType.equals(DataType.BOOL)) {
            field.set("type", "boolean");
        } else if (fieldType.equals(DataType.STRING)) {
            field.set("type", "string");
        } else if (fieldType.equals(DataType.INT) || fieldType.equals(DataType.LONG) || fieldType.equals(
                DataType.BYTE)) {
            field.set("type", "integer");
        } else if (fieldType.equals(DataType.FLOAT) || fieldType.equals(DataType.DOUBLE) || fieldType.equals(
                DataType.FLOAT16)) {
            field.set("type", "number");
        } else if (fieldType instanceof ArrayDataType arrayType) {
            field.set("type", "array");
            var itemsValue = generateJsonSchemaForFieldValue(arrayType.getNestedType());
            field.set("items", itemsValue);
        } else if (fieldType instanceof MapDataType mapType) {
            field.set("type", "object");
            var value = generateJsonSchemaForFieldValue(mapType.getValueType());
            field.set("additionalProperties", value);
        } else if (fieldType instanceof WeightedSetDataType) {
            field.set("type", "object");
            var additionalProperties = field.setObject("additionalProperties");
            additionalProperties.set("type", "integer");    
        } else if (fieldType instanceof StructDataType structType) {
            field.set("type", "object");
            var properties = field.setObject("properties");
            var required = field.setArray("required");
            field.set("additionalProperties", false);

            for (var structField : structType.getFields()) {
                var fieldName = structField.getName();
                var fieldValue = generateJsonSchemaForFieldValue(structField.getDataType());
                properties.set(fieldName, fieldValue);
                required.add(fieldName);
            }
        } else {
            throw new IllegalArgumentException("Failed to generate schema for field type %s".formatted(fieldType));
        }

        return field;
    }
Generates JSON schema for a document field value.
Schemas are compatible with JSON format used for feeding.
Not all types are supported. 
See conditions in code for supported types.
model-integration/src/main/java/ai/vespa/llm/generation/FieldGeneratorUtils.java