mirror of
https://github.com/foss42/apidash.git
synced 2025-09-18 23:22:58 +08:00
Merge branch 'main' of https://github.com/foss42/apidash into add-go-http-codegen
This commit is contained in:
@ -53,7 +53,9 @@ class DartHttpCodeGen {
|
||||
declareVar('uri').assign(refer('Uri.parse').call([literalString(url)]));
|
||||
|
||||
Expression? dataExp;
|
||||
if (kMethodsWithBody.contains(method) && (body?.isNotEmpty ?? false)) {
|
||||
if (kMethodsWithBody.contains(method) &&
|
||||
(body?.isNotEmpty ?? false) &&
|
||||
contentType != ContentType.formdata) {
|
||||
final strContent = CodeExpression(Code('r\'\'\'$body\'\'\''));
|
||||
dataExp = declareVar('body', type: refer('String')).assign(strContent);
|
||||
if (!hasContentTypeHeader) {
|
||||
|
@ -7,7 +7,7 @@ import 'package:apidash/consts.dart';
|
||||
|
||||
class KotlinOkHttpCodeGen {
|
||||
final String kTemplateStart = """import okhttp3.OkHttpClient
|
||||
import okhttp3.Request{{importForQuery}}{{importForBody}}
|
||||
import okhttp3.Request{{importForQuery}}{{importForBody}}{{importForFormData}}
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
@ -23,6 +23,10 @@ import okhttp3.HttpUrl.Companion.toHttpUrl""";
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.MediaType.Companion.toMediaType""";
|
||||
|
||||
final String kStringImportForFormData = """
|
||||
|
||||
import okhttp3.MultipartBody""";
|
||||
|
||||
final String kTemplateUrl = '''
|
||||
|
||||
val url = "{{url}}"
|
||||
@ -77,6 +81,7 @@ import okhttp3.MediaType.Companion.toMediaType""";
|
||||
String result = "";
|
||||
bool hasQuery = false;
|
||||
bool hasBody = false;
|
||||
bool hasFormData = false;
|
||||
|
||||
String url = requestModel.url;
|
||||
if (!url.contains("://") && url.isNotEmpty) {
|
||||
@ -109,6 +114,7 @@ import okhttp3.MediaType.Companion.toMediaType""";
|
||||
var method = requestModel.method;
|
||||
var requestBody = requestModel.requestBody;
|
||||
if (requestModel.isFormDataRequest) {
|
||||
hasFormData = true;
|
||||
var formDataTemplate = jj.Template(kFormDataBody);
|
||||
|
||||
result += formDataTemplate.render({
|
||||
@ -128,7 +134,8 @@ import okhttp3.MediaType.Companion.toMediaType""";
|
||||
var templateStart = jj.Template(kTemplateStart);
|
||||
var stringStart = templateStart.render({
|
||||
"importForQuery": hasQuery ? kStringImportForQuery : "",
|
||||
"importForBody": hasBody ? kStringImportForBody : ""
|
||||
"importForBody": hasBody ? kStringImportForBody : "",
|
||||
"importForFormData": hasFormData ? kStringImportForFormData : ""
|
||||
});
|
||||
|
||||
result = stringStart + result;
|
||||
|
@ -130,7 +130,9 @@ body = b'\r\n'.join(dataList)
|
||||
|
||||
var method = requestModel.method;
|
||||
var requestBody = requestModel.requestBody;
|
||||
if (kMethodsWithBody.contains(method) && requestBody != null) {
|
||||
if (kMethodsWithBody.contains(method) &&
|
||||
requestBody != null &&
|
||||
!requestModel.isFormDataRequest) {
|
||||
var contentLength = utf8.encode(requestBody).length;
|
||||
if (contentLength > 0) {
|
||||
hasBody = true;
|
||||
|
@ -140,7 +140,7 @@ print('Response Body:', response.text)
|
||||
hasJsonBody = true;
|
||||
var templateBody = jj.Template(kTemplateJson);
|
||||
result += templateBody.render({"body": requestBody});
|
||||
} else {
|
||||
} else if (!requestModel.isFormDataRequest) {
|
||||
hasBody = true;
|
||||
var templateBody = jj.Template(kTemplateBody);
|
||||
result += templateBody.render({"body": requestBody});
|
||||
|
Reference in New Issue
Block a user