mock-server icon indicating copy to clipboard operation
mock-server copied to clipboard

Mocking on different parameters is not working

Open stefanalfbo opened this issue 2 years ago • 0 comments

Describe the bug Trying to mock a unique result for each parameter on a RPC method, however the mocking is only working for the first parameter that is defined in the params section of the json document.

I'm probably misunderstanding something on how to create these examples correct. This issue 511 looks similar to mine but it hasn't helped to solve my issue.

To Reproduce This is a simplified version of the schema:

{
  "openrpc": "1.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Mock Server"
  },
  "methods": [
    {
      "name": "Test.Method",
      "params": [
        {
          "name": "param1",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "param2",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "result": {
        "name": "Test.Result",
        "description": "The result",
        "schema": {
          "type": "string"
        }
      },
      "examples": [
        {
          "name": "Test.Method.Example.Param1",
          "params": [
            {
              "name": "param1",
              "value": "1337 as text"
            }
          ],
          "result": {
            "name": "Test.Method.Example.Param1.Result",
            "value": "Expected.Result.Param1"
          }
        },
        {
          "name": "Test.Method.Example.Param2",
          "params": [
            {
              "name": "param2",
              "value": 1337
            }
          ],
          "result": {
            "name": "Test.Method.Example.Param2.Result",
            "value": "Expected.Result.Param2"
          }
        }
      ]
    }
  ]
}

A request that looks like this,

{"jsonrpc":"2.0","method":"Test.Method","params":{"param1":"1337 as text","param2":42},"id":0}

will give me this result,

{"id":0,"jsonrpc":"2.0","result":"Expected.Result.Param1"}

However, when I try to trigger the second result by using the defined value for param2 like this,

{"jsonrpc":"2.0","method":"Test.Method","params":{"param1":"Some text","param2":1337},"id":0}

then I receive this response.

{"id":0,"jsonrpc":"2.0","result":"Ut Excepteur incididunt"}

Expected behavior In the last example above I would expect to get the result value: Expected.Result.Param2

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.1 LTS
  • open-rpc-mock-server: 1.7.5
  • node: 18.12.1

stefanalfbo avatar Jan 16 '23 21:01 stefanalfbo