6
6
module Primer.Pagination (
7
7
PaginationParams ,
8
8
Pagination (.. ),
9
- Paginated ,
9
+ -- Constructor and field accessors of Pagination exported for testing
10
+ Paginated (.. ),
10
11
-- 'Positive' is abstract. Do not export its constructor.
11
12
Positive (getPositive ),
12
13
mkPositive ,
13
14
pagedDefaultClamp ,
14
15
-- the following are exposed for testing
15
- meta ,
16
16
PaginatedMeta (PM ),
17
17
totalItems ,
18
18
pageSize ,
@@ -21,7 +21,6 @@ module Primer.Pagination (
21
21
thisPage ,
22
22
nextPage ,
23
23
lastPage ,
24
- items ,
25
24
getNonNeg ,
26
25
NonNeg ,
27
26
mkNonNeg ,
@@ -36,7 +35,9 @@ import Optics ((?~))
36
35
import Primer.Database (
37
36
OffsetLimit (OL , limit , offset ),
38
37
Page (Page , pageContents , total ),
38
+ Session ,
39
39
)
40
+ import Primer.OpenAPI ()
40
41
import Servant (
41
42
DefaultErrorFormatters ,
42
43
ErrorFormatters ,
@@ -108,10 +109,20 @@ data Paginated a = Paginated
108
109
{ meta :: PaginatedMeta
109
110
, items :: [a ]
110
111
}
111
- deriving (Generic )
112
+ deriving (Generic , Show )
112
113
113
- instance ToJSON a => ToJSON (Paginated a )
114
- instance ToSchema a => ToSchema (Paginated a )
114
+ -- We may well need more instances than just Paginated Session in the future.
115
+ -- However, giving polymorphic `instance To... (Paginated a)` can generate
116
+ -- a schema inconsistent with the ToJSON for some 'a'.
117
+ -- This happens because aeson and openapi3 differ in their special handling
118
+ -- for lists (e.g. to serialise strings as strings rather than arrays of
119
+ -- characters). In particular the instance for 'Paginated Char' is broken.
120
+ -- See https://github.com/biocad/openapi3/issues/58
121
+ -- We prefer to explicitly list the particular instances we need, rather
122
+ -- than having a known broken polymorphic instance, even if we expect to
123
+ -- never hit the broken case.
124
+ instance ToJSON (Paginated Session )
125
+ instance ToSchema (Paginated Session )
115
126
116
127
-- Used solely for nice bounds in schema
117
128
newtype NonNeg = NonNeg Int
0 commit comments