Paging params in API docs

Closes #6003
This commit is contained in:
Mark McDowall 2023-09-07 21:59:00 -07:00
parent b4ef873cc3
commit 4cf7c89282
8 changed files with 279 additions and 37 deletions

View File

@ -158,6 +158,8 @@ namespace NzbDrone.Host
{
{ apikeyQuery, Array.Empty<string>() }
});
c.DescribeAllParametersInCamelCase();
});
services

View File

@ -23,9 +23,9 @@ namespace Sonarr.Api.V3.Blocklist
[HttpGet]
[Produces("application/json")]
public PagingResource<BlocklistResource> GetBlocklist()
public PagingResource<BlocklistResource> GetBlocklist([FromQuery] PagingRequestResource paging)
{
var pagingResource = Request.ReadPagingResourceFromRequest<BlocklistResource>();
var pagingResource = new PagingResource<BlocklistResource>(paging);
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
return pagingSpec.ApplyToPage(_blocklistService.Paged, model => BlocklistResourceMapper.MapToResource(model, _formatCalculator));

View File

@ -61,9 +61,9 @@ namespace Sonarr.Api.V3.History
[HttpGet]
[Produces("application/json")]
public PagingResource<HistoryResource> GetHistory(bool includeSeries, bool includeEpisode)
public PagingResource<HistoryResource> GetHistory([FromQuery] PagingRequestResource paging, bool includeSeries, bool includeEpisode)
{
var pagingResource = Request.ReadPagingResourceFromRequest<HistoryResource>();
var pagingResource = new PagingResource<HistoryResource>(paging);
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, EpisodeHistory>("date", SortDirection.Descending);
var eventTypeFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "eventType");

View File

@ -18,9 +18,9 @@ namespace Sonarr.Api.V3.Logs
[HttpGet]
[Produces("application/json")]
public PagingResource<LogResource> GetLogs()
public PagingResource<LogResource> GetLogs([FromQuery] PagingRequestResource paging)
{
var pagingResource = Request.ReadPagingResourceFromRequest<LogResource>();
var pagingResource = new PagingResource<LogResource>(paging);
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>();
if (pageSpec.SortKey == "time")

View File

@ -29,9 +29,9 @@ namespace Sonarr.Api.V3.Wanted
[HttpGet]
[Produces("application/json")]
public PagingResource<EpisodeResource> GetCutoffUnmetEpisodes(bool includeSeries = false, bool includeEpisodeFile = false, bool includeImages = false)
public PagingResource<EpisodeResource> GetCutoffUnmetEpisodes([FromQuery] PagingRequestResource paging, bool includeSeries = false, bool includeEpisodeFile = false, bool includeImages = false)
{
var pagingResource = Request.ReadPagingResourceFromRequest<EpisodeResource>();
var pagingResource = new PagingResource<EpisodeResource>(paging);
var pagingSpec = new PagingSpec<Episode>
{
Page = pagingResource.Page,

View File

@ -25,9 +25,9 @@ namespace Sonarr.Api.V3.Wanted
[HttpGet]
[Produces("application/json")]
public PagingResource<EpisodeResource> GetMissingEpisodes(bool includeSeries = false, bool includeImages = false)
public PagingResource<EpisodeResource> GetMissingEpisodes([FromQuery] PagingRequestResource paging, bool includeSeries = false, bool includeImages = false)
{
var pagingResource = Request.ReadPagingResourceFromRequest<EpisodeResource>();
var pagingResource = new PagingResource<EpisodeResource>(paging);
var pagingSpec = new PagingSpec<Episode>
{
Page = pagingResource.Page,

View File

@ -59,25 +59,25 @@
"schema": {
"type": "object",
"properties": {
"Username": {
"username": {
"type": "string"
},
"Password": {
"password": {
"type": "string"
},
"RememberMe": {
"rememberMe": {
"type": "string"
}
}
},
"encoding": {
"Username": {
"username": {
"style": "form"
},
"Password": {
"password": {
"style": "form"
},
"RememberMe": {
"rememberMe": {
"style": "form"
}
}
@ -381,6 +381,50 @@
"tags": [
"Blocklist"
],
"parameters": [
{
"name": "page",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 1
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 10
}
},
{
"name": "sortKey",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "sortDirection",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortDirection"
}
},
{
"name": "filters",
"in": "query",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PagingResourceFilter"
}
}
}
],
"responses": {
"200": {
"description": "Success",
@ -1050,6 +1094,48 @@
"Cutoff"
],
"parameters": [
{
"name": "page",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 1
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 10
}
},
{
"name": "sortKey",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "sortDirection",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortDirection"
}
},
{
"name": "filters",
"in": "query",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PagingResourceFilter"
}
}
},
{
"name": "includeSeries",
"in": "query",
@ -2220,6 +2306,48 @@
"History"
],
"parameters": [
{
"name": "page",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 1
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 10
}
},
{
"name": "sortKey",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "sortDirection",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortDirection"
}
},
{
"name": "filters",
"in": "query",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PagingResourceFilter"
}
}
},
{
"name": "includeSeries",
"in": "query",
@ -3627,6 +3755,50 @@
"tags": [
"Log"
],
"parameters": [
{
"name": "page",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 1
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 10
}
},
{
"name": "sortKey",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "sortDirection",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortDirection"
}
},
{
"name": "filters",
"in": "query",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PagingResourceFilter"
}
}
}
],
"responses": {
"200": {
"description": "Success",
@ -4142,6 +4314,48 @@
"Missing"
],
"parameters": [
{
"name": "page",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 1
}
},
{
"name": "pageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 10
}
},
{
"name": "sortKey",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "sortDirection",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortDirection"
}
},
{
"name": "filters",
"in": "query",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PagingResourceFilter"
}
}
},
{
"name": "includeSeries",
"in": "query",
@ -4325,21 +4539,21 @@
],
"parameters": [
{
"name": "RenameEpisodes",
"name": "renameEpisodes",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "ReplaceIllegalCharacters",
"name": "replaceIllegalCharacters",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "ColonReplacementFormat",
"name": "colonReplacementFormat",
"in": "query",
"schema": {
"type": "integer",
@ -4347,7 +4561,7 @@
}
},
{
"name": "MultiEpisodeStyle",
"name": "multiEpisodeStyle",
"in": "query",
"schema": {
"type": "integer",
@ -4355,91 +4569,91 @@
}
},
{
"name": "StandardEpisodeFormat",
"name": "standardEpisodeFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "DailyEpisodeFormat",
"name": "dailyEpisodeFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "AnimeEpisodeFormat",
"name": "animeEpisodeFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "SeriesFolderFormat",
"name": "seriesFolderFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "SeasonFolderFormat",
"name": "seasonFolderFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "SpecialsFolderFormat",
"name": "specialsFolderFormat",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "IncludeSeriesTitle",
"name": "includeSeriesTitle",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "IncludeEpisodeTitle",
"name": "includeEpisodeTitle",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "IncludeQuality",
"name": "includeQuality",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "ReplaceSpaces",
"name": "replaceSpaces",
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "Separator",
"name": "separator",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "NumberStyle",
"name": "numberStyle",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "Id",
"name": "id",
"in": "query",
"schema": {
"type": "integer",
@ -4447,7 +4661,7 @@
}
},
{
"name": "ResourceName",
"name": "resourceName",
"in": "query",
"schema": {
"type": "string"
@ -7402,7 +7616,7 @@
"type": "array",
"items": {
"type": "object",
"additionalProperties": { }
"additionalProperties": {}
},
"nullable": true
}
@ -11628,10 +11842,10 @@
},
"security": [
{
"X-Api-Key": [ ]
"X-Api-Key": []
},
{
"apikey": [ ]
"apikey": []
}
]
}

View File

@ -1,8 +1,20 @@
using System.Collections.Generic;
using System.ComponentModel;
using NzbDrone.Core.Datastore;
namespace Sonarr.Http
{
public class PagingRequestResource
{
[DefaultValue(1)]
public int? Page { get; set; }
[DefaultValue(10)]
public int? PageSize { get; set; }
public string SortKey { get; set; }
public SortDirection? SortDirection { get; set; }
public List<PagingResourceFilter> Filters { get; set; }
}
public class PagingResource<TResource>
{
public int Page { get; set; }
@ -10,8 +22,22 @@ namespace Sonarr.Http
public string SortKey { get; set; }
public SortDirection SortDirection { get; set; }
public List<PagingResourceFilter> Filters { get; set; }
public int TotalRecords { get; set; }
public List<TResource> Records { get; set; }
public PagingResource()
{
}
public PagingResource(PagingRequestResource requestResource)
{
Page = requestResource.Page ?? 1;
PageSize = requestResource.PageSize ?? 10;
SortKey = requestResource.SortKey;
SortDirection = requestResource.SortDirection ?? SortDirection.Descending;
Filters = requestResource.Filters ?? new List<PagingResourceFilter>();
}
}
public static class PagingResourceMapper