null
null

Reputation: 449

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

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

Upvotes: 8

Views: 14961

Answers (1)

null
null

Reputation: 449

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?

Upvotes: 13

Related Questions