diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/ClientGeneratedIdsStartup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/ClientGeneratedIdsStartup.cs
index 10255d6727..8f60d43a62 100644
--- a/src/Examples/JsonApiDotNetCoreExample/Startups/ClientGeneratedIdsStartup.cs
+++ b/src/Examples/JsonApiDotNetCoreExample/Startups/ClientGeneratedIdsStartup.cs
@@ -15,8 +15,8 @@ namespace JsonApiDotNetCoreExample
public class ClientGeneratedIdsStartup : Startup
{
public ClientGeneratedIdsStartup(IWebHostEnvironment env)
- : base (env)
- { }
+ : base(env)
+ { }
public override void ConfigureServices(IServiceCollection services)
{
@@ -41,4 +41,4 @@ public override void ConfigureServices(IServiceCollection services)
mvcBuilder: mvcBuilder);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs b/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs
new file mode 100644
index 0000000000..a15b71c2c5
--- /dev/null
+++ b/src/Examples/JsonApiDotNetCoreExample/Startups/NoDefaultPageSizeStartup.cs
@@ -0,0 +1,43 @@
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using JsonApiDotNetCoreExample.Data;
+using Microsoft.EntityFrameworkCore;
+using JsonApiDotNetCore.Extensions;
+using System.Reflection;
+
+namespace JsonApiDotNetCoreExample
+{
+ ///
+ /// This should be in JsonApiDotNetCoreExampleTests project but changes in .net core 3.0
+ /// do no longer allow that. See https://github.com/aspnet/AspNetCore/issues/15373.
+ ///
+ public class NoDefaultPageSizeStartup : Startup
+ {
+ public NoDefaultPageSizeStartup(IWebHostEnvironment env)
+ : base(env)
+ { }
+
+ public override void ConfigureServices(IServiceCollection services)
+ {
+ var loggerFactory = new LoggerFactory();
+ var mvcBuilder = services.AddMvcCore();
+ services
+ .AddSingleton(loggerFactory)
+ .AddLogging(builder =>
+ {
+ builder.AddConsole();
+ })
+ .AddDbContext(options => options.UseNpgsql(GetDbConnectionString()), ServiceLifetime.Transient)
+ .AddJsonApi(options => {
+ options.Namespace = "api/v1";
+ options.IncludeTotalRecordCount = true;
+ options.EnableResourceHooks = true;
+ options.LoaDatabaseValues = true;
+ options.AllowClientGeneratedIds = true;
+ },
+ discovery => discovery.AddAssembly(Assembly.Load(nameof(JsonApiDotNetCoreExample))),
+ mvcBuilder: mvcBuilder);
+ }
+ }
+}
diff --git a/src/Examples/NoEntityFrameworkExample/.gitignore b/src/Examples/NoEntityFrameworkExample/.gitignore
index 0ca27f04e1..700191e656 100644
--- a/src/Examples/NoEntityFrameworkExample/.gitignore
+++ b/src/Examples/NoEntityFrameworkExample/.gitignore
@@ -22,6 +22,8 @@ bld/
[Bb]in/
[Oo]bj/
+Properties/launchSettings.json
+
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
diff --git a/src/Examples/NoEntityFrameworkExample/Properties/launchSettings.json b/src/Examples/NoEntityFrameworkExample/Properties/launchSettings.json
deleted file mode 100644
index 1dff6cfe69..0000000000
--- a/src/Examples/NoEntityFrameworkExample/Properties/launchSettings.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:57181/",
- "sslPort": 0
- }
- },
- "profiles": {
- "NoEntityFrameworkExample": {
- "commandName": "Project",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- },
- "applicationUrl": "http://localhost:5000/"
- },
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs b/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs
index 76f56baf6a..017773d3d6 100644
--- a/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs
+++ b/src/JsonApiDotNetCore/QueryParameterServices/Contracts/IPageService.cs
@@ -14,19 +14,13 @@ public interface IPageService : IQueryParameterService
///
int PageSize { get; set; }
///
- /// What is the default page size
- ///
- int DefaultPageSize { get; set; }
- ///
/// What page are we currently on
///
int CurrentPage { get; set; }
-
///
/// Total amount of pages for request
///
int TotalPages { get; }
-
///
/// Checks if pagination is enabled
///
diff --git a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs
index d4aa5052ee..6f1559246c 100644
--- a/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs
+++ b/src/JsonApiDotNetCore/QueryParameterServices/PageService.cs
@@ -15,7 +15,6 @@ public class PageService : QueryParameterService, IPageService
public PageService(IJsonApiOptions options)
{
_options = options;
- DefaultPageSize = _options.DefaultPageSize;
PageSize = _options.DefaultPageSize;
}
///
@@ -23,11 +22,9 @@ public PageService(IJsonApiOptions options)
///
public int PageSize { get; set; }
///
- public int DefaultPageSize { get; set; } // I think we shouldnt expose this
- ///
public int CurrentPage { get; set; }
///
- public int TotalPages => (TotalRecords == null) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize));
+ public int TotalPages => (TotalRecords == null || PageSize == 0) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize));
///
public virtual void Parse(KeyValuePair queryParameter)
diff --git a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs
index 77be87e23a..40d82b8888 100644
--- a/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs
+++ b/test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/FetchingDataTests.cs
@@ -1,4 +1,5 @@
-using System.Net;
+using System.Linq;
+using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Bogus;
@@ -96,5 +97,31 @@ public async Task Included_Records_Contain_Relationship_Links()
Assert.Equal($"http://localhost/api/v1/people/{person.Id}/relationships/todo-items", deserializedBody.Included[0].Relationships["todo-items"].Links.Self);
context.Dispose();
}
+
+ [Fact]
+ public async Task GetResources_NoDefaultPageSize_ReturnsResources()
+ {
+ // Arrange
+ var context = _fixture.GetService();
+ var todoItems = _todoItemFaker.Generate(20).ToList();
+ context.TodoItems.AddRange(todoItems);
+ await context.SaveChangesAsync();
+
+ var builder = new WebHostBuilder()
+ .UseStartup();
+ var httpMethod = new HttpMethod("GET");
+ var route = $"/api/v1/todo-items";
+ var server = new TestServer(builder);
+ var client = server.CreateClient();
+ var request = new HttpRequestMessage(httpMethod, route);
+
+ // Act
+ var response = await client.SendAsync(request);
+ var body = await response.Content.ReadAsStringAsync();
+ var result = _fixture.GetDeserializer().DeserializeList(body);
+
+ // Assert
+ Assert.True(result.Data.Count >= 20);
+ }
}
}