public Optional<String> maybeVisit(JsonNode schema, String baseName, String name) {
            var typeText = getTypeText(schema);

            if ((typeText == null || typeText.equals("object"))
                    && (schema.has("properties") ||
                    (schema.has("additionalProperties") &&  !schema.get("additionalProperties").asBoolean()))) {
                var required = new HashSet<String>();
                if (schema.has("required"))
                    schema.get("required").forEach(node -> required.add(node.asText()));

                var properties = new ArrayList<Map.Entry<String, JsonNode>>();
                if (schema.has("properties"))
                    schema.get("properties").fields().forEachRemaining(properties::add);

                var rule = addRule(name, generateObject(properties, required, baseName, schema.get("additionalProperties")));
                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