open-rpc / docs-react

OpenRPC documentation as a react component.
10 stars 8 forks source link

Support for arguments by name in examples #320

Closed ferreteleco closed 4 years ago

ferreteleco commented 4 years ago

After playing arround for a while I found that, when defining a call's example as a Example Pairing Object, the params for this MUST be inside a list, and I think It does not cover the case of calls where all params are defined by name. For example, for the given definition:

{
  "openrpc": "1.0.0-rc1",
  "info": {
    "version": "1.0.0",
    "title": "Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "methods": [
    {
      "name": "get_pet",
      "summary": "Info for a specific pet",
      "paramStructure": "by-name",
      "tags": [
        {
          "name": "pets"
        }
      ],
      "params": [
        {
          "name": "petId",
          "required": true,
          "description": "The id of the pet to retrieve",
          "schema": {
            "type": "object"
          }
        }
      ],
      "result": {
        "name": "pet",
        "description": "Expected response to a valid request",
        "schema": {
          "$ref": "#/components/schemas/Pet"
        }
      },
      "examples": [
          {"name": "get_pet_example",
          "params": [
              {
                  "name": "pet_id",
                  "value": 1
              }
          ],
          "result":{
              "name": "get_pet_result",
              "value": {
                  "id": 1,
                  "name": "Vivian" 
              }
          }
        }
      ]
    }
  ],
  "components": {
    "schemas": {
      "Pet": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          }
        }
      },
      "Pets": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Pet"
        }
      }
    }
  }
}

The resulting example display in the Open-RPC playground shows: image

and I think the correct request should be of the form

{
"id":1,
"jsonrpc":"2.0",
"method":"get_pet",
"params":{
"petID":1
}
}

From my point of view, 'params' field in Example Pairing Object should be allowed being a single Example object. Am I Wrong?

github-actions[bot] commented 4 years ago

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

shanejonas commented 4 years ago

I think this should be a docs-react ticket to support params-by-name for showing examples. just having "paramStructure": "by-name", ideally should change the docs-react examples to show an object instead.

ferreteleco commented 4 years ago

I think its also a mater of documents, since the specification does not allow for a single object in Example Pairing Object params field:

image

shanejonas commented 4 years ago

my reply here is relevant: https://github.com/open-rpc/spec/issues/274#issuecomment-620393082

openrpc-bastion commented 4 years ago

:tada: This issue has been resolved in version 1.2.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: