asyncapi / avro-schema-parser

An AsyncAPI schema parser for Avro 1.x schemas.
Apache License 2.0
32 stars 19 forks source link

"bidnings.kafka.key" is transformed even if schema is defined as JSON Schema #139

Closed magicmatatjahu closed 1 year ago

magicmatatjahu commented 2 years ago

Describe the bug

bidnings.kafka.key field is transformed by avro-parser even if schema is defined as JSON Schema, but it should be only when is defined as Avro Schema.

How to Reproduce

Paste to the Studio example spec with bindings.kafka.key:

asyncapi: 2.3.0
info:
  title: Generic title
  version: '0.0.1'
  description: Generic description

channels:
  kafka-topic-name:
    publish:
      message:
        oneOf:
          - name: SessionCreated
            schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
            bindings:
              kafka:
                key:
                  type: string
                  description: Here we go
                  enum: [ 'sessionId' ]
                bindingVersion: '0.2.0'
            payload:
              $ref: '#/components/x-avro-schemas/SessionCreated'

components:
  x-avro-schemas:
    SessionCreated:
      {"namespace": "example.avro",
       "type": "record",
       "name": "User",
       "fields": [
         {"name": "name", "type": "string"},
         {"name": "favorite_number",  "type": ["int", "null"]},
         {"name": "favorite_color", "type": ["string", "null"]}
       ]
      }

and you will see:

image

but it should be (I changed kafka.key to kafka.test):

image

github-actions[bot] commented 2 years ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

M3lkior commented 2 years ago

@magicmatatjahu this is a side effect of the basic support of Avro definition in the key bindings, described here. Should we wait for any progress on your proposal ? or find a workaround to fix this issue like parsing the entire structure to detect if it is a avro or json definition ?

magicmatatjahu commented 2 years ago

@M3lkior Sorry for delayed response, I was on vacation.

this is a side effect of the basic support of Avro definition in the key bindings, described https://github.com/asyncapi/avro-schema-parser/pull/77. Should we wait for any progress on https://github.com/asyncapi/spec/issues/622 ? or find a workaround to fix this issue like parsing the entire structure to detect if it is a avro or json definition ?

I understand, thanks. I don't know when that proposal will be accepted (or even accepted), so I won't count on that. As I see we can check if given schema is avro schema like here https://github.com/asyncapi/avro-schema-parser/blob/master/to-json-schema.js#L271 and make simple try catch for that:

try {
  validateAvroSchema(message.bindings.kafka.key);
} catch(e) {
  // "break" rest of the function
}

but we need to remember that then only JSON Schema will be then accepted.

WDYT?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart: