Clarify oneOf usage if any
See original GitHub issueI have been struggling to understand how oneOf can be used within params since it is mentioned in the documentation https://spec.open-rpc.org/#method-object. I have played a bit with the playground as well and the only way I found to make use of oneOf was inside the schema, which is standard json schema. Am I missing something?
I found issue #193 which was auto closed so I am wondering whether oneOf was somehow supported in the past but it’s not anymore? If that’s the case the documentation should probably be updated.
As a side note I can see a use case where one could want to use oneOf outside the schema. This would be to define some sort of polymorphic group of top level params e.g.
"params" : { "oneOf" :[
{ "$ref": "#/components/schemas/Foo" },
{ "$ref": "#/components/schemas/Bar" }
]
}
This is clearly not compatible with params being of type array so not sure the added complexity is worth the benefits but I am currently migrating an API to OpenRPC and I found myself in the need of doing something like this so maybe others would too.
This limitation is easily overcome by introducing another level of nesting as follow but it ultimately changes what your API looks like
"params" : [
{ "name": "p", "schema": { "type" : "object", "oneOf": [
{ "$ref": "#/components/schemas/Foo" } ,
{ "$ref": "#/components/schemas/Bar" }
]}
}
I hope it makes sense.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
@BelfordZ Thanks for the clarification and your great work! My PR is all yours.
🎉 This issue has been resolved in version 1.2.6 🎉
The release is available on:
1.2.6
Your semantic-release bot 📦🚀