@@ -250,11 +250,11 @@ self = module.exports = {
250250 description : 'Remove white space and additional lines that may affect the server\'s response'
251251 } ,
252252 {
253- name : 'Follow redirects ' ,
254- id : 'followRedirect ' ,
253+ name : 'Include boilerplate ' ,
254+ id : 'includeBoilerplate ' ,
255255 type : 'boolean' ,
256- default : true ,
257- description : 'Automatically follow HTTP redirects '
256+ default : false ,
257+ description : 'Include class definition and import statements in snippet '
258258 }
259259 ] ;
260260 } ,
@@ -286,15 +286,15 @@ self = module.exports = {
286286 throw new Error ( 'Swift-Converter: callback is not valid function' ) ;
287287 }
288288 options = sanitizeOptions ( options , self . getOptions ( ) ) ;
289- var codeSnippet , indent , trim , timeout , finalUrl , // followRedirect,
289+ var indent , trim , timeout , finalUrl ,
290+ codeSnippet = '' ,
290291 bodySnippet = '' ,
291292 headerSnippet = '' ,
292293 requestBody ;
293294
294295 indent = options . indentType === 'Tab' ? '\t' : ' ' ;
295296 indent = indent . repeat ( options . indentCount ) ;
296297 timeout = options . requestTimeout ;
297- // followRedirect = options.followRedirect;
298298 trim = options . trimRequestBody ;
299299 finalUrl = getUrlStringfromUrlObject ( request . url ) ;
300300
@@ -342,9 +342,10 @@ self = module.exports = {
342342 requestBody = ( request . body ? request . body . toJSON ( ) : { } ) ;
343343 bodySnippet = parseBody ( requestBody , trim , indent ) ;
344344
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+ }
348349 if ( bodySnippet !== '' ) {
349350 codeSnippet += `${ bodySnippet } \n\n` ;
350351 }
@@ -375,13 +376,14 @@ self = module.exports = {
375376 codeSnippet += '\nlet task = URLSession.shared.dataTask(with: request) { data, response, error in \n' ;
376377 codeSnippet += `${ indent } guard let data = data else {\n` ;
377378 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' ;
380381 codeSnippet += `${ indent } }\n` ;
381382 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' ;
383385 codeSnippet += 'task.resume()\n' ;
384- codeSnippet += 'semaphore.wait ()\n';
386+ codeSnippet += options . includeBoilerplate ? 'dispatchMain ()\n' : ' ';
385387
386388 return callback ( null , codeSnippet ) ;
387389 }
0 commit comments