Add support for oneOf, anyOf and other keywords in client schema parsing#34
Add support for oneOf, anyOf and other keywords in client schema parsing#34imnisen wants to merge 1 commit into40ants:masterfrom
Conversation
Extend schema-to-type function to support JSON Schema composition keywords (oneOf, anyOf, allOf), implicit object types, $ref, enum, and const patterns. This enables generating clients from OpenRPC specs like the Ethereum execution APIs that use these schema patterns. Includes regression tests covering all supported patterns.
|
I don't see in the OpenRPC spec any support for:
There is this issue of mine open-rpc/spec#382 for discussion this problem and seems these types will not be supported ever. Also, found this article https://answerroom.online/articles/support-parsing-oneof-and-anyof (probably you are the author) :) The problem of support for these types is that we should not only to validate if the given argument has the correct type, but also we need to do serialization/deserialization correctly, which may not be possible in some cases. Although this PR makes it possible to generate a client for Ethereum API, I doubt it will work correctly. For example, what client will do if API returns an object with field which can be |
|
Also, found this issue open-rpc/spec#278 and comment about why oneOf mention was removed from the OpenRPC spec: open-rpc/spec#278 (comment):
If I read this comment correctly, then support of oneOf is the task of the library supporting validation of JSON Schema. Actually, there is already support of oneOf for the case when it is used to specify that an object is optional: https://github.com/40ants/openrpc/blob/master/t/client/deserialization.lisp#L16. And I still do not know how to support a more generic case with more types in the list. |
Extend schema-to-type function to support JSON Schema composition keywords (oneOf, anyOf, allOf), implicit object types, $ref, enum, and const patterns.
This enables generating clients from OpenRPC specs like the Ethereum execution APIs that use these schema patterns.
Includes regression tests covering all supported patterns.