public Optional<String> maybeVisit(JsonNode schema, String baseName, String name) {
            var type = schema.get("type");

            if (type != null && type.isArray()) {
                var modSchemas = new ArrayList<JsonNode>();

                for (Iterator<JsonNode> it = type.elements(); it.hasNext(); ) {
                    var t = it.next();
                    var schemaCopy = schema.deepCopy();
                    ((ObjectNode) schemaCopy).set("type", t);
                    modSchemas.add(schemaCopy);
                }

                var rule = addRule(name, generateUnion(baseName, modSchemas));
                return Optional.of(rule);
            }

            return Optional.empty();
        }
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