@@ -250,11 +250,11 @@ self = module.exports = {
250
250
description : 'Remove white space and additional lines that may affect the server\'s response'
251
251
} ,
252
252
{
253
- name : 'Follow redirects ' ,
254
- id : 'followRedirect ' ,
253
+ name : 'Include boilerplate ' ,
254
+ id : 'includeBoilerplate ' ,
255
255
type : 'boolean' ,
256
- default : true ,
257
- description : 'Automatically follow HTTP redirects '
256
+ default : false ,
257
+ description : 'Include class definition and import statements in snippet '
258
258
}
259
259
] ;
260
260
} ,
@@ -286,15 +286,15 @@ self = module.exports = {
286
286
throw new Error ( 'Swift-Converter: callback is not valid function' ) ;
287
287
}
288
288
options = sanitizeOptions ( options , self . getOptions ( ) ) ;
289
- var codeSnippet , indent , trim , timeout , finalUrl , // followRedirect,
289
+ var indent , trim , timeout , finalUrl ,
290
+ codeSnippet = '' ,
290
291
bodySnippet = '' ,
291
292
headerSnippet = '' ,
292
293
requestBody ;
293
294
294
295
indent = options . indentType === 'Tab' ? '\t' : ' ' ;
295
296
indent = indent . repeat ( options . indentCount ) ;
296
297
timeout = options . requestTimeout ;
297
- // followRedirect = options.followRedirect;
298
298
trim = options . trimRequestBody ;
299
299
finalUrl = getUrlStringfromUrlObject ( request . url ) ;
300
300
@@ -342,9 +342,10 @@ self = module.exports = {
342
342
requestBody = ( request . body ? request . body . toJSON ( ) : { } ) ;
343
343
bodySnippet = parseBody ( requestBody , trim , indent ) ;
344
344
345
- codeSnippet = 'import Foundation\n' ;
346
- codeSnippet += '#if canImport(FoundationNetworking)\nimport FoundationNetworking\n#endif\n\n' ;
347
- codeSnippet += 'var semaphore = DispatchSemaphore (value: 0)\n\n' ;
345
+ if ( options . includeBoilerplate ) {
346
+ codeSnippet += 'import Foundation\n' ;
347
+ codeSnippet += '#if canImport(FoundationNetworking)\nimport FoundationNetworking\n#endif\n\n' ;
348
+ }
348
349
if ( bodySnippet !== '' ) {
349
350
codeSnippet += `${ bodySnippet } \n\n` ;
350
351
}
@@ -375,13 +376,14 @@ self = module.exports = {
375
376
codeSnippet += '\nlet task = URLSession.shared.dataTask(with: request) { data, response, error in \n' ;
376
377
codeSnippet += `${ indent } guard let data = data else {\n` ;
377
378
codeSnippet += `${ indent . repeat ( 2 ) } print(String(describing: error))\n` ;
378
- codeSnippet += `${ indent . repeat ( 2 ) } semaphore.signal()\n ` ;
379
- codeSnippet += ` ${ indent . repeat ( 2 ) } return\n` ;
379
+ codeSnippet += `${ indent . repeat ( 2 ) } ` ;
380
+ codeSnippet += options . includeBoilerplate ? 'exit(EXIT_SUCCESS)\n' : ' return\n' ;
380
381
codeSnippet += `${ indent } }\n` ;
381
382
codeSnippet += `${ indent } print(String(data: data, encoding: .utf8)!)\n` ;
382
- codeSnippet += `${ indent } semaphore.signal()\n}\n\n` ;
383
+ codeSnippet += options . includeBoilerplate ? `${ indent } exit(EXIT_SUCCESS)\n` : '' ;
384
+ codeSnippet += '}\n\n' ;
383
385
codeSnippet += 'task.resume()\n' ;
384
- codeSnippet += 'semaphore.wait ()\n';
386
+ codeSnippet += options . includeBoilerplate ? 'dispatchMain ()\n' : ' ';
385
387
386
388
return callback ( null , codeSnippet ) ;
387
389
}
0 commit comments