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

Clarify oneOf usage if any #278

Closed
antoine-mulet opened this issue May 5, 2020 · 6 comments · Fixed by #291
Closed

Clarify oneOf usage if any #278

antoine-mulet opened this issue May 5, 2020 · 6 comments · Fixed by #291
Assignees
Labels
bug Something isn't working released

Comments

@antoine-mulet
Copy link
Contributor

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.

@github-actions
Copy link

github-actions bot commented May 5, 2020

Welcome to OpenRPC! Thank you for taking the time to create an issue. Please review the guidelines

@BelfordZ BelfordZ self-assigned this May 12, 2020
@georgeconstantinou
Copy link

Having the same issue as described by @antoine-mulet.

@BelfordZ BelfordZ added the bug Something isn't working label May 21, 2020
@BelfordZ
Copy link
Member

BelfordZ commented May 21, 2020

@antoine-mulet @georgeconstantinou Thank you both for raising this issue. It's something we experimented with early on and dropped, but as pointed out, we missed a reference to it in the spec. Anything referring to oneOf should be removed. Polymorphism as described should be pushed down to the JSON schema, since it already fully supports oneOf.

PRs are very welcomed. I'll make one later on today though.

BelfordZ added a commit that referenced this issue May 21, 2020
BelfordZ added a commit that referenced this issue May 21, 2020
@BelfordZ
Copy link
Member

@antoine-mulet since it's ultimately your contribution, if you want to copy the PR and re-open, I'm happy to merge yours.

antoine-mulet added a commit to antoine-mulet/spec that referenced this issue May 22, 2020
@antoine-mulet
Copy link
Contributor Author

@BelfordZ Thanks for the clarification and your great work! My PR is all yours.

openrpc-bastion added a commit that referenced this issue May 22, 2020
## [1.2.6](1.2.5...1.2.6) (2020-05-22)

### Bug Fixes

* schema required formatting ([1a745b5](1a745b5))
* **method.paramStructure:** add spec detailing by-name case of cd.name ([646978c](646978c))
* [@BelfordZ](https://github.com/belfordz) edits for awesomeness ([cbae9e3](cbae9e3))
* add another oxford comma ([b1092f6](b1092f6))
* append 's' to param_s_ field ([9da993b](9da993b))
* formatting of required on linkObject.name ([63f5410](63f5410))
* missing oxford comma ([df8a507](df8a507))
* non-oxfordian missing space after oxfordian comma ([1deef5c](1deef5c))
* remove oneOf ([215b0ae](215b0ae)), closes [#278](#278)
* remove unused dev deps ([11df1e8](11df1e8))
* s/field/value ([75275e6](75275e6))
* update FAQ and add to repo ([7c7310c](7c7310c)), closes [#283](#283)
@openrpc-bastion
Copy link
Member

🎉 This issue has been resolved in version 1.2.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants