riferrei / srclient

Golang Client for Schema Registry
Apache License 2.0
235 stars 70 forks source link

CreateSchema method #74

Closed kompl closed 2 years ago

kompl commented 2 years ago

The method returns the latest version of the schema, but the schema registry behaves differently: it compares the schemas with the existing ones, and if it doesn't find it, it creates a new schema. In this case, the answer will be correct. But if it finds a match, then the post request will return the id of the existing schema, in which case the answer will be incorrect, since the existing schema will not necessarily be the last one.

cp-schema-registry:7.0.1

kompl commented 2 years ago

Request:

curl --location --request POST '0.0.0.0:8081/subjects/charges/versions' \
--header 'Content-Type: application/vnd.schemaregistry.v1+json' \
--data-raw '{
    "schema": "{\"type\":\"record\",\"name\":\"ChargeMessage\",\"fields\":[{\"name\":\"MessageTypeId\",\"type\":\"int\"},{\"name\":\"MessageTypeCode\",\"type\":\"string\"},{\"name\":\"Version\",\"type\":\"int\"},{\"name\":\"CreatedAt\",\"type\":\"string\",\"logicalType\":\"date\"},{\"name\":\"Payload\",\"type\":{\"type\":\"record\",\"name\":\"Payload\",\"fields\":[{\"name\":\"Charge\",\"type\":{\"type\":\"record\",\"name\":\"Charge\",\"fields\":[{\"name\":\"ChargeLogId\",\"type\":\"int\"},{\"name\":\"ChargeLogLineId\",\"type\":\"long\"},{\"name\":\"ChargeLogLineIdq\",\"type\":\"long\"},{\"name\":\"ChangeBalanceTypejjhkId\",\"type\":\"string\"}]}}]}}]}"
}'

Response:

{
    "id": 1
}

Request:

curl --location --request GET '0.0.0.0:8081/subjects/charges/versions/latest' \
--header 'Content-Type: application/vnd.schemaregistry.v1+json'

Response:

{
    "subject": "charges",
    "version": 8,
    "id": 8,
    "schema": "{\"type\":\"record\",\"name\":\"ChargeMessage\",\"fields\":[{\"name\":\"MessageTypeId\",\"type\":\"int\"},{\"name\":\"MessageTypeCode\",\"type\":\"string\"},{\"name\":\"Version\",\"type\":\"int\"},{\"name\":\"CreatedAt\",\"type\":\"string\",\"logicalType\":\"date\"},{\"name\":\"Payload\",\"type\":{\"type\":\"record\",\"name\":\"Payload\",\"fields\":[]}}]}"
}
kompl commented 2 years ago

https://github.com/riferrei/srclient/pull/75

riferrei commented 2 years ago

Your PR was merged and included in the v0.5.2 release. Thanks 🙏🏻

kompl commented 2 years ago

Your PR was merged and included in the v0.5.2 release. Thanks 🙏🏻

Thanks 🙏🏻