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

Add more "native" support for the oneOf JSON schema #163

Open
kdeme opened this issue Apr 27, 2023 · 1 comment
Open

Add more "native" support for the oneOf JSON schema #163

kdeme opened this issue Apr 27, 2023 · 1 comment

Comments

@kdeme
Copy link
Contributor

kdeme commented Apr 27, 2023

Issue regarding potentially improving support for the oneOf JSON schema, and perhaps also anyOf and others.

When currently one of two (or more) types are to be accepted, we will typically write something custom, e.g.:

In case this concerns a type that is often used, it can be improved of course by creating a custom type for this and overloading the %, but it still results in something custom for each different group of types.

For some scenarios the Option type can be (ab)used to deal with this, like here: https://github.com/status-im/nim-web3/blob/437c768bc3267da325645a7f346516f75776a05c/web3/ethtypes.nim#L289

But it is not ideal as it:

  • will still result in extra null value(s) (in case of return value), or it will not be properly checked for only one of the values (in case of a parameter). (I've checked with AJV schema validator and it does consider the extra null(s) valid according to the schema, but I wouldn't be surprised if some implementations do complain about the null.)
  • only works if all types are supposed to be wrapped in an object

PS: Optional fields now can be removed from output and the server also able to handle null fields

@kdeme
Copy link
Contributor Author

kdeme commented Apr 27, 2023

Somewhat related issue as a variant could be used for this: #29

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

1 participant