AVRO schema's JSON looks valid but returns invalid from Kafka Schema Registry
Asked Answered
D

1

8

I am trying to register an AVRO schema to Schema Registry. The schema contains a record and some fields. I post the schema as JSON to Schema Registry REST API and although the JSON look fine the server returns curl : {"error_code":42201,"message":"Input schema is an invalid Avro schema"}.

Could someone please have a look?

Powershell is used to produce the schema as JSON.

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

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

This produces the following...

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

Which looks really bad; those escaped quotes are all required. The same escaped characters are used with simpler schema without problems.

Thanks in advance.

[Edit] The call to Schema Registry API if it helps

curl -Uri http://server:8081/subjects/customer-enrollment/versions `
     -Method Post `
     -ContentType "application/vnd.schemaregistry.v1+json" `
     -Body $schemaJ
Daley answered 21/10, 2017 at 16:30 Comment(0)
D
13

The problem was the - character in the name customer-enrollment

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

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

Is there a term for when you find the answer yourself immediately after posting a question in a public forum?

Daley answered 21/10, 2017 at 16:41 Comment(4)
validator here AVRO Schema ValidatorDaley
Not sure if a term but what happened to you is like Rubber Duck DebuggingLyall
The validator link ^ was really helpful because in my case the type was incorrect. it does not take "integer" but "int"Halfhardy
Thanks for the validator link!Mckissick

© 2022 - 2024 — McMap. All rights reserved.