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 ,
@@ -132,11 +133,21 @@ data Paginated a = Paginated
132
133
{ meta :: PaginatedMeta
133
134
, items :: [a ]
134
135
}
135
- deriving (Generic )
136
+ deriving (Generic , Show )
136
137
137
- instance ToJSON a => ToJSON (Paginated a )
138
- instance FromJSON a => FromJSON (Paginated a )
139
- instance ToSchema a => ToSchema (Paginated a )
138
+ -- We may well need more instances than just Paginated Session in the future.
139
+ -- However, giving polymorphic `instance To... (Paginated a)` can generate
140
+ -- a schema inconsistent with the ToJSON for some 'a'.
141
+ -- This happens because aeson and openapi3 differ in their special handling
142
+ -- for lists (e.g. to serialise strings as strings rather than arrays of
143
+ -- characters). In particular the instance for 'Paginated Char' is broken.
144
+ -- See https://github.com/biocad/openapi3/issues/58
145
+ -- We prefer to explicitly list the particular instances we need, rather
146
+ -- than having a known broken polymorphic instance, even if we expect to
147
+ -- never hit the broken case.
148
+ instance ToJSON (Paginated Session )
149
+ instance FromJSON (Paginated Session )
150
+ instance ToSchema (Paginated Session )
140
151
141
152
-- Used solely for nice bounds in schema
142
153
newtype NonNeg = NonNeg Int
0 commit comments