3

Confluent 5.5.0 understands not just Avro schemas, but also json-schema and protobuf. I have a valid json-schema that I'm trying to curl to the schema registry server, but I keep getting the response

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
     --data @$tmpfile ${schemaregistry}/subjects/${topic}-value/versions?schemaType=JSONSCHEMA
{"error_code":42201,"message":"Either the input schema or one its references is invalid"}

The manual is unclear about how to use the schemaType parameter. I've tried as a query parameter, as a field in the json, ... The $tmpfile I'm posting is a json with one top-level field named schema that contains a quote-escaped json-schema. The same mechanism works perfectly for Avro schemas.

Looking in the logging from the schema registry, I see that it tries to parse the provided data as an Avro schema, so no wonder it fails.

Any help? And Confluent: please clarify and fix your documentation!

bart van deenen
  • 661
  • 6
  • 16

2 Answers2

6

Ah I got it. The documentation is unclear and wrong!

You have to add a field inside the posted json. The field name is schemaType, and its value must be JSON, and not JSONSCHEMA (what the documentation says).

For others here's an example that shows how to put local files with an avro and json schema into the schema-registry:

#!/bin/bash
schemaregistry="$1"
tmpfile=$(mktemp)

topic=avro-topic
export SCHEMA=$(cat schema.avsc)
echo '{"schema":""}' | jq --arg schema "$SCHEMA" '.schema = $schema' \
   > $tmpfile
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
    --data @$tmpfile ${schemaregistry}/subjects/${topic}-value/versions

topic=json-topic
export SCHEMA=$(cat schema.json)
echo '{"schema":"","schemaType":"JSON"}' | jq --arg schema "$SCHEMA" '.schema = $schema' \
   > $tmpfile
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
    --data @$tmpfile ${schemaregistry}/subjects/${topic}-value/versions
rm $tmpfile
bart van deenen
  • 661
  • 6
  • 16
1

According to the Confluent schema registry API documentation one can check the supported schema types by calling

curl --silent -X GET http://localhost:8081/schemas/types

This should result in

["JSON","PROTOBUF","AVRO"]

for the current version (5.5) so the output might help to set a proper schemaType-attribute.

Nonetheless as @bart van deenen pointed out here, the API doc is (still) wrong.

hecke
  • 236
  • 1
  • 6