dotnet-fake-json-server icon indicating copy to clipboard operation
dotnet-fake-json-server copied to clipboard

Controller Path/Tree Support

Open Shanjaq opened this issue 5 years ago • 1 comments

using a web service tree with controller paths like:

garage/v3.0/storage/Bins garage/v3.0/storage/Shelves garage/v3.0/workbench/Tools

I haven't been able to figure out how to mock these, even manually editing datastore.json as follows and calling Reload:

{ "garage/v3.0/storage/Bins": [ { "Type": "Large", "id": 0 }, { "Type": "Small", "id": 1 } ] }

I see there is support for nested items, but this requires specifying an item ID at each level which will not match the paths used by the real service.

Shanjaq avatar Mar 19 '20 07:03 Shanjaq

Thanks for the issue.

Unfortunately this kind of path/naming is not supported.

curl -X GET "http://localhost:57603/api/garage/v3.0/storage/bins" -H "accept: application/json"

Now API tries to look for items, with these parameters:

collection=garage
id=v3.0
path=storage/bins

Supporting slashes in collection names could be possible, but would require lots of changes as current implementation relies on dividing the request by slashes.

{
  "garage/v3.0/storage/bins": [
    {
      "type": "Large",
      "id": 0
    },
    {
      "type": "Small",
      "id": 1
    }
  ],
  "garage/v3.0/storage/shelves": [
    {
      "type": "Large",
      "id": 0
    },
    {
      "type": "Small",
      "id": 1
    }
  ],
}

As you mentioned you can get this almost working by using nested items.

Change ApiRoute from Config file:

public class Config
{
	public const string ApiRoute = "garage/v3.0";
	public const string AsyncRoute = "async";
	public const string GraphQLRoute = "graphql";
	public const string TokenRoute = "token";
	public const string TokenLogoutRoute = "logout";
}

Json file should be like this:

{
  "storage": [
    {
      "id": "bins",
      "bins": [
        {
          "type": "Large",
          "id": "0"
        },
        {
          "type": "Small",
          "id": "1"
        }
      ]
    },
    {
      "id": "shelves",
      "shelves": [
        {
          "type": "High",
          "id": "0"
        },
        {
          "type": "Low",
          "id": "1"
        }
      ]
    }
  ]
}

Query has unfortunately double bins as now bins is an id and the name of the collection property.

curl -X GET "http://localhost:57603/api/garage/v3.0/storage/bins/bins/0" -H "accept: application/json"

Correct implementation would be that single items would support searching for nested properties. Now only collections support that.

Then we could query inside an item. Now only whole item can be returned.

curl -X GET "http://localhost:57603/api/garage/v3.0/storage/" -H "accept: application/json"
{
  "storage": {
    "bins": [
      {
        "type": "Large",
        "id": 0
      },
      {
        "type": "Small",
        "id": 1
      }
    ],
    "shelves": [
      {
        "type": "High",
        "id": 0
      },
      {
        "type": "Low",
        "id": 1
      }
    ]
  },
  "workbench": {
    "tools": [
      {
        "type": "Hammer",
        "id": 0
      },
      {
        "type": "Saw",
        "id": 1
      }
    ]
  }
}

Have to think what would be the best way to implement this.

ttu avatar Mar 22 '20 06:03 ttu