Skip to content

Incorrect documentation for registering Avro schema using AVSC file #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
joshjluo opened this issue Nov 11, 2021 · 2 comments
Open

Comments

@joshjluo
Copy link

Issue description

The documentation for registering an Avro schema using an AVSC file shows the following:

const { SchemaType, readAVSCAsync, avdlToAVSCAsync } = require('@kafkajs/confluent-schema-registry')

// From an avsc file
const schema = await readAVSCAsync('path/to/schema.avsc')
const { id } = await registry.register({ type: SchemaType.AVRO, schema }) // { id: 2 }

When attempting to do this with Typescript, Typescript shows the following error with schema:

Type 'RawAvroSchema' is not assignable to type 'string'.

Steps to reproduce the issue

  1. Create a schema.avsc file. For example,
{
  "type": "string",
  "name": "name"
}
  1. Read and register the schema according to the documentation
const { SchemaType, readAVSCAsync } = require('@kafkajs/confluent-schema-registry')

const schema = await readAVSCAsync('path/to/schema.avsc')
const { id } = await registry.register({ type: SchemaType.AVRO, schema })
  1. Observe the error caused by schema.
Type 'RawAvroSchema' is not assignable to type 'string'.

Screen Shot 2021-11-11 at 2 27 48 PM

Potential Solution

I believe the documentation should say something like

const { SchemaType, readAVSCAsync, avdlToAVSCAsync } = require('@kafkajs/confluent-schema-registry')

const schema = await readAVSCAsync('path/to/schema.avsc')
const { id } = await registry.register(schema)

based on getConfluentSchema() in SchemaRegistry.ts.

@USSliberty
Copy link

In my case this error was throwing since I was using pure Node.js:

ResponseError: Confluent_Schema_Registry - Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)

@joshjluo Potential Solution did the trick!

@silverwind
Copy link

Also ran into this and this fix worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants