json-api-dotnet / JsonApiDotNetCore

A framework for building JSON:API compliant REST APIs using ASP.NET and Entity Framework Core.

Home Page:https://www.jsonapi.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TopLevelLinks All / Paging does not work as expected

patcharees opened this issue · comments

Set TopLevelLinks.All or TopLevelLinks.Paging but does not get expected links.

DESCRIPTION

On start up

services.AddJsonApi(
    options =>
    {
        options.Namespace = "api/v1";
        options.IncludeTotalResourceCount = true;
        options.DefaultPageSize = new PageSize(100); 
        options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver()
        {
            NamingStrategy = new Newtonsoft.Json.Serialization.CamelCaseNamingStrategy(false, false),
        };
        options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
        options.ValidateModelState = true;

        options.UseRelativeLinks = true;
        options.TopLevelLinks = JsonApiDotNetCore.Resources.Annotations.LinkTypes.All;
        options.RelationshipLinks = JsonApiDotNetCore.Resources.Annotations.LinkTypes.None;
    },
    resources: builder =>
    {
        builder.Add<Resource1, string>("res1");
        builder.Add<Resource2, string>("res2");
        builder.Add<Resource3, string>("res3");
    });

EXPECTED BEHAVIOR

{
"links": {
"self": "/api/v1/books",
"first": "/api/v1/books?page[size]=100",
"last":
"prev":
"next":
},
...
}

ACTUAL BEHAVIOR

{
"links": {
"self": "/api/v1/books",
"first": "/api/v1/books?page[size]=100"
},
...
}

VERSIONS USED

  • JsonApiDotNetCore version: 4.20

Another test
http://localhost:21000/api/v1/books?page[number]=3

Got below

{
    "links": {
        "self": "/api/v1/books?page[number]=3",
        "first": "/api/v1/books?page[size]=100",
        "prev": "/api/v1/books?page[number]=2&page[size]=100"
    },
    ...
}    

No next, no last

Otherwise, try with the latest version.