Skip to content

Clarify oneOf usage if any #278

@antoine-mulet

Description

@antoine-mulet

I 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions