asyncapi/jasyncapi

Array schema is not being parsed correctly

jaydeepk opened this issue ยท 11 comments

Hi
We are experiencing some issues with parsing specs where messages are defined as an array of objects.
Let's say I have this spec:

channels:
  test-topic-array:
    publish:
      operationId: publishObjectMessage
      message:
        bindings:
          kafka:
            key:
              type: string
            bindingVersion: '0.4.0'
        payload:
          $ref: "#/components/messages/Task"

components:
  messages:
    Task:
      name: Task
      title: A Task to be processed
      summary: Inform about a new user task in the system
      contentType: application/json
      payload:
        $ref: "#/components/schemas/taskPayload"

  schemas:
    taskPayload:
      type: array
      items:
        type: object
        required:
          - id
          - name
          - done
        properties:
          id:
            type: integer
          name:
            type: string
          done:
            type: boolean

When I parse this schema, the 'items' property appears as a LinkedHashMap.
Ideally, we'd expect this to be a Schema object.
Also in this map, 'properties is again a <String, LinkedHashMap> instead of <String, Schema> ( like we see it for a payload of type="object")

Screenshot 2023-06-29 at 1 47 35 PM

Could you please advise if my understanding is correct and if this is something that you plan to fix at some point ?

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.

Hello, just want to add that I had a look at the code and there is this comment on that the 'Items' property can either be a json schema or an array of schemas.
If items is an array of schemas, one option would be to define it in the 'prefixItems' property:

{
  "type": "array",
  "prefixItems": [
    { "type": "number" },
    { "type": "string" },
    { "enum": ["Street", "Avenue", "Boulevard"] },
    { "enum": ["NW", "NE", "SW", "SE"] }
  ]
}

as described here:
https://json-schema.org/understanding-json-schema/reference/array.html

So we could either use the 'prefixItems' property ..or the other option would be to set the 'items' property as a list of schemas?
Please let me know your thoughts on this.

Thanks a lot for this project. Appreciate it very much. However lack of array support is a blocker for us. Can you please help by prioritising the same and if you could please review the PR?

@jaydeepk @harikrishnan83 sorry for late response. I reviewed your PR now and it looks fine, for first view.

I'm not sure that selected key word is actual for JSON Schema draft 7. Will check it tomorrow

@Pakisan thanks for taking a look.

Thanks for the update @Pakisan, no worries !
Please let us know if any changes are required.

Hello, just want to add that I had a look at the code and there is this comment on that the 'Items' property can either be a json schema or an array of schemas. If items is an array of schemas, one option would be to define it in the 'prefixItems' property:

{
  "type": "array",
  "prefixItems": [
    { "type": "number" },
    { "type": "string" },
    { "enum": ["Street", "Avenue", "Boulevard"] },
    { "enum": ["NW", "NE", "SW", "SE"] }
  ]
}

as described here: https://json-schema.org/understanding-json-schema/reference/array.html

So we could either use the 'prefixItems' property ..or the other option would be to set the 'items' property as a list of schemas? Please let me know your thoughts on this.

I think that we can't use prefixItems because it was introduced in 2020-12

Array-value "items" functionality is now "prefixItems"

Reference

In Draft 4 - 2019-09, tuple validation was handled by an alternate form of the items keyword. When items was an array of schemas instead of a single schema, it behaved the way prefixItems behaves.

Reference

So let's don't add prefixItems into Schema

@harikrishnan83 @harikrishnan83 Hi!

If everything works fine, I propose to close this issue.

If you are using library in project inside open repo, you can attach link to it. It will allow me to notify you about new release o propose MR with bumped version of library

@Pakisan Can you please share in what release we can expect the changes so that we can test and confirm with that release version? BTW we extensively use Dependabot, so we should receive a dependency version bump PR for this. cc @jaydeepk

@Pakisan Can you please share in what release we can expect the changes so that we can test and confirm with that release version? BTW we extensively use Dependabot, so we should receive a dependency version bump PR for this. cc @jaydeepk

In think it will be end of December, cause on 6 of December will be release of new version of our spec and I need time to refactor things

Thanks @Pakisan, looking forward to the release. cc @jaydeepk