open-rpc / spec

The OpenRPC specification
https://spec.open-rpc.org
Apache License 2.0
167 stars 49 forks source link

Question: params array #319

Closed pedrouid closed 3 years ago

pedrouid commented 3 years ago

I've just learned about OpenRPC and I think this is an amazing project that should be far more adopted.

However it seems from the examples on the website that the specification for the params for methods assumes that they are always an array.

{
  "params": [
       <PARAMS_SCHEMA>
   ]
}

I would expect the params to be specified as per json-schema specification:

{
  "params": {
      "type": "array",
      "items": <PARAMS_SCHEMA>
  }
}

Am I interpreting this correctly?

github-actions[bot] commented 3 years ago

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

shanejonas commented 3 years ago

Hi @pedrouid,

In the spec params is always an array. If you want configure object (by-name) vs array (by-position) parameter request formatting check out paramStructure on Method Object.

Params is not a JSON-Schema, but an array of Content Descriptor Objects which includes fields like name (required), description, schema (required)(which is a JSON-Schema) etc.

Here is an example:

{
  "openrpc": "1.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Petstore"
  },
  "methods": [
    {
      "name": "create_pet",
      "summary": "Create a pet",
      "paramStructure": "by-name",
      "params": [
        {
          "name": "newPetName",
          "description": "Name of pet to create",
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "newPetTag",
          "description": "Pet tag to create",
          "schema": {
            "type": "string"
          }
        }
      ],
      "result": {
        "name": "petId",
        "schema": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  ]
}
pedrouid commented 3 years ago

Awesome 🙌 Thanks for taking the time to clarify that. It makes more sense now!