Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confluent schema-registry how to http post json-schema

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!

like image 764
bart van deenen Avatar asked Oct 29 '25 09:10

bart van deenen


1 Answers

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
like image 99
bart van deenen Avatar answered Nov 01 '25 13:11

bart van deenen