private String generateRepetition(String itemRule, int minItems, Integer maxItems, String separatorRule) {
        if (minItems == 0 && maxItems != null && maxItems == 1) {
            return itemRule + "?";
        }

        if (separatorRule == null) {
            if (minItems == 1 && maxItems == null) {
                return itemRule + "+";
            } else if (minItems == 0 && maxItems == null) {
                return itemRule + "*";
            } else {
                return itemRule + "{" + minItems + "," + (maxItems != null ? maxItems : "") + "}";
            }
        }

        String result = itemRule + " " + generateRepetition(
                "(" + separatorRule + " " + itemRule + ")",
                minItems > 0 ? minItems - 1 : 0,
                maxItems != null ? maxItems - 1 : null,
                null
        );

        return (minItems == 0) ? "(" + result + ")?" : result;
    }
Converts a JSON Schema to a GBNF grammar to be used for structured output with llama.cpp.
It is a port of Python implementation from llama.cpp repository.
Current implementation doesn't support regex patterns, resolving $ref or fetching schemas from URLs.
The plan is to replace this with C++ implementation from llama.cpp though JNI.
model-integration/src/main/java/ai/vespa/llm/clients/JsonSchemaToGrammar.java