@@ -174,28 +174,28 @@ describe('endpoint overrides', () => {
174
174
} ) ;
175
175
} ) ;
176
176
177
- describe ( 'option encodeParams ' , ( ) => {
177
+ describe ( 'option encodePathParams ' , ( ) => {
178
178
const config = {
179
179
apiFile : './fixtures/emptyApi.ts' ,
180
180
schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
181
- encodeParams : true ,
181
+ encodePathParams : true ,
182
182
} ;
183
183
184
- it ( 'should encode query parameters' , async ( ) => {
184
+ it ( 'should encode path parameters' , async ( ) => {
185
185
const api = await generateEndpoints ( {
186
186
...config ,
187
- filterEndpoints : [ 'findPetsByStatus ' ] ,
187
+ filterEndpoints : [ 'getOrderById ' ] ,
188
188
} ) ;
189
- expect ( api ) . toContain ( 'status: encodeURIComponent(String(queryArg.status))' ) ;
189
+ // eslint-disable-next-line no-template-curly-in-string
190
+ expect ( api ) . toContain ( '`/store/order/${encodeURIComponent(String(queryArg.orderId))}`' ) ;
190
191
} ) ;
191
192
192
- it ( 'should encode path parameters' , async ( ) => {
193
+ it ( 'should not encode query parameters' , async ( ) => {
193
194
const api = await generateEndpoints ( {
194
195
...config ,
195
- filterEndpoints : [ 'getOrderById ' ] ,
196
+ filterEndpoints : [ 'findPetsByStatus ' ] ,
196
197
} ) ;
197
- // eslint-disable-next-line no-template-curly-in-string
198
- expect ( api ) . toContain ( '`/store/order/${encodeURIComponent(String(queryArg.orderId))}`' ) ;
198
+ expect ( api ) . toContain ( 'status: queryArg.status' ) ;
199
199
} ) ;
200
200
201
201
it ( 'should not encode body parameters' , async ( ) => {
@@ -217,18 +217,63 @@ describe('option encodeParams', () => {
217
217
expect ( api ) . toContain ( '`/store/order/${encodeURIComponent(String(queryArg))}`' ) ;
218
218
} ) ;
219
219
220
- it ( 'should not encode parameters when encodeParams is false' , async ( ) => {
220
+ it ( 'should not encode path parameters when encodePathParams is false' , async ( ) => {
221
221
const api = await generateEndpoints ( {
222
222
...config ,
223
- encodeParams : false ,
223
+ encodePathParams : false ,
224
224
filterEndpoints : [ 'findPetsByStatus' , 'getOrderById' ] ,
225
225
} ) ;
226
- expect ( api ) . toContain ( 'status: queryArg.status' ) ;
227
226
// eslint-disable-next-line no-template-curly-in-string
228
227
expect ( api ) . toContain ( '`/store/order/${queryArg.orderId}`' ) ;
229
228
} ) ;
230
229
} ) ;
231
230
231
+ describe ( 'option encodeQueryParams' , ( ) => {
232
+ const config = {
233
+ apiFile : './fixtures/emptyApi.ts' ,
234
+ schemaFile : resolve ( __dirname , 'fixtures/petstore.json' ) ,
235
+ encodeQueryParams : true ,
236
+ } ;
237
+
238
+ it ( 'should conditionally encode query parameters' , async ( ) => {
239
+ const api = await generateEndpoints ( {
240
+ ...config ,
241
+ filterEndpoints : [ 'findPetsByStatus' ] ,
242
+ } ) ;
243
+
244
+ expect ( api ) . toMatch (
245
+ / p a r a m s : \s * { \s * \n \s * s t a t u s : \s * q u e r y A r g \. s t a t u s \s * \? \s * e n c o d e U R I C o m p o n e n t \( \s * S t r i n g \( q u e r y A r g \. s t a t u s \) \s * \) \s * : \s * u n d e f i n e d \s * , ? \s * \n \s * } / s
246
+ ) ;
247
+ } ) ;
248
+
249
+ it ( 'should not encode path parameters' , async ( ) => {
250
+ const api = await generateEndpoints ( {
251
+ ...config ,
252
+ filterEndpoints : [ 'getOrderById' ] ,
253
+ } ) ;
254
+ // eslint-disable-next-line no-template-curly-in-string
255
+ expect ( api ) . toContain ( '`/store/order/${queryArg.orderId}`' ) ;
256
+ } ) ;
257
+
258
+ it ( 'should not encode body parameters' , async ( ) => {
259
+ const api = await generateEndpoints ( {
260
+ ...config ,
261
+ filterEndpoints : [ 'addPet' ] ,
262
+ } ) ;
263
+ expect ( api ) . toContain ( 'body: queryArg.pet' ) ;
264
+ expect ( api ) . not . toContain ( 'body: encodeURIComponent(String(queryArg.pet))' ) ;
265
+ } ) ;
266
+
267
+ it ( 'should not encode query parameters when encodeQueryParams is false' , async ( ) => {
268
+ const api = await generateEndpoints ( {
269
+ ...config ,
270
+ encodeQueryParams : false ,
271
+ filterEndpoints : [ 'findPetsByStatus' , 'getOrderById' ] ,
272
+ } ) ;
273
+ expect ( api ) . toContain ( 'status: queryArg.status' ) ;
274
+ } ) ;
275
+ } ) ;
276
+
232
277
describe ( 'option flattenArg' , ( ) => {
233
278
const config = {
234
279
apiFile : './fixtures/emptyApi.ts' ,
0 commit comments