@@ -20,7 +20,9 @@ module.exports = function (source, options) {
2020
2121 var code = new CodeBuilder ( opts . indent )
2222
23- var methods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'HEAD' , 'OPTIONS' ]
23+ var methods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'HEAD' ]
24+
25+ var methodsWithBody = [ 'POST' , 'PUT' , 'DELETE' , 'PATCH' ]
2426
2527 code . push ( 'OkHttpClient client = new OkHttpClient();' )
2628 . blank ( )
@@ -34,6 +36,8 @@ module.exports = function (source, options) {
3436 code . push ( 'RequestBody body = RequestBody.create(mediaType, %s);' , JSON . stringify ( source . postData . text ) )
3537 }
3638
39+ console . log ( source )
40+
3741 code . push ( 'Request request = new Request.Builder()' )
3842 code . push ( 1 , '.url("%s")' , source . fullUrl )
3943 if ( methods . indexOf ( source . method . toUpperCase ( ) ) === - 1 ) {
@@ -46,7 +50,12 @@ module.exports = function (source, options) {
4650 if ( source . postData . text ) {
4751 code . push ( 1 , '.%s(body)' , source . method . toLowerCase ( ) )
4852 } else {
49- code . push ( 1 , '.%s()' , source . method . toLowerCase ( ) )
53+ console . log ( methodsWithBody . indexOf ( source . method . toUpperCase ( ) ) )
54+ if ( methodsWithBody . indexOf ( source . method . toUpperCase ( ) ) >= 0 ) {
55+ code . push ( 1 , '.%s(null)' , source . method . toLowerCase ( ) )
56+ } else {
57+ code . push ( 1 , '.%s()' , source . method . toLowerCase ( ) )
58+ }
5059 }
5160 }
5261
0 commit comments