@@ -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 } ,
@@ -285,17 +285,16 @@ self = module.exports = {
285285 else if ( ! _ . isFunction ( callback ) ) {
286286 throw new Error ( 'Swift-Converter: callback is not valid function' ) ;
287287 }
288- var isTest = options . isTest ,
289- codeSnippet , indent , trim , timeout , finalUrl , // followRedirect,
288+ options = sanitizeOptions ( options , self . getOptions ( ) ) ;
289+ var indent , trim , timeout , finalUrl ,
290+ codeSnippet = '' ,
290291 bodySnippet = '' ,
291292 headerSnippet = '' ,
292293 requestBody ;
293- options = sanitizeOptions ( options , self . getOptions ( ) ) ;
294294
295295 indent = options . indentType === 'Tab' ? '\t' : ' ' ;
296296 indent = indent . repeat ( options . indentCount ) ;
297297 timeout = options . requestTimeout ;
298- // followRedirect = options.followRedirect;
299298 trim = options . trimRequestBody ;
300299 finalUrl = getUrlStringfromUrlObject ( request . url ) ;
301300
@@ -343,9 +342,10 @@ self = module.exports = {
343342 requestBody = ( request . body ? request . body . toJSON ( ) : { } ) ;
344343 bodySnippet = parseBody ( requestBody , trim , indent ) ;
345344
346- codeSnippet = 'import Foundation\n' ;
347- codeSnippet += '#if canImport(FoundationNetworking)\nimport FoundationNetworking\n#endif\n\n' ;
348- codeSnippet += isTest ? '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+ }
349349 if ( bodySnippet !== '' ) {
350350 codeSnippet += `${ bodySnippet } \n\n` ;
351351 }
@@ -376,18 +376,14 @@ self = module.exports = {
376376 codeSnippet += '\nlet task = URLSession.shared.dataTask(with: request) { data, response, error in \n' ;
377377 codeSnippet += `${ indent } guard let data = data else {\n` ;
378378 codeSnippet += `${ indent . repeat ( 2 ) } print(String(describing: error))\n` ;
379- codeSnippet += isTest ? `${ indent . repeat ( 2 ) } semaphore.signal()\n` : '' ;
380- codeSnippet += ` ${ indent . repeat ( 2 ) } return\n` ;
379+ codeSnippet += `${ indent . repeat ( 2 ) } ` ;
380+ codeSnippet += options . includeBoilerplate ? 'exit(EXIT_SUCCESS)\n' : ' return\n' ;
381381 codeSnippet += `${ indent } }\n` ;
382- if ( isTest ) {
383- codeSnippet += `${ indent } print(String(data: data, encoding: .utf8)!)\n` ;
384- codeSnippet += `${ indent } semaphore.signal()\n}\n\n` ;
385- }
386- else {
387- codeSnippet += `${ indent } print(String(data: data, encoding: .utf8)!)\n}\n\n` ;
388- }
382+ codeSnippet += `${ indent } print(String(data: data, encoding: .utf8)!)\n` ;
383+ codeSnippet += options . includeBoilerplate ? `${ indent } exit(EXIT_SUCCESS)\n` : '' ;
384+ codeSnippet += '}\n\n' ;
389385 codeSnippet += 'task.resume()\n' ;
390- codeSnippet += isTest ? 'semaphore.wait ()\n' : '' ;
386+ codeSnippet += options . includeBoilerplate ? 'dispatchMain ()\n' : '' ;
391387
392388 return callback ( null , codeSnippet ) ;
393389 }
0 commit comments