Skip to content
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

Array schema is not being parsed correctly #154

Closed
jaydeepk opened this issue Jun 29, 2023 · 11 comments
Closed

Array schema is not being parsed correctly #154

jaydeepk opened this issue Jun 29, 2023 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@jaydeepk
Copy link
Contributor

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 ?

@jaydeepk jaydeepk added the bug Something isn't working label Jun 29, 2023
@github-actions
Copy link

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.

@jaydeepk
Copy link
Contributor Author

jaydeepk commented Jul 3, 2023

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.

@harikrishnan83
Copy link

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?

@Pakisan
Copy link
Member

Pakisan commented Oct 5, 2023

@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

@harikrishnan83
Copy link

@Pakisan thanks for taking a look.

@jaydeepk
Copy link
Contributor Author

jaydeepk commented Oct 6, 2023

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

@Pakisan
Copy link
Member

Pakisan commented Oct 13, 2023

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

@Pakisan
Copy link
Member

Pakisan commented Oct 22, 2023

@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

@harikrishnan83
Copy link

@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
Copy link
Member

Pakisan commented Dec 2, 2023

@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

@harikrishnan83
Copy link

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

@Pakisan Pakisan self-assigned this Jan 30, 2024
@Pakisan Pakisan closed this as completed Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants