@@ -78,12 +78,14 @@ describe('operationPagination', () => {
78
78
const queryParam = (
79
79
name : string ,
80
80
type : IR . SchemaObject [ 'type' ] = 'string' ,
81
+ pagination = false ,
81
82
) : IR . ParameterObject => ( {
82
- explode : true ,
83
- location : 'query' ,
84
83
name,
84
+ location : 'query' ,
85
85
schema : { type } ,
86
86
style : 'form' ,
87
+ explode : true ,
88
+ ...( pagination ? { pagination : true } : { } ) ,
87
89
} ) ;
88
90
89
91
const emptyContext = { } as IR . Context ;
@@ -105,8 +107,7 @@ describe('operationPagination', () => {
105
107
method : 'get' ,
106
108
parameters : {
107
109
query : {
108
- page : queryParam ( 'page' , 'integer' ) ,
109
- perPage : queryParam ( 'perPage' , 'integer' ) ,
110
+ page : queryParam ( 'page' , 'integer' , true ) ,
110
111
} ,
111
112
} ,
112
113
} ,
@@ -128,7 +129,7 @@ describe('operationPagination', () => {
128
129
129
130
it . each ( queryScenarios ) (
130
131
'query params for $operation.id → $hasPagination' ,
131
- ( { hasPagination, operation } ) => {
132
+ ( { hasPagination, operation } : { hasPagination : boolean ; operation : IR . OperationObject } ) => {
132
133
const result = operationPagination ( { context : emptyContext , operation } ) ;
133
134
expect ( Boolean ( result ) ) . toEqual ( hasPagination ) ;
134
135
} ,
@@ -137,17 +138,17 @@ describe('operationPagination', () => {
137
138
it ( 'body.pagination === true returns entire body' , ( ) => {
138
139
const operation : IR . OperationObject = {
139
140
...baseOperationMeta ,
141
+ id : 'bodyTrue' ,
140
142
body : {
141
143
mediaType : 'application/json' ,
142
144
pagination : true ,
143
145
schema : {
146
+ type : 'object' ,
144
147
properties : {
145
148
page : { type : 'integer' } ,
146
149
} ,
147
- type : 'object' ,
148
150
} ,
149
151
} ,
150
- id : 'bodyTrue' ,
151
152
} ;
152
153
153
154
const result = operationPagination ( { context : emptyContext , operation } ) ;
@@ -160,22 +161,22 @@ describe('operationPagination', () => {
160
161
it ( 'body.pagination = "pagination" returns the matching property' , ( ) => {
161
162
const operation : IR . OperationObject = {
162
163
...baseOperationMeta ,
164
+ id : 'bodyField' ,
163
165
body : {
164
166
mediaType : 'application/json' ,
165
167
pagination : 'pagination' ,
166
168
schema : {
169
+ type : 'object' ,
167
170
properties : {
168
171
pagination : {
172
+ type : 'object' ,
169
173
properties : {
170
174
page : { type : 'integer' } ,
171
175
} ,
172
- type : 'object' ,
173
176
} ,
174
177
} ,
175
- type : 'object' ,
176
178
} ,
177
179
} ,
178
- id : 'bodyField' ,
179
180
} ;
180
181
181
182
const result = operationPagination ( { context : emptyContext , operation } ) ;
@@ -188,26 +189,26 @@ describe('operationPagination', () => {
188
189
it ( 'resolves $ref and uses the resolved pagination property' , ( ) => {
189
190
const context : IR . Context = {
190
191
resolveIrRef : vi . fn ( ) . mockReturnValue ( {
192
+ type : 'object' ,
191
193
properties : {
192
194
pagination : {
195
+ type : 'object' ,
193
196
properties : {
194
197
page : { type : 'integer' } ,
195
198
} ,
196
- type : 'object' ,
197
199
} ,
198
200
} ,
199
- type : 'object' ,
200
201
} ) ,
201
202
} as unknown as IR . Context ;
202
203
203
204
const operation : IR . OperationObject = {
204
205
...baseOperationMeta ,
206
+ id : 'refPagination' ,
205
207
body : {
206
208
mediaType : 'application/json' ,
207
209
pagination : 'pagination' ,
208
210
schema : { $ref : '#/components/schemas/PaginationBody' } ,
209
211
} ,
210
- id : 'refPagination' ,
211
212
} ;
212
213
213
214
const result = operationPagination ( { context, operation } ) ;
@@ -223,27 +224,28 @@ describe('operationPagination', () => {
223
224
it ( 'falls back to query when pagination key not found in body' , ( ) => {
224
225
const operation : IR . OperationObject = {
225
226
...baseOperationMeta ,
227
+ id : 'fallback' ,
228
+ parameters : {
229
+ query : {
230
+ cursor : queryParam ( 'cursor' , 'string' , true ) ,
231
+ } ,
232
+ } ,
226
233
body : {
227
234
mediaType : 'application/json' ,
228
235
pagination : 'pagination' ,
229
236
schema : {
237
+ type : 'object' ,
230
238
properties : {
231
239
notPagination : { type : 'string' } ,
232
240
} ,
233
- type : 'object' ,
234
- } ,
235
- } ,
236
- id : 'fallback' ,
237
- parameters : {
238
- query : {
239
- cursor : queryParam ( 'cursor' , 'string' ) ,
240
241
} ,
241
242
} ,
242
243
} ;
243
244
244
245
const result = operationPagination ( { context : emptyContext , operation } ) ;
245
246
246
247
expect ( result ?. in ) . toEqual ( 'query' ) ;
247
- expect ( result ?. schema ?. properties ?. cursor ) . toBeDefined ( ) ;
248
+ expect ( result ?. name ) . toEqual ( 'cursor' ) ;
249
+ expect ( result ?. schema ?. type ) . toEqual ( 'string' ) ;
248
250
} ) ;
249
- } ) ;
251
+ } ) ;
0 commit comments