Kafka Connect JSON Schema 似乎不支持"$ref"标记



我正在使用Kafka连接JSONSchema和我在一个情况下,我需要在Kafka连接插件内手动转换JSON模式(到" schema ")。我可以成功地检索JSON模式从模式注册表和我成功转换简单的JSON模式,但我有困难与那些复杂的,有有效的"在一个JSON Schema定义中引用组件的标签。

我有几个问题:

  1. JsonConverter.java似乎没有处理"$ref"。我说的对吗,还是在其他地方用另一种方式处理?
  2. 模式注册表是否处理子定义的引用?如果是,是否有代码显示如何处理解引用?
  3. JSON Schema应该被解析为一个没有引用的字符串吗?内联引用),然后提交到架构注册中心,从而删除"$ref"的问题?

我正在查看下面的Kafka源代码模块JsonConverter.java:

https://github.com/apache/kafka/blob/trunk/connect/json/src/main/java/org/apache/kafka/connect/json/JsonConverter.java#L428
下面是一个复杂模式的例子(取自JSON模式站点)(注意"$ref"; "#/$defs/veggie"标记引用(稍后的子定义)
{
"$id": "https://example.com/arrays.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A representation of a person, company, organization, or place",
"title": "complex-schema",
"type": "object",
"properties": {
"fruits": {
"type": "array",
"items": {
"type": "string"
}
},
"vegetables": {
"type": "array",
"items": { "$ref": "#/$defs/veggie" }
}
},
"$defs": {
"veggie": {
"type": "object",
"required": [ "veggieName", "veggieLike" ],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
}
}
}
}
}

下面是模式注册成功后从模式注册中心返回的实际模式:

[
{
"subject": "complex-schema",
"version": 1,
"id": 1,
"schemaType": "JSON",
"schema": "{"$id":"https://example.com/arrays.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","description":"A representation of a person, company, organization, or place","title":"complex-schema","type":"object","properties":{"fruits":{"type":"array","items":{"type":"string"}},"vegetables":{"type":"array","items":{"$ref":"#/$defs/veggie"}}},"$defs":{"veggie":{"type":"object","required":["veggieName","veggieLike"],"properties":{"veggieName":{"type":"string","description":"The name of the vegetable."},"veggieLike":{"type":"boolean","description":"Do I like this vegetable?"}}}}}"
}
]

实际的模式嵌入在上面返回的字符串中("模式"的内容;字段)并包含$ref引用:

{"$id":"https://example.com/arrays.schema.json","$schema":"https://json-schema.org/draft/2020-12/schema","description":"A representation of a person, company, organization, or place","title":"complex-schema","type":"object","properties":{"fruits":{"type":"array","items":{"type":"string"}},"vegetables":{"type":"array","items":{"$ref":"#/$defs/veggie"}}},"$defs":{"veggie":{"type":"object","required":["veggieName","veggieLike"],"properties":{"veggieName":{"type":"string","description":"The name of the vegetable."},"veggieLike":{"type":"boolean","description":"Do I like this vegetable?"}}}}}

同样,Apache Kafka源代码中的JsonConverter没有JSONSchema的概念,因此,不,$ref不能工作,它也不能与注册表集成。

你似乎在寻找io.confluent.connect.json.JsonSchemaConverter类+逻辑