Skip to content

DisableRoutingConvention #800

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

Closed
ahmad550 opened this issue Aug 13, 2020 · 4 comments
Closed

DisableRoutingConvention #800

ahmad550 opened this issue Aug 13, 2020 · 4 comments

Comments

@ahmad550
Copy link

Description

[DisableRoutingConvention]
[Route("api/v1/companies")]

public class CompaniesController : JsonApiController

when I use DisableRoutingConvention and give it the route with same name like controller name in plural it works fine but the problem is that if i want to change the route like [Route("api/v1/todo")] the response links will not be the same as my route it will still take the result of the links as it is without disableRoutingCounvention

with same name as controller
with to do

Environment

  • JsonApiDotNetCore Version: 3 and 4
  • Other Relevant Package Versions: .net core 3.1
@bart-degreed
Copy link
Contributor

Thanks for reporting. However I cannot reproduce this on the current master branch. What I've tried is running the test CustomRouteControllers_Uses_Dasherized_Collection_Route in the repo, which uses a controller named TodoItemsCustomController with [DisableRoutingConvention, Route("custom/route/todoItems")] on it. I captured the response from GET /custom/route/todoItems and got the following:

{
  "meta": {
    "total-records": 7
  },
  "links": {
    "self": "http://localhost/custom/route/todoItems?page[size]=5&page[number]=1",
    "next": "http://localhost/custom/route/todoItems?page[size]=5&page[number]=2",
    "first": "http://localhost/custom/route/todoItems?page[size]=5&page[number]=1",
    "last": "http://localhost/custom/route/todoItems?page[size]=5&page[number]=2"
  },
  "data": [
    {
      "type": "todoItems",
      "id": "49",
      "attributes": {
        "description": "Officia dicta accusantium eum eum perferendis corporis laudantium ut.",
        "ordinal": 0,
        "guidProperty": "d378c1b4-f65e-409f-9a71-ffe5dd75f915",
        "alwaysChangingValue": "5e16696f-da09-43cb-8b80-d683eb04030d",
        "createdDate": "2020-06-30T22:22:15.951418",
        "achievedDate": null,
        "updatedDate": null,
        "calculatedValue": "calculated",
        "offsetDate": null
      },
      "relationships": {
        "owner": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/owner",
            "related": "http://localhost/custom/route/todoItems/49/owner"
          }
        },
        "assignee": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/assignee",
            "related": "http://localhost/custom/route/todoItems/49/assignee"
          }
        },
        "oneToOnePerson": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/oneToOnePerson",
            "related": "http://localhost/custom/route/todoItems/49/oneToOnePerson"
          }
        },
        "stakeHolders": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/stakeHolders",
            "related": "http://localhost/custom/route/todoItems/49/stakeHolders"
          }
        },
        "collection": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/collection",
            "related": "http://localhost/custom/route/todoItems/49/collection"
          }
        },
        "dependentOnTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/dependentOnTodo",
            "related": "http://localhost/custom/route/todoItems/49/dependentOnTodo"
          }
        },
        "parentTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/parentTodo",
            "related": "http://localhost/custom/route/todoItems/49/parentTodo"
          }
        },
        "childrenTodos": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/49/relationships/childrenTodos",
            "related": "http://localhost/custom/route/todoItems/49/childrenTodos"
          }
        }
      },
      "links": {
        "self": "http://localhost/custom/route/todoItems/49"
      }
    },
    {
      "type": "todoItems",
      "id": "50",
      "attributes": {
        "description": "Et dolorum odio similique illo omnis.",
        "ordinal": 1,
        "guidProperty": "4da62c9a-3118-4e51-8176-ad3a82f65e83",
        "alwaysChangingValue": "7add3095-af87-4b82-965b-6196f6427d51",
        "createdDate": "2020-04-23T12:18:09.186328",
        "achievedDate": null,
        "updatedDate": null,
        "calculatedValue": "calculated",
        "offsetDate": null
      },
      "relationships": {
        "owner": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/owner",
            "related": "http://localhost/custom/route/todoItems/50/owner"
          }
        },
        "assignee": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/assignee",
            "related": "http://localhost/custom/route/todoItems/50/assignee"
          }
        },
        "oneToOnePerson": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/oneToOnePerson",
            "related": "http://localhost/custom/route/todoItems/50/oneToOnePerson"
          }
        },
        "stakeHolders": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/stakeHolders",
            "related": "http://localhost/custom/route/todoItems/50/stakeHolders"
          }
        },
        "collection": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/collection",
            "related": "http://localhost/custom/route/todoItems/50/collection"
          }
        },
        "dependentOnTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/dependentOnTodo",
            "related": "http://localhost/custom/route/todoItems/50/dependentOnTodo"
          }
        },
        "parentTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/parentTodo",
            "related": "http://localhost/custom/route/todoItems/50/parentTodo"
          }
        },
        "childrenTodos": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/50/relationships/childrenTodos",
            "related": "http://localhost/custom/route/todoItems/50/childrenTodos"
          }
        }
      },
      "links": {
        "self": "http://localhost/custom/route/todoItems/50"
      }
    },
    {
      "type": "todoItems",
      "id": "52",
      "attributes": {
        "description": "Atque nemo soluta sapiente qui impedit laborum libero sequi et.",
        "ordinal": 1,
        "guidProperty": "bace5a43-00f9-405b-88dd-3cdc38ea8668",
        "alwaysChangingValue": "f6c1ff22-6176-457f-96da-cbbe5cde2406",
        "createdDate": "2020-05-27T11:11:55.147949",
        "achievedDate": null,
        "updatedDate": null,
        "calculatedValue": "calculated",
        "offsetDate": null
      },
      "relationships": {
        "owner": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/owner",
            "related": "http://localhost/custom/route/todoItems/52/owner"
          }
        },
        "assignee": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/assignee",
            "related": "http://localhost/custom/route/todoItems/52/assignee"
          }
        },
        "oneToOnePerson": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/oneToOnePerson",
            "related": "http://localhost/custom/route/todoItems/52/oneToOnePerson"
          }
        },
        "stakeHolders": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/stakeHolders",
            "related": "http://localhost/custom/route/todoItems/52/stakeHolders"
          }
        },
        "collection": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/collection",
            "related": "http://localhost/custom/route/todoItems/52/collection"
          }
        },
        "dependentOnTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/dependentOnTodo",
            "related": "http://localhost/custom/route/todoItems/52/dependentOnTodo"
          }
        },
        "parentTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/parentTodo",
            "related": "http://localhost/custom/route/todoItems/52/parentTodo"
          }
        },
        "childrenTodos": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/52/relationships/childrenTodos",
            "related": "http://localhost/custom/route/todoItems/52/childrenTodos"
          }
        }
      },
      "links": {
        "self": "http://localhost/custom/route/todoItems/52"
      }
    },
    {
      "type": "todoItems",
      "id": "53",
      "attributes": {
        "description": "Omnis voluptatum repellendus dolores nisi.",
        "ordinal": 1,
        "guidProperty": "4963d590-bdd1-4637-8fce-a3e653a0fc90",
        "alwaysChangingValue": "ba81ac53-0365-43ce-8b3e-382af3da4c4d",
        "createdDate": "2019-12-31T02:40:24.241526",
        "achievedDate": null,
        "updatedDate": null,
        "calculatedValue": "calculated",
        "offsetDate": null
      },
      "relationships": {
        "owner": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/owner",
            "related": "http://localhost/custom/route/todoItems/53/owner"
          }
        },
        "assignee": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/assignee",
            "related": "http://localhost/custom/route/todoItems/53/assignee"
          }
        },
        "oneToOnePerson": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/oneToOnePerson",
            "related": "http://localhost/custom/route/todoItems/53/oneToOnePerson"
          }
        },
        "stakeHolders": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/stakeHolders",
            "related": "http://localhost/custom/route/todoItems/53/stakeHolders"
          }
        },
        "collection": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/collection",
            "related": "http://localhost/custom/route/todoItems/53/collection"
          }
        },
        "dependentOnTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/dependentOnTodo",
            "related": "http://localhost/custom/route/todoItems/53/dependentOnTodo"
          }
        },
        "parentTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/parentTodo",
            "related": "http://localhost/custom/route/todoItems/53/parentTodo"
          }
        },
        "childrenTodos": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/53/relationships/childrenTodos",
            "related": "http://localhost/custom/route/todoItems/53/childrenTodos"
          }
        }
      },
      "links": {
        "self": "http://localhost/custom/route/todoItems/53"
      }
    },
    {
      "type": "todoItems",
      "id": "54",
      "attributes": {
        "description": "Error alias aut dolore non.",
        "ordinal": 0,
        "guidProperty": "01efa2a3-7128-4c3f-a6d1-649ae2e574f1",
        "alwaysChangingValue": "49f98f1b-81a9-40c8-8712-069e7f44e5f7",
        "createdDate": "2019-08-14T19:03:11.896882",
        "achievedDate": null,
        "updatedDate": null,
        "calculatedValue": "calculated",
        "offsetDate": null
      },
      "relationships": {
        "owner": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/owner",
            "related": "http://localhost/custom/route/todoItems/54/owner"
          }
        },
        "assignee": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/assignee",
            "related": "http://localhost/custom/route/todoItems/54/assignee"
          }
        },
        "oneToOnePerson": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/oneToOnePerson",
            "related": "http://localhost/custom/route/todoItems/54/oneToOnePerson"
          }
        },
        "stakeHolders": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/stakeHolders",
            "related": "http://localhost/custom/route/todoItems/54/stakeHolders"
          }
        },
        "collection": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/collection",
            "related": "http://localhost/custom/route/todoItems/54/collection"
          }
        },
        "dependentOnTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/dependentOnTodo",
            "related": "http://localhost/custom/route/todoItems/54/dependentOnTodo"
          }
        },
        "parentTodo": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/parentTodo",
            "related": "http://localhost/custom/route/todoItems/54/parentTodo"
          }
        },
        "childrenTodos": {
          "links": {
            "self": "http://localhost/custom/route/todoItems/54/relationships/childrenTodos",
            "related": "http://localhost/custom/route/todoItems/54/childrenTodos"
          }
        }
      },
      "links": {
        "self": "http://localhost/custom/route/todoItems/54"
      }
    }
  ]
}

Note that the custom route is used in all returned links in the response above.

Can you verify your project against the latest master branch? If you still see this problem, please provide some repro steps for us to investigate.

@ahmad550
Copy link
Author

Controller: public class CompanyController : JsonApiController

Example 1
[DisableRoutingConvention,Route("api/v1/companies")] companies plural for company (model) in this case links will work perfectly fine since last word in the custom route is same as model in plural
https://localhost:44313/api/v1/companies/1
{
"links": {
"self": "https://localhost:44313/api/v1/companies/1"
},
"data": {
"type": "companies",
"id": "1",
"attributes": {
"name": "name1",
"location": "location 1"
},
"relationships": {
"employees": {
"links": {
"self": "https://localhost:44313/api/v1/companies/1/relationships/employees",
"related": "https://localhost:44313/api/v1/companies/1/employees"
}
}
},
"links": {
"self": "https://localhost:44313/api/v1/companies/1"
}
}
}

Example 2
[DisableRoutingConvention,Route("api/v1/comp")] comp my custom route i dont want it to be same as controller name in plural so the result will be as shown bellow. there is an extra slash before companies which is not my route its the name for the model in plural , also my links must be as my custom routes
https://localhost:44313/api/v1/comp/1
{
"links": {
"self": "https://localhost:44313/api/v1//companies/1"
},
"data": {
"type": "companies",
"id": "1",
"attributes": {
"name": "name1",
"location": "location 1"
},
"relationships": {
"employees": {
"links": {
"self": "https://localhost:44313/api/v1//companies/1/relationships/employees",
"related": "https://localhost:44313/api/v1//companies/1/employees"
}
}
},
"links": {
"self": "https://localhost:44313/api/v1//companies/1"
}
}
}

@ahmad550 ahmad550 reopened this Aug 14, 2020
@bart-degreed
Copy link
Contributor

This is not supported, as described at https://json-api-dotnet.github.io/JsonApiDotNetCore/usage/routing.html, specifically:

It is important to note that your routes must still end with the model name in the same format as the resource name. This is so that we can build accurate resource links in the json:api document.

#786 already tracks the request for having a different resource name in routes. So I think this is a duplicate of that.

@maurei
Copy link
Member

maurei commented Aug 27, 2020

This is not supported, as described at https://json-api-dotnet.github.io/JsonApiDotNetCore/usage/routing.html, specifically:

It is important to note that your routes must still end with the model name in the same format as the resource name. This is so that we can build accurate resource links in the json:api document.

#786 already tracks the request for having a different resource name in routes. So I think this is a duplicate of that.

@ahmad550, this is not correct. See #805 (comment)

Docs have been updated in that PR. Please check it out

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

No branches or pull requests

3 participants