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

additionalItems should only apply for tuples #1138

Closed
jonaslagoni opened this issue Feb 20, 2023 · 4 comments
Closed

additionalItems should only apply for tuples #1138

jonaslagoni opened this issue Feb 20, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@jonaslagoni
Copy link
Member

Describe the bug

Currently, additionalItems are applied even when the items are not a tuple.

https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.4.2

This means that this:

    "tags": {
      "type": "array",
      "items": {
        "$ref": "http://asyncapi.com/definitions/2.6.0/tag.json"
      },
      "uniqueItems": true
    },

generates this union type:

private _tags?: (Tag | any)[];

When it should only be:

private _tags?: Tag[];
@jonaslagoni jonaslagoni added the bug Something isn't working label Feb 20, 2023
@jonaslagoni
Copy link
Member Author

jonaslagoni commented Feb 20, 2023

The simple array type above makes sense.

But what about those tuples... Say we have this:

    "tags": {
      "type": "array",
      "items": [{type: string}, {type: boolean}],
      "additionalItems": true
    },

Would we expect to generate:

private _tags?: (string | boolean | any)[];

or rather a tuple and an array type in union 🤔

private _tags?: [string, boolean] | (string | boolean | any)[];

I am leaning towards the last option because the following input is valid:

{
  tags: ["teest", true, "test"]
}

Same with:

{
  tags: ["teest", true, false]
}

Same with:

{
  tags: ["teest", true]
}

And in most languages its either a tuple or array, it cant be partly tuple and partly array. So even though you lose the tuple structure for the array type (string | boolean | any)[] we get the best of both worlds IMO 🤔

@jonaslagoni
Copy link
Member Author

Continued with tuple discussion here: #1139

@kennethaasan
Copy link
Collaborator

I've had issues with differences between draft 7 and draft 2020-12: https://ajv.js.org/json-schema.html#draft-2020-12
But I guess that's a different issue and should be handled by checking draft version

@jonaslagoni
Copy link
Member Author

Gonna be solved in v2 and currently released as part of 2.0.0-next.4

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

2 participants