asyncapi-react icon indicating copy to clipboard operation
asyncapi-react copied to clipboard

Inconsistent reporting of "Adheres to" between records of same structure, based on the order of declaration

Open Amzani opened this issue 2 years ago • 2 comments

This issue was initially reposted by @ghuser here

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 the following:

image

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:

{
  "r1": {
    "child1": {
      "field": "string"
    }
  },
  "r2": {
    "child2": {}
  },
  "r3": {
    "child3": {
      "field": "string"
    }
  },
  "r4": {
    "child4": {
      "field": "string"
    }
  }
}

Amzani avatar Nov 02 '23 15:11 Amzani

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.

github-actions[bot] avatar Nov 02 '23 15:11 github-actions[bot]

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:

github-actions[bot] avatar Mar 02 '24 00:03 github-actions[bot]