apache-kafka - Kafka Connect JSON 模式似乎不支持“$ref”标签
问题描述
我正在使用带有 JSONSchema 的 Kafka Connect,并且需要在 Kafka Connect 插件中手动转换 JSON 模式(转换为“模式”)。我可以成功地从模式注册表中检索 JSON 模式,并成功地使用简单的 JSON 模式进行转换,但是对于那些复杂且具有引用单个 JSON 模式定义中组件的有效“$ref”标签的模式,我遇到了困难。
我有几个问题:
- JsonConverter.java 似乎无法处理“$ref”。我是正确的,还是它在其他地方以其他方式处理它?
- Schema Registry 是否处理子定义的引用?如果是,是否有代码显示如何处理取消引用?
- JSON Schema 是否应该在提交给 Schema Registry 之前解析为没有引用的字符串(即内联引用),从而消除“$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 Schema 站点)(注意 "$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?\"}}}}}
解决方案
同样,JsonConverter
Apache Kafka 源代码中没有 JSONSchema 的概念,因此,不,$ref
它不起作用,它也没有与注册表集成。
推荐阅读
- c# - C# TimeSpan 秒和毫秒不同步
- azure - 以编程方式访问 Azure 数据工厂数据集表源
- c - Getting GLib warning on passing struct as arg to G_CALLBACK
- java - 按顺序编写数组的多次迭代
- php - 使用 PHP 和 SQL Server 将日期时间转换为字符串时出现问题
- php - 在codeigniter中使用表单数据上传单个文件
- google-apps-script - 需要编辑 Google 脚本以复制一行并移动到另一张工作表
- permissions - 动态请求 Google Docs 插件的权限
- git - git --version 命令返回与实际安装的结果不同的结果
- f# - 从 IList 中删除空字符串或空白字符串
在 F#