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
157 stars 102 forks source link

ConfluentSchemaRegistryArgumentError: no such type #263

Open hrebijan opened 4 months ago

hrebijan commented 4 months ago

Hi!

In my project I'm using .proto schema:

syntax = "proto3";

package common;

import "google/protobuf/timestamp.proto";

enum EventType {
  EVENT_UNSPECIFIED = 0;
  CREATED = 1;
  UPDATED = 2;
  DELETED = 4;
}

message SomeMessage {
  string uid = 1;
  string text = 2;
}
...

When try to register schema:

 const { id } = await this.registry.register(schema, { subject: 'some.subject', compatibility: COMPATIBILITY.BACKWARD});

i got error:

ConfluentSchemaRegistryArgumentError: no such type: common..EventType
    at Object.exports.schemaFromConfluentSchema (/app/node_modules/.pnpm/@kafkajs+confluent-schema-registry@3.3.0/node_modules/@kafkajs/confluent-schema-registry/src/schemaTypeResolver.ts:99:11)
    at SchemaRegistry.register (/app/node_modules/.pnpm/@kafkajs+confluent-schema-registry@3.3.0/node_modules/@kafkajs/confluent-schema-registry/src/SchemaRegistry.ts:119:28)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
...

My suggest to solve this issue: in: src/ProtoSchema.ts to lookup both types - messages and enums:

- this.message = root.lookupType(this.getTypeName(parsedMessage, opts))
+ this.message = root.lookupTypeOrEnum(this.getTypeName(parsedMessage, opts));

Question: why are in function [getTypeName](https://github.com/kafkajs/confluent-schema-registry/blob/master/src/ProtoSchema.ts#L35) doubled dots pkg..name ?

My suggestion:

- return `${pkg ? pkg + '.' : ''}.${name}`;
+ return `${pkg ? pkg : ''}.${name}`;

Thanks.