asyncapi / avro-schema-parser

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

[BUG] Inconsistent reporting of "Adheres to" between records of same structure, based on the order of declaration. #256

Open ghuser opened 6 months ago

ghuser commented 6 months ago

Describe the bug.

In the following asyncapi document

asyncapi: 2.6.0
info:
  title: AsyncAPI
  version: 1.0.0
  description: AsyncAPI
channels:
  example:
    publish:
      message:
        $ref: '#/components/messages/example_message'
components:
  messages:
    example_message:
      name: example_event
      schemaFormat: application/vnd.apache.avro;version=1.9.0
      payload:
        type: record
        name: ParentRecord
        fields:
          - name: r1
            type:
              type: record
              name: Record1
              fields:
                - name: child1
                  type:
                    - 'null'
                    - type: record
                      name: CommonChildRecord
                      fields:
                        - name: field
                          type:
                            type: string
                            minLength: 1
                            maxLength: 256
          - name: r2
            type:
              type: record
              name: Record2
              fields:
                - name: child2
                  type:
                    - 'null'
                    - CommonChildRecord
          - name: r3
            type:
              type: record
              name: Record3
              fields:
                - name: child3
                  type: CommonChildRecord
          - name: r4
            type:
              - 'null'
              - type: record
                name: Record4
                fields:
                  - name: child4
                    type: CommonChildRecord

the preview reports what is presented in Screenshot1

As you can see r2 is of type Record2 which equal (structure-wise) to Record1 (used by r1). However, the report for r2 is "Adheres to: Any or null" while the report for r1 is: "Adheres to Object or null".

This inconsistent reporting seems to be related with having a nested field (in this case of type CommonChildRecord) marked as nullable. But the issue for some reason does not affect the first record.

Now if I make the nested field not nullable, there is no issue, even if the parent is nullable. (rendering of cases of r3 and r4 reports: "Adheres to Object or null")

The above issue also affects the payload in the examples section: see below:

Expected behavior

For r2 the adheres to should be Object containing a a field of type String

Screenshots

Screenshot1:

image

How to Reproduce

  1. Visit https://studio.asyncapi.com/
  2. Paste the above payload
  3. See in the preview that r2/child2 is presented with "Adheres to Any" while r1/child1 is shown correctly.

🥦 Browser

Google Chrome

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it