2017-10-21 133 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就是這樣! –