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

params field could be a restricted JSON schema instead of custom contentDescriptorObject #226

Closed
rmedaer opened this issue Sep 11, 2019 · 5 comments
Labels

Comments

@rmedaer
Copy link
Member

rmedaer commented Sep 11, 2019

According to JSON RPC specs (4.2 Parameter Structures), params member can either be:

  • omitted: (4 Request object, params) "This member MAY be omitted."
  • an array (aka by-position): with ordered value
  • an object (aka by-name): with named parameter (as object-key)

The OpenRPC params member and its item type contentDescriptorObject should reflect the JSON RPC spec described above. However I see multiple mismatches or issues in the current OpenRPC spec:

To solve all these issues I would propose to replace the OpenRPC params field by a restricted JSON schema. Restricted means "limited to types allowed in the JSON RPC spec". Btw, with this change, we don't need anymore the paramStructure field.

by-name example

Currently:

{
  "openrpc": "1.0.0-rc1",
  "methods": [
    {
      "name": "addition",
      "params": [
        { "name": "a", "schema": { "type": "integer" } },
        { "name": "b", "schema": { "type": "integer" } }
      ],
    }
  ]
}

Proposal:

{
  "openrpc": "1.0.0-rc1",
  "methods": [
    {
      "name": "addition",
      "params": {
        "type": "object",
        "properties": {
          "a": { "type": "integer" },
          "b": { "type": "integer" }
        }
      }
    }
  ]
}

by-position example

Proposal:

{
  "openrpc": "1.0.0-rc1",
  "methods": [
    {
      "name": "addition",
      "params": {
        "type": "array",
        "items": {
          "type": "integer"
        },
        "minItems": 2
      }
    }
  ]
}

either by-position or by-name (#190)

Proposal:

{
  "openrpc": "1.0.0-rc1",
  "methods": [
    {
      "name": "addition",
      "params": {
        "oneOf": [
          {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "minItems": 2
          }, {
            "type": "object",
            "properties": {
              "a": { "type": "integer" },
              "b": { "type": "integer" }
            }
          }
        ]
      }
    }
  ]
}
@BelfordZ
Copy link
Member

Potentially fixes
#229

BelfordZ added a commit that referenced this issue Sep 25, 2019
BelfordZ added a commit that referenced this issue Sep 26, 2019
BelfordZ added a commit that referenced this issue Sep 26, 2019
BelfordZ added a commit that referenced this issue Sep 26, 2019
fixes #190

partly addresses #226

Signed-off-by: Zachary Belford <belfordz66@gmail.com>
BelfordZ added a commit that referenced this issue Sep 26, 2019
fixes #190

partly addresses #226

Signed-off-by: Zachary Belford <belfordz66@gmail.com>
BelfordZ added a commit that referenced this issue Sep 26, 2019
BelfordZ added a commit that referenced this issue Sep 26, 2019
fixes #190

partly addresses #226

Signed-off-by: Zachary Belford <belfordz66@gmail.com>
openrpc-bastion added a commit that referenced this issue Sep 26, 2019
## [1.2.1](1.2.0...1.2.1) (2019-09-26)

### Bug Fixes

* add "either" option for param structure ([947c12b](947c12b)), closes [#190](#190) [#226](#226)
@BelfordZ
Copy link
Member

The content descriptor is key in the ability to separate the domain specific languages.

For example, consider the method "division".

{
  "name": "division",
  "params": [
    { "name": "numerator", schema: { $ref: "#/components/schemas/Number } },
    { "name": "denominator", schema: { $ref: "#/components/schemas/NonZeroNumber } }
  ]
}

In this example, it reads very clearly, and you need not have schema.title that matches the names of the data returning from the api. This is especially important in client generation, where the parameter names -> type becomes very clear.

@BelfordZ
Copy link
Member

to address some of your other points:

  • if paramStructure is by-position:
    • the contentDescriptorObject > name is not required
      • While you may not require names to manipulate the data if its by position, it greatly complicates things to accommodate these types of conditionally optional fields. It also makes generated documentation much better, among many other benefits.
      • the required field is not relevant
        • Its still relevant. you can mark trailing content descriptors as optional
      • there is no way to define generic item schema or validate number of items, etc.

@BelfordZ
Copy link
Member

I've opened an issue for the only thing I can think of from this that we really need to address.

#229

@BelfordZ
Copy link
Member

Thanks for opening the issue and bringing these to our attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants