Skip to content

Add support for oneOf, anyOf and other keywords in client schema parsing#34

Open
imnisen wants to merge 1 commit into40ants:masterfrom
imnisen:master
Open

Add support for oneOf, anyOf and other keywords in client schema parsing#34
imnisen wants to merge 1 commit into40ants:masterfrom
imnisen:master

Conversation

@imnisen
Copy link
Copy Markdown

@imnisen imnisen commented Jan 15, 2026

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.

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

I don't see in the OpenRPC spec any support for:

  • oneOf
  • anyOf
  • allOf

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 anyOf few different types? How our client will decide which type to create?

@svetlyak40wt
Copy link
Copy Markdown
Member

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):

Anything referring to oneOf should be removed. Polymorphism as described should be pushed down to the JSON schema, since it already fully supports oneOf.

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.

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

Successfully merging this pull request may close these issues.

2 participants