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!
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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With