Reputation: 11597
The 'simple' syntax for adding an entry in Schema registry goes this way :
curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{\"type\":\"record\",\"name\":\"Payment\",\"namespace\":\"io.confluent.examples.clients.basicavro\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"amount\",\"type\":\"double\"}]}"}' http://localhost:8081/subjects/test-value/versions
However, when doing it from terminal, if the schema is large, this can be pretty heavy and unpractical. Is there a convenient way not to blot the curl command with the inline schema (i.e the schema content), and just pass an avro schema file (avsc) ?
I know there is a python tool that does that :
$ python register_schema.py http://localhost:8081 persons-avro person.avsc
I am also aware I can do it (with much boilerplate code) in Java via http requests
But I was wondering if there was a way to do it right from the command line (without python, in plain bash)
Upvotes: 1
Views: 3558
Reputation: 32050
Yes, you can do this with jq
and the tojson
function.
To load /tmp/example.avsc
schema to my_schema_01-value
subject run:
jq '. | {schema: tojson}' /tmp/example.avsc | \
curl -X POST http://localhost:8081/subjects/my_schema_01-value/versions \
-H "Content-Type:application/json" \
-d @-
Ref: https://rmoff.net/2019/01/17/confluent-schema-registry-rest-api-cheatsheet/
Upvotes: 6