kafkajs / confluent-schema-registry

is a library that makes it easier to interact with the Confluent schema registry
https://www.npmjs.com/package/@kafkajs/confluent-schema-registry
MIT License
156 stars 102 forks source link

ConfluentSchemaRegistryValidationError when union contains more than one number data type #213

Open jomo02 opened 2 years ago

jomo02 commented 2 years ago

Hi together,

I am running into the following error when I try to produce a message:

ConfluentSchemaRegistryValidationError: invalid ["null", "boolean", "double", "long"]: true

The schema was previously registered and the relevant part looks like this:

{
    "name": "value",
    "type": ["null", "boolean", "double", "long"]
}

If I replace "long" e.g. with "string" I am able to produce, but when I'm using any combination of double, float, long and int, I'm getting the described error.

Maybe it has something to do with the fact that unions may not contain more than one schema with the same type (since there is only the number type in Typescript)?

Thanks in advance!

kinhsloob1-erecruiter commented 2 years ago

Same issue.

ConfluentSchemaRegistryValidationError: invalid ["null", "int", "long", "string"]: 7.5

The schema was previously registered and the relevant part looks like this:

{
    "name": "value",
    "type": ["null", "int", "long", "string"]
}

If I remove "int" from the union, it works.

stebl commented 1 year ago

Just ran into this as well. Any movement?

Bahkran commented 4 months ago

Hi - realise this is old, but we hit it recently using v3.3.0.

This can be solved by explicitly specifying the type of the union that you are using. It is the same technique used if there are objects in the union.

e.g.

{
    "name": "value",
    "type": ["null", "int", "long", "string"]
}
const registry = new SchemaRegistry({…});
await registry.encode(schemaId, {
  value: { long: 75 },
});