2017-10-21 541 views
2

我正在尝试将AVRO模式注册到模式注册表。该模式包含一个记录和一些字段。我将架构作为JSON发布到Schema Registry REST API,虽然JSON看起来很好,但服务器返回curl : {"error_code":42201,"message":"Input schema is an invalid Avro schema"}AVRO模式的JSON看起来有效,但从Kafka Schema注册表返回无效

有人可以看一下吗?

Powershell用于生成JSON模式。

$type = @{namespace="customer-actions"; name="customer-enrollment"; 
      type="record"; 
      [email protected]{name="id"; type="int"}, 
       @{name="name"; type="string"}} 
$typeJ = ConvertTo-Json $type -Depth 3 -Compress 

$schema = @{schema = "$typeJ" } 
$schemaJ = ConvertTo-Json $schema -Compress 

这将产生以下...

{"schema":"{\"type\":\"record\",\"namespace\":\"customer-actions\",\"name\":\"customer-enrollment\",\"fields\":[{\"name\":\"id\",\"type\":\"int\ 
"},{\"name\":\"name\",\"type\":\"string\"}]}"} 

这看起来非常糟糕;那些逃脱的报价都是必需的。使用相同的转义字符与更简单的模式没有问题。

在此先感谢。

[编辑] 到架构注册表API的调用,如果有帮助

curl -Uri http://server:8081/subjects/customer-enrollment/versions ` 
    -Method Post ` 
    -ContentType "application/vnd.schemaregistry.v1+json" ` 
    -Body $schemaJ 

回答

3

的问题是 - 字符名称中的客户招生

$type = @{namespace="customer-actions"; name="enrollment"; 
      type="record"; 
      [email protected]{name="id"; type="int"}, 
       @{name="name"; type="string"}} 
$typeJ = ConvertTo-Json $type -Depth 3 -Compress 

$schema = @{schema = "$typeJ" } 
$schemaJ = ConvertTo-Json $schema -Compress 

是否有当一个术语在公共论坛上发布问题后立即找到答案?

+0

validator here [AVRO Schema Validator](https://json-schema-validator.herokuapp.com/avro.jsp) –

+2

不知道一个术语,但是发生在你身上的是像[Rubber Duck Debugging](https: //en.wikipedia.org/wiki/Rubber_duck_debugging) –

+0

@LucianoAfranllie就是这样! –