diff --git a/lib/codegen/python/pkg_request.dart b/lib/codegen/python/pkg_request.dart index 7c2c8376..e25c9d76 100644 --- a/lib/codegen/python/pkg_request.dart +++ b/lib/codegen/python/pkg_request.dart @@ -7,7 +7,6 @@ class PythonRequestCodeGen { int kHeadersPadding = 16; String kPythonTemplate = ''' import requests -import json def main(): url = '{{url}}'{{params}}{{body}}{{headers}} @@ -56,9 +55,7 @@ main() if (requestBody != null && requestBody.isNotEmpty) { hasBody = true; var bodyType = requestModel.requestBodyContentType; - if (bodyType == ContentType.text) { - requestBodyString = "data = '''$requestBody'''\n"; - } else if (bodyType == ContentType.json) { + if (bodyType == ContentType.json) { int index = requestBody.lastIndexOf("}"); index--; while (requestBody[index] == " " || requestBody[index] == "\n") { @@ -68,9 +65,8 @@ main() requestBody = requestBody.substring(0, index) + requestBody.substring(index + 1); } - requestBodyString = - "data = '''$requestBody''' \n data = json.loads(data)\n"; } + requestBodyString = "data = '''$requestBody'''"; } var headersList = requestModel.requestHeaders; diff --git a/test/codegen/python_request_codegen_test.dart b/test/codegen/python_request_codegen_test.dart index a4c86096..a74f50ac 100644 --- a/test/codegen/python_request_codegen_test.dart +++ b/test/codegen/python_request_codegen_test.dart @@ -14,7 +14,6 @@ void main() { id: '', ); const expectedCode = """import requests -import json def main(): url = 'https://jsonplaceholder.typicode.com/todos/1' @@ -44,14 +43,11 @@ main()"""; id: '1', ); const expectedCode = """import requests -import json def main(): url = 'https://jsonplaceholder.typicode.com/posts' - data = '''{"title": "foo","body": "bar","userId": 1}''' - data = json.loads(data) - + data = '''{"title": "foo","body": "bar","userId": 1}''' headers = { "content-type": "application/json" @@ -82,14 +78,11 @@ main()"""; id: '1', ); const expectedCode = """import requests -import json def main(): url = 'https://jsonplaceholder.typicode.com/posts/1' - data = '''{"title": "foo","body": "bar","userId": 1}''' - data = json.loads(data) - + data = '''{"title": "foo","body": "bar","userId": 1}''' headers = { "content-type": "application/json" @@ -118,7 +111,6 @@ main()"""; id: '1', ); const expectedCode = """import requests -import json def main(): url = 'https://jsonplaceholder.typicode.com/posts/1' @@ -155,7 +147,6 @@ main()"""; id: '1', ); const expectedCode = """import requests -import json def main(): url = 'https://jsonplaceholder.typicode.com/posts'