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

Support prefixItems in array schemas #208

Open
splitbrain opened this issue Nov 30, 2023 · 4 comments
Open

Support prefixItems in array schemas #208

splitbrain opened this issue Nov 30, 2023 · 4 comments

Comments

@splitbrain
Copy link

I am modelling an existing API which uses positional arguments in the request body. According to this stackoverflow answer the correct way to do that is to use prefixItems.

Unfortunately, this seems not to be picked up by openapi-explorer. The model tab just shows [].

Any chance this could be supported properly? Or maybe there's a workaround?

@wparad
Copy link
Member

wparad commented Nov 30, 2023

Do you have a link to the oas schema where this is documented.

Of course if it is spec compliant we would accept a PR to implement thine missing functionality. Thanks for finding this missing piece.

@splitbrain
Copy link
Author

From what I understand, this comes from JSON-Schema. But digging further into this, it seems it is not fully supported after all. The swagger editor however does display at least some info:

screenshot-editor-next swagger io-2023 11 30-11_07_47

@splitbrain
Copy link
Author

https://json-schema.org/understanding-json-schema/reference/array#tupleValidation has some more info on the used syntax.

@wparad
Copy link
Member

wparad commented Nov 30, 2023

So it's clearly something in the json schema draft 2020-12 schema that could be added. Given that we'll keep this ticket open. I will share two concerns about using this however:

  • This is non-trivial functionality that likely leads to a lot of confusion. In these cases when you already know about these properties, first class properties of the parent are a better design. Or changing the array to be an object with nested properties, one of those of those being an array.
  • This can't work for most typed languages given that typed languages don't have a concept of positional schema for array elements.

While I can recommend all day long that this should never be done, that doesn't stop it from having been added to the spec. So if someone spends the time to implement this feature, as per Draft 2020-12, we will accept it, but will caution that this functionality should never exist in an API due to its lack of polymorphism across languages.

Note on the first point and the example, the example uses address, but not every address works that way, so realistically, the example is a really bad one and sets a bad precedent. If you are trying to create an api with properties for an address, see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants