首页 > 解决方案 > schema-registry JSON Schema FULL 兼容性检查

问题描述

给定以下 Kafka 主题和架构:

$kafka-json-schema-console-producer \
>       --broker-list localhost:9092 \
>       --topic topicFull \
>       --property value.schema='{"type":"object","properties":{"a":{"type":"string"}}, "required" : ["a"], "additionalProperties" : true}'
{"a" : "bip"}

兼容性FULL

# FULL compatibility
$curl -s -X GET http://localhost:8081/config/topicFull-value
{"error_code":40401,"message":"Subject 'topicFull-value' not found."}
$curl -s -X GET http://localhost:8081/config
{"compatibilityLevel":"FULL"}

我检查了添加必填字段 ,b是否兼容:

$curl -s -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"  \
>   --data '{"schemaType": "JSON", "schema": "{\"type\":\"object\",\"properties\":{\"a\":{\"type\":\"string\"}, \"b\":{\"type\":\"string\"}},\"required\":[\"a\", \"b\"],\"additionalProperties\":true}"}' \
>   http://localhost:8081/compatibility/subjects/topicFull-value/versions/1 | jq
{
  "is_compatible": false
}

API显示它不兼容。

但是,我不明白为什么添加可选字段 ,b不兼容:

$curl -s -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"  \
>   --data '{"schemaType": "JSON", "schema": "{\"type\":\"object\",\"properties\":{\"a\":{\"type\":\"string\"}, \"b\":{\"type\":\"string\"}},\"required\":[\"a\"],\"additionalProperties\":true}"}' \
>   http://localhost:8081/compatibility/subjects/topicFull-value/versions/1 | jq
{
  "is_compatible": false
}

您能解释一下为什么添加可选字段无法通过兼容性检查吗?

标签: jsonapache-kafkajsonschemaconfluent-schema-registry

解决方案


推荐阅读