mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 12:59:58 +08:00
Merge branch 'main' into resolve-issue-missing-drag-scrolling
This commit is contained in:
@ -129,21 +129,28 @@ flutter test test/widgets/codegen_previewer_test.dart
|
||||
|
||||
Instead of copy pasting from pub.dev, it is recommended that you use `flutter pub add package_name` to add a new package to `pubspec.yaml`. You can read more [here](https://docs.flutter.dev/packages-and-plugins/using-packages#adding-a-package-dependency-to-an-app-using-flutter-pub-add).
|
||||
|
||||
## Troubleshooting Common Issues
|
||||
## Platform-specific Additional Instructions
|
||||
|
||||
### Network Connection Issues on macOS
|
||||
### macOS
|
||||
|
||||
If you encounter a network connection error similar to the following while running your Flutter app on macOS:
|
||||
Add below keys to `macos/Runner/DebugProfile.entitlements` and `macos/Runner/Release.entitlements`.
|
||||
|
||||
```
|
||||
<key>com.apple.security.network.server</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.downloads.read-write</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
<true/>
|
||||
```
|
||||
|
||||
If not added, you can encounter a network connection error similar to the following while running your Flutter app on macOS:
|
||||
|
||||
```
|
||||
ClientException with SocketException: Connection failed (OS Error: Operation not permitted, errno = 1)
|
||||
```
|
||||
Add below key to `macos/Runner/DebugProfile.entitlements` and `macos/Runner/Release.entitlements`.
|
||||
|
||||
```
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
```
|
||||
|
||||
You can read more [here](https://docs.flutter.dev/platform-integration/macos/building#setting-up-entitlements)
|
||||
|
||||
|
35
README.md
35
README.md
@ -123,19 +123,28 @@ API Dash can be downloaded from the links below:
|
||||
|
||||
API Dash currently supports API integration code generation for the following languages/libraries.
|
||||
|
||||
| Language | Library |
|
||||
| ---------------------- | ------------- |
|
||||
| cURL | |
|
||||
| HAR | |
|
||||
| Dart | `http` |
|
||||
| JavaScript | `axios` |
|
||||
| JavaScript | `fetch` |
|
||||
| JavaScript (`node.js`) | `axios` |
|
||||
| JavaScript (`node.js`) | `fetch` |
|
||||
| Python | `http.client` |
|
||||
| Python | `requests` |
|
||||
| Kotlin | `okhttp3` |
|
||||
| Java | `okhttp3` |
|
||||
| Language | Library | Comment/Issues |
|
||||
| ---------------------- | ------------- | ------- |
|
||||
| cURL | | |
|
||||
| HAR | | |
|
||||
| Dart | `http` | |
|
||||
| Dart | `dio` | |
|
||||
| Go | `net/http` | |
|
||||
| JavaScript | `axios` | |
|
||||
| JavaScript | `fetch` | |
|
||||
| JavaScript (`node.js`) | `axios` | |
|
||||
| JavaScript (`node.js`) | `fetch` | |
|
||||
| Python | `requests` | |
|
||||
| Python | `http.client` | |
|
||||
| Kotlin | `okhttp3` | |
|
||||
| Rust | `reqwest` | |
|
||||
| Rust | `ureq` | |
|
||||
| Rust | `Actix Client` | |
|
||||
| Java | `asynchttpclient` | https://github.com/foss42/apidash/issues/136 |
|
||||
| Java | `HttpClient` | https://github.com/foss42/apidash/issues/137 |
|
||||
| Java | `okhttp3` | |
|
||||
| Julia | `HTTP` | https://github.com/foss42/apidash/issues/154 |
|
||||
| PHP | `guzzle` | https://github.com/foss42/apidash/issues/143 |
|
||||
|
||||
We welcome contributions to support other programming languages/libraries/frameworks. Please check out more details [here](https://github.com/foss42/apidash/discussions/80).
|
||||
|
||||
|
@ -5,6 +5,7 @@ import 'dart/http.dart';
|
||||
import 'dart/dio.dart';
|
||||
import 'go/http.dart';
|
||||
import 'kotlin/okhttp.dart';
|
||||
import 'php/guzzle.dart';
|
||||
import 'python/http_client.dart';
|
||||
import 'python/requests.dart';
|
||||
import 'rust/actix.dart';
|
||||
@ -17,6 +18,7 @@ import 'others/curl.dart';
|
||||
import 'julia/http.dart';
|
||||
import 'java/okhttp.dart';
|
||||
import 'java/async_http_client.dart';
|
||||
import 'java/httpclient.dart';
|
||||
|
||||
class Codegen {
|
||||
String? getCode(
|
||||
@ -44,6 +46,8 @@ class Codegen {
|
||||
return DartHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.dartDio:
|
||||
return DartDioCodeGen().getCode(rM);
|
||||
case CodegenLanguage.goHttp:
|
||||
return GoHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.jsAxios:
|
||||
return AxiosCodeGen().getCode(rM);
|
||||
case CodegenLanguage.jsFetch:
|
||||
@ -52,10 +56,16 @@ class Codegen {
|
||||
return AxiosCodeGen(isNodeJs: true).getCode(rM);
|
||||
case CodegenLanguage.nodejsFetch:
|
||||
return FetchCodeGen(isNodeJs: true).getCode(rM);
|
||||
case CodegenLanguage.kotlinOkHttp:
|
||||
return KotlinOkHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.javaAsyncHttpClient:
|
||||
return JavaAsyncHttpClientGen().getCode(rM);
|
||||
case CodegenLanguage.javaHttpClient:
|
||||
return JavaHttpClientCodeGen().getCode(rM);
|
||||
case CodegenLanguage.javaOkHttp:
|
||||
return JavaOkHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.juliaHttp:
|
||||
return JuliaHttpClientCodeGen().getCode(rM);
|
||||
case CodegenLanguage.kotlinOkHttp:
|
||||
return KotlinOkHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.pythonHttpClient:
|
||||
return PythonHttpClientCodeGen()
|
||||
.getCode(rM, boundary: boundary ?? getNewUuid());
|
||||
@ -67,12 +77,8 @@ class Codegen {
|
||||
return RustReqwestCodeGen().getCode(rM);
|
||||
case CodegenLanguage.rustUreq:
|
||||
return RustUreqCodeGen().getCode(rM, boundary: boundary);
|
||||
case CodegenLanguage.goHttp:
|
||||
return GoHttpCodeGen().getCode(rM);
|
||||
case CodegenLanguage.juliaHttp:
|
||||
return JuliaHttpClientCodeGen().getCode(rM);
|
||||
case CodegenLanguage.javaAsyncHttpClient:
|
||||
return JavaAsyncHttpClientGen().getCode(rM);
|
||||
case CodegenLanguage.phpGuzzle:
|
||||
return PhpGuzzleCodeGen().getCode(rM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func main() {
|
||||
|
||||
var templateStart = jj.Template(kTemplateStart);
|
||||
result += templateStart.render({
|
||||
"hasBody": requestModel.hasData,
|
||||
"hasBody": requestModel.hasBody,
|
||||
"hasFormData": requestModel.hasFormData,
|
||||
"hasFileInFormData": requestModel.hasFileInFormData,
|
||||
});
|
||||
@ -144,7 +144,7 @@ func main() {
|
||||
});
|
||||
|
||||
var headersList = requestModel.enabledRequestHeaders;
|
||||
if (headersList != null || requestModel.hasData) {
|
||||
if (headersList != null || requestModel.hasBody) {
|
||||
var headers = requestModel.enabledHeadersMap;
|
||||
if (requestModel.hasJsonData || requestModel.hasTextData) {
|
||||
headers.putIfAbsent(kHeaderContentType,
|
||||
|
183
lib/codegen/java/httpclient.dart
Normal file
183
lib/codegen/java/httpclient.dart
Normal file
@ -0,0 +1,183 @@
|
||||
import 'dart:convert';
|
||||
import 'package:jinja/jinja.dart' as jj;
|
||||
import 'package:apidash/utils/utils.dart'
|
||||
show getValidRequestUri, requestModelToHARJsonRequest, stripUriParams;
|
||||
import '../../models/request_model.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
class JavaHttpClientCodeGen {
|
||||
final String kTemplateStart = """
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpHeaders;
|
||||
import java.net.http.HttpRequest.BodyPublishers;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
|
||||
public class JavaHttpClientExample {
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
""";
|
||||
final String kTemplateUrl = '''
|
||||
|
||||
String url = "{{url}}";
|
||||
|
||||
''';
|
||||
|
||||
final String kTemplateUrlQuery = '''
|
||||
|
||||
String url = "{{url}}";
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
url = uri.resolve("{{params}}").toString();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
''';
|
||||
|
||||
String kTemplateRequestBody = '''
|
||||
|
||||
String body = "{{body}}";
|
||||
|
||||
''';
|
||||
|
||||
final String kStringRequestStart = """
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
""";
|
||||
|
||||
final String kTemplateRequestEnd = """
|
||||
.{{method}}({{body}})
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
|
||||
System.out.println(response.statusCode());
|
||||
System.out.println(response.body());
|
||||
}
|
||||
}
|
||||
\n
|
||||
""";
|
||||
|
||||
String? getCode(
|
||||
RequestModel requestModel,
|
||||
) {
|
||||
try {
|
||||
String result = "";
|
||||
bool hasQuery = false;
|
||||
bool hasBody = false;
|
||||
bool hasJsonBody = false;
|
||||
|
||||
var rec = getValidRequestUri(
|
||||
requestModel.url,
|
||||
requestModel.enabledRequestParams,
|
||||
);
|
||||
Uri? uri = rec.$1;
|
||||
|
||||
if (uri != null) {
|
||||
String url = stripUriParams(uri);
|
||||
|
||||
if (uri.hasQuery) {
|
||||
var params = uri.queryParameters;
|
||||
if (params.isNotEmpty) {
|
||||
hasQuery = true;
|
||||
var templateParams = jj.Template(kTemplateUrlQuery);
|
||||
result += templateParams.render({"url": url, "params": uri.query});
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasQuery) {
|
||||
var templateUrl = jj.Template(kTemplateUrl);
|
||||
result += templateUrl.render({"url": url});
|
||||
}
|
||||
var rM = requestModel.copyWith(url: url);
|
||||
|
||||
var harJson = requestModelToHARJsonRequest(rM, useEnabled: true);
|
||||
|
||||
var method = requestModel.method;
|
||||
var requestBody = requestModel.requestBody;
|
||||
if (requestModel.hasFormData &&
|
||||
requestModel.formDataMapList.isNotEmpty &&
|
||||
kMethodsWithBody.contains(method)) {
|
||||
var formDataList = requestModel.formDataMapList;
|
||||
result += """
|
||||
StringBuilder formData = new StringBuilder();
|
||||
formData.append(""";
|
||||
|
||||
for (var formDataMap in formDataList) {
|
||||
result += '"""${formDataMap['name']}=${formDataMap['value']}&""",';
|
||||
}
|
||||
|
||||
result = result.substring(0, result.length - 1);
|
||||
result += ");\n";
|
||||
hasBody = true;
|
||||
} else if (kMethodsWithBody.contains(method) && requestBody != null) {
|
||||
var contentLength = utf8.encode(requestBody).length;
|
||||
if (contentLength > 0) {
|
||||
var templateBody = jj.Template(kTemplateRequestBody);
|
||||
hasBody = true;
|
||||
hasJsonBody =
|
||||
requestBody.startsWith("{") && requestBody.endsWith("}");
|
||||
if (harJson["postData"]?["text"] != null) {
|
||||
result += templateBody.render({
|
||||
"body": kEncoder.convert(harJson["postData"]["text"]).substring(
|
||||
1, kEncoder.convert(harJson["postData"]["text"]).length - 1)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = kTemplateStart + result;
|
||||
result += kStringRequestStart;
|
||||
|
||||
var headersList = requestModel.enabledRequestHeaders;
|
||||
var contentType = requestModel.requestBodyContentType.header;
|
||||
if (hasBody &&
|
||||
!requestModel.enabledHeadersMap.containsKey('Content-Type')) {
|
||||
result =
|
||||
"""$result .header("Content-Type", "$contentType")\n""";
|
||||
}
|
||||
if (headersList != null) {
|
||||
var headers = requestModel.enabledHeadersMap;
|
||||
if (headers.isNotEmpty) {
|
||||
result += getHeaders(headers, hasJsonBody);
|
||||
}
|
||||
}
|
||||
|
||||
var templateRequestEnd = jj.Template(kTemplateRequestEnd);
|
||||
|
||||
if (kMethodsWithBody.contains(method)) {
|
||||
result += templateRequestEnd.render({
|
||||
"method": method.name.toUpperCase(),
|
||||
"body": hasBody
|
||||
? "BodyPublishers.ofString(body)"
|
||||
: "BodyPublishers.noBody()"
|
||||
});
|
||||
} else {
|
||||
result += templateRequestEnd
|
||||
.render({"method": method.name.toUpperCase(), "body": ""});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String getHeaders(Map<String, String> headers, hasJsonBody) {
|
||||
String result = "";
|
||||
for (final k in headers.keys) {
|
||||
if (k.toLowerCase() == 'authorization') {
|
||||
result = """$result .header("$k", "${headers[k]}")\n""";
|
||||
} else {
|
||||
result = """$result .header("$k", "${headers[k]}")\n""";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import 'dart:convert';
|
||||
import 'package:jinja/jinja.dart' as jj;
|
||||
import 'package:apidash/utils/utils.dart'
|
||||
show padMultilineString, requestModelToHARJsonRequest, stripUrlParams;
|
||||
@ -10,12 +9,14 @@ class AxiosCodeGen {
|
||||
|
||||
final bool isNodeJs;
|
||||
|
||||
String kStringImportNode = """{% if isNodeJs %}import axios from 'axios';
|
||||
String kStringImportNode = """import axios from 'axios';
|
||||
{%if hasFileInFormData -%}
|
||||
import fs from 'fs'
|
||||
{% endif %}
|
||||
|
||||
{% endif %}{% if hasFormData and isNodeJs %}const fs = require('fs');{% endif %}
|
||||
""";
|
||||
|
||||
String kTemplateStart = """let config = {
|
||||
String kTemplateStart = """const config = {
|
||||
url: '{{url}}',
|
||||
method: '{{method}}'
|
||||
""";
|
||||
@ -37,59 +38,28 @@ class AxiosCodeGen {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
String kMultiPartBodyTemplate = r'''
|
||||
|
||||
|
||||
async function buildFormData(fields) {
|
||||
var formdata = new FormData();
|
||||
for (const field of fields) {
|
||||
const name = field.name || '';
|
||||
const value = field.value || '';
|
||||
const type = field.type || 'text';
|
||||
|
||||
if (type === 'text') {
|
||||
formdata.append(name, value);
|
||||
} else if (type === 'file') {
|
||||
formdata.append(name,{% if isNodeJs %} fs.createReadStream(value){% else %} fileInput.files[0],value{% endif %});
|
||||
}
|
||||
}
|
||||
return formdata;
|
||||
}
|
||||
|
||||
|
||||
''';
|
||||
var kGetFormDataTemplate = '''buildFormData({{fields_list}});
|
||||
''';
|
||||
String? getCode(
|
||||
RequestModel requestModel,
|
||||
) {
|
||||
try {
|
||||
jj.Template kNodejsImportTemplate = jj.Template(kStringImportNode);
|
||||
String importsData = kNodejsImportTemplate.render({
|
||||
"hasFormData": requestModel.hasFormData,
|
||||
"isNodeJs": isNodeJs,
|
||||
"hasFileInFormData": requestModel.hasFileInFormData,
|
||||
});
|
||||
|
||||
String result = importsData;
|
||||
if (requestModel.hasFormData && requestModel.formDataMapList.isNotEmpty) {
|
||||
var templateMultiPartBody = jj.Template(kMultiPartBodyTemplate);
|
||||
var renderedMultiPartBody = templateMultiPartBody.render({
|
||||
"isNodeJs": isNodeJs,
|
||||
});
|
||||
result += renderedMultiPartBody;
|
||||
}
|
||||
|
||||
String result = isNodeJs
|
||||
? importsData
|
||||
: requestModel.hasFileInFormData
|
||||
? "// refer https://github.com/foss42/apidash/issues/293#issuecomment-1997568083 for details regarding integration\n\n"
|
||||
: "";
|
||||
var harJson = requestModelToHARJsonRequest(
|
||||
requestModel,
|
||||
useEnabled: true,
|
||||
@ -126,17 +96,22 @@ async function buildFormData(fields) {
|
||||
.render({"headers": padMultilineString(kEncoder.convert(m), 2)});
|
||||
}
|
||||
var templateBody = jj.Template(kTemplateBody);
|
||||
|
||||
if (requestModel.hasFormData && requestModel.formDataMapList.isNotEmpty) {
|
||||
var getFieldDataTemplate = jj.Template(kGetFormDataTemplate);
|
||||
|
||||
result += templateBody.render({
|
||||
"body": getFieldDataTemplate.render({
|
||||
"fields_list": json.encode(requestModel.formDataMapList),
|
||||
})
|
||||
});
|
||||
// Manually Create a JS Object
|
||||
Map<String, String> formParams = {};
|
||||
int formFileCounter = 1;
|
||||
for (var element in requestModel.formDataMapList) {
|
||||
formParams["${element["name"]}"] = element["type"] == "text"
|
||||
? "${element["value"]}"
|
||||
: isNodeJs
|
||||
? "fs.createReadStream(${element["value"]})"
|
||||
: "fileInput$formFileCounter.files[0]";
|
||||
if (element["type"] == "file") formFileCounter++;
|
||||
}
|
||||
if (harJson["postData"]?["text"] != null) {
|
||||
var sanitizedJSObject = sanitzeJSObject(kEncoder.convert(formParams));
|
||||
result += templateBody
|
||||
.render({"body": padMultilineString(sanitizedJSObject, 2)});
|
||||
} else if (harJson["postData"]?["text"] != null) {
|
||||
result += templateBody
|
||||
.render({"body": kEncoder.convert(harJson["postData"]["text"])});
|
||||
}
|
||||
@ -146,4 +121,18 @@ async function buildFormData(fields) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// escape function and variables in JS Object
|
||||
String sanitzeJSObject(String jsObject) {
|
||||
RegExp pattern = isNodeJs
|
||||
? RegExp(r'"fs\.createReadStream\((.*?)\)"')
|
||||
: RegExp(r'"fileInput(\d+)\.files\[0\]"');
|
||||
|
||||
var sanitizedJSObject = jsObject.replaceAllMapped(pattern, (match) {
|
||||
return isNodeJs
|
||||
? 'fs.createReadStream("${match.group(1)}")'
|
||||
: 'fileInput${match.group(1)}.files[0]';
|
||||
});
|
||||
return sanitizedJSObject;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import 'package:apidash/consts.dart';
|
||||
|
||||
class KotlinOkHttpCodeGen {
|
||||
final String kTemplateStart = """import okhttp3.OkHttpClient
|
||||
import okhttp3.Request{{importForQuery}}{{importForBody}}{{importForFormData}}
|
||||
import okhttp3.Request{{importForQuery}}{{importForBody}}{{importForFormData}}{{importForFile}}
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
@ -27,6 +27,12 @@ import okhttp3.MediaType.Companion.toMediaType""";
|
||||
|
||||
import okhttp3.MultipartBody""";
|
||||
|
||||
final String kStringImportForFile = """
|
||||
|
||||
import java.io.File
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.MediaType.Companion.toMediaType""";
|
||||
|
||||
final String kTemplateUrl = '''
|
||||
|
||||
val url = "{{url}}"
|
||||
@ -68,7 +74,7 @@ import okhttp3.MultipartBody""";
|
||||
// Converting list of form data objects to kolin multi part data
|
||||
String kFormDataBody = '''
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM){% for item in formDataList %}{% if item.type == 'file' %}
|
||||
.addFormDataPart("{{item.name}}",null,File("{{item.value}}").asRequestBody("application/octet-stream".toMediaType()))
|
||||
.addFormDataPart("{{item.name}}",File("{{item.value}}").name,File("{{item.value}}").asRequestBody("application/octet-stream".toMediaType()))
|
||||
{% else %}.addFormDataPart("{{item.name}}","{{item.value}}")
|
||||
{% endif %}{% endfor %}.build()
|
||||
''';
|
||||
@ -81,6 +87,7 @@ import okhttp3.MultipartBody""";
|
||||
bool hasQuery = false;
|
||||
bool hasBody = false;
|
||||
bool hasFormData = false;
|
||||
bool hasFile = false;
|
||||
|
||||
var rec = getValidRequestUri(
|
||||
requestModel.url,
|
||||
@ -111,8 +118,34 @@ import okhttp3.MultipartBody""";
|
||||
hasFormData = true;
|
||||
var formDataTemplate = jj.Template(kFormDataBody);
|
||||
|
||||
List<Map<String,String>> modifiedFormDataList = [];
|
||||
for (var item in requestModel.formDataList) {
|
||||
if (item.type == FormDataType.file ) {
|
||||
if (item.value[0] == "/") {
|
||||
modifiedFormDataList.add({
|
||||
"name": item.name,
|
||||
"value": item.value.substring(1),
|
||||
"type": "file"
|
||||
});
|
||||
}else{
|
||||
modifiedFormDataList.add({
|
||||
"name": item.name,
|
||||
"value": item.value,
|
||||
"type": "file"
|
||||
});
|
||||
}
|
||||
hasFile = true;
|
||||
}else{
|
||||
modifiedFormDataList.add({
|
||||
"name": item.name,
|
||||
"value": item.value,
|
||||
"type": "text"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
result += formDataTemplate.render({
|
||||
"formDataList": requestModel.formDataMapList,
|
||||
"formDataList": modifiedFormDataList,
|
||||
});
|
||||
} else if (kMethodsWithBody.contains(method) && requestBody != null) {
|
||||
var contentLength = utf8.encode(requestBody).length;
|
||||
@ -129,7 +162,8 @@ import okhttp3.MultipartBody""";
|
||||
var stringStart = templateStart.render({
|
||||
"importForQuery": hasQuery ? kStringImportForQuery : "",
|
||||
"importForBody": hasBody ? kStringImportForBody : "",
|
||||
"importForFormData": hasFormData ? kStringImportForFormData : ""
|
||||
"importForFormData": hasFormData ? kStringImportForFormData : "",
|
||||
"importForFile": hasFile ? kStringImportForFile : "",
|
||||
});
|
||||
|
||||
result = stringStart + result;
|
||||
|
161
lib/codegen/php/guzzle.dart
Normal file
161
lib/codegen/php/guzzle.dart
Normal file
@ -0,0 +1,161 @@
|
||||
import 'package:jinja/jinja.dart' as jj;
|
||||
import 'package:apidash/utils/utils.dart'
|
||||
show requestModelToHARJsonRequest, stripUrlParams;
|
||||
import 'package:apidash/models/models.dart' show RequestModel;
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
class PhpGuzzleCodeGen {
|
||||
String kStringImportNode = """use GuzzleHttp\\Client;
|
||||
use GuzzleHttp\\Psr7\\Request;
|
||||
{% if hasFormData %}use GuzzleHttp\\Psr7\\MultipartStream;{% endif %}
|
||||
|
||||
|
||||
""";
|
||||
|
||||
String kMultiPartBodyTemplate = """
|
||||
\$multipart = [
|
||||
{{fields_list}}
|
||||
];
|
||||
|
||||
|
||||
""";
|
||||
|
||||
String kTemplateParams = """
|
||||
\$queryParams = [
|
||||
{{params}}
|
||||
];
|
||||
\$queryParamsStr = '?' . http_build_query(\$queryParams);
|
||||
|
||||
|
||||
""";
|
||||
|
||||
String kTemplateHeader = """
|
||||
\$headers = [
|
||||
{{headers}}
|
||||
];
|
||||
|
||||
|
||||
""";
|
||||
|
||||
String kTemplateBody = """
|
||||
\$body = {{body}};
|
||||
|
||||
|
||||
""";
|
||||
|
||||
String kStringRequest = """
|
||||
\$client = new Client();
|
||||
|
||||
\$request = new Request('{{method}}', '{{url}}'{{queryParams}} {{headers}} {{body}});
|
||||
\$res = \$client->sendAsync(\$request)->wait();
|
||||
echo \$res->getBody();
|
||||
""";
|
||||
|
||||
String? getCode(RequestModel requestModel) {
|
||||
try {
|
||||
jj.Template kNodejsImportTemplate = jj.Template(kStringImportNode);
|
||||
String importsData = kNodejsImportTemplate.render({
|
||||
"hasFormData": requestModel.hasFormData,
|
||||
});
|
||||
|
||||
String result = importsData;
|
||||
|
||||
if (requestModel.hasFormData && requestModel.formDataMapList.isNotEmpty) {
|
||||
var templateMultiPartBody = jj.Template(kMultiPartBodyTemplate);
|
||||
var renderedMultiPartBody = templateMultiPartBody.render({
|
||||
"fields_list": requestModel.formDataMapList.map((field) {
|
||||
return '''
|
||||
[
|
||||
'name' => '${field['name']}',
|
||||
'contents' => '${field['value']}'
|
||||
],''';
|
||||
}).join(),
|
||||
});
|
||||
result += renderedMultiPartBody;
|
||||
}
|
||||
|
||||
var harJson =
|
||||
requestModelToHARJsonRequest(requestModel, useEnabled: true);
|
||||
|
||||
var params = harJson["queryString"];
|
||||
if (params.isNotEmpty) {
|
||||
var templateParams = jj.Template(kTemplateParams);
|
||||
var m = {};
|
||||
for (var i in params) {
|
||||
m[i["name"]] = i["value"];
|
||||
}
|
||||
var jsonString = '';
|
||||
m.forEach((key, value) {
|
||||
jsonString += "\t\t\t\t'$key' => '$value', \n";
|
||||
});
|
||||
jsonString = jsonString.substring(
|
||||
0, jsonString.length - 2); // Removing trailing comma and space
|
||||
result += templateParams.render({
|
||||
"params": jsonString,
|
||||
});
|
||||
}
|
||||
|
||||
var headers = harJson["headers"];
|
||||
if (headers.isNotEmpty || requestModel.hasFormData) {
|
||||
var templateHeader = jj.Template(kTemplateHeader);
|
||||
var m = {};
|
||||
for (var i in headers) {
|
||||
m[i["name"]] = i["value"];
|
||||
}
|
||||
var headersString = '';
|
||||
m.forEach((key, value) {
|
||||
headersString += "\t\t\t\t'$key' => '$value', \n";
|
||||
});
|
||||
if (requestModel.hasFormData) {
|
||||
m['Content-Type'] = 'multipart/form-data';
|
||||
}
|
||||
headersString = headersString.substring(
|
||||
0, headersString.length - 2); // Removing trailing comma and space
|
||||
result += templateHeader.render({
|
||||
"headers": headersString,
|
||||
});
|
||||
}
|
||||
|
||||
var templateBody = jj.Template(kTemplateBody);
|
||||
if (requestModel.hasFormData && requestModel.formDataMapList.isNotEmpty) {
|
||||
result += templateBody.render({
|
||||
"body": "new MultipartStream(\$multipart)",
|
||||
});
|
||||
}
|
||||
|
||||
if (harJson["postData"]?["text"] != null) {
|
||||
result += templateBody
|
||||
.render({"body": kEncoder.convert(harJson["postData"]["text"])});
|
||||
}
|
||||
|
||||
String getRequestBody(Map harJson) {
|
||||
if (harJson.containsKey("postData")) {
|
||||
var postData = harJson["postData"];
|
||||
if (postData.containsKey("mimeType")) {
|
||||
var mimeType = postData["mimeType"];
|
||||
if (mimeType == "text/plain" || mimeType == "application/json") {
|
||||
return " \$body";
|
||||
} else if (mimeType == "multipart/form-data") {
|
||||
return " new MultipartStream(\$multipart)";
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""; // Return empty string if postData or formdata is not present
|
||||
}
|
||||
|
||||
var templateRequest = jj.Template(kStringRequest);
|
||||
result += templateRequest.render({
|
||||
"url": stripUrlParams(requestModel.url),
|
||||
"method": harJson["method"].toLowerCase(),
|
||||
"queryParams":
|
||||
harJson["queryString"].isNotEmpty ? ". \$queryParamsStr," : "",
|
||||
"headers": harJson["headers"].isNotEmpty ? " \$headers," : "",
|
||||
"body": getRequestBody(harJson),
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -116,7 +116,7 @@ body = b'\r\n'.join(dataList)
|
||||
}
|
||||
}
|
||||
|
||||
if (requestModel.hasData) {
|
||||
if (requestModel.hasBody) {
|
||||
hasBody = true;
|
||||
if (requestModel.hasJsonData || requestModel.hasTextData) {
|
||||
var templateBody = jj.Template(kTemplateBody);
|
||||
|
@ -265,14 +265,16 @@ enum CodegenLanguage {
|
||||
nodejsAxios("node.js (axios)", "javascript", "js"),
|
||||
nodejsFetch("node.js (fetch)", "javascript", "js"),
|
||||
kotlinOkHttp("Kotlin (okhttp3)", "java", "kt"),
|
||||
pythonHttpClient("Python (http.client)", "python", "py"),
|
||||
pythonRequests("Python (requests)", "python", "py"),
|
||||
pythonHttpClient("Python (http.client)", "python", "py"),
|
||||
rustActix("Rust (Actix Client)", "rust", "rs"),
|
||||
rustReqwest("Rust (reqwest)", "rust", "rs"),
|
||||
rustUreq("Rust (ureq)", "rust", "rs"),
|
||||
javaOkHttp("Java (okhttp3)", "java", 'java'),
|
||||
javaAsyncHttpClient("Java (async-http-client)", "java", "java"),
|
||||
juliaHttp("Julia (HTTP)", "julia", "jl");
|
||||
javaAsyncHttpClient("Java (asynchttpclient)", "java", "java"),
|
||||
javaHttpClient("Java (HttpClient)", "java", "java"),
|
||||
juliaHttp("Julia (HTTP)", "julia", "jl"),
|
||||
phpGuzzle("PHP (guzzle)", "php", "php");
|
||||
|
||||
const CodegenLanguage(this.label, this.codeHighlightLang, this.ext);
|
||||
final String label;
|
||||
|
@ -68,7 +68,7 @@ class RequestModel {
|
||||
bool get hasJsonContentType => requestBodyContentType == ContentType.json;
|
||||
bool get hasTextContentType => requestBodyContentType == ContentType.text;
|
||||
int get contentLength => utf8.encode(requestBody ?? "").length;
|
||||
bool get hasData => hasJsonData || hasTextData || hasFormData;
|
||||
bool get hasBody => hasJsonData || hasTextData || hasFormData;
|
||||
bool get hasJsonData =>
|
||||
kMethodsWithBody.contains(method) &&
|
||||
hasJsonContentType &&
|
||||
|
@ -17,11 +17,14 @@ class EditRequestPane extends ConsumerWidget {
|
||||
selectedRequestModelProvider.select((value) => value?.requestTabIndex));
|
||||
|
||||
final headerLength = ref.watch(selectedRequestModelProvider
|
||||
.select((value) => value?.headersMap.length));
|
||||
.select((value) => value?.headersMap.length)) ??
|
||||
0;
|
||||
final paramLength = ref.watch(selectedRequestModelProvider
|
||||
.select((value) => value?.paramsMap.length));
|
||||
final bodyLength = ref.watch(selectedRequestModelProvider
|
||||
.select((value) => value?.requestBody?.length));
|
||||
.select((value) => value?.paramsMap.length)) ??
|
||||
0;
|
||||
final hasBody = ref.watch(
|
||||
selectedRequestModelProvider.select((value) => value?.hasBody)) ??
|
||||
false;
|
||||
|
||||
return RequestPane(
|
||||
selectedId: selectedId,
|
||||
@ -37,9 +40,9 @@ class EditRequestPane extends ConsumerWidget {
|
||||
.update(selectedId!, requestTabIndex: index);
|
||||
},
|
||||
showIndicators: [
|
||||
paramLength != null && paramLength > 0,
|
||||
headerLength != null && headerLength > 0,
|
||||
bodyLength != null && bodyLength > 0,
|
||||
paramLength > 0,
|
||||
headerLength > 0,
|
||||
hasBody,
|
||||
],
|
||||
children: const [
|
||||
EditRequestURLParams(),
|
||||
|
122
pubspec.lock
122
pubspec.lock
@ -109,10 +109,10 @@ packages:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: build_runner
|
||||
sha256: "67d591d602906ef9201caf93452495ad1812bea2074f04e25dbd7c133785821b"
|
||||
sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.7"
|
||||
version: "2.4.8"
|
||||
build_runner_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -173,10 +173,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: code_builder
|
||||
sha256: feee43a5c05e7b3199bb375a86430b8ada1b04104f2923d0e03cc01ca87b6d84
|
||||
sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.9.0"
|
||||
version: "4.10.0"
|
||||
collection:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -213,18 +213,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: csv
|
||||
sha256: "63ed2871dd6471193dffc52c0e6c76fb86269c00244d244297abbb355c84a86e"
|
||||
sha256: c6aa2679b2a18cb57652920f674488d89712efaf4d3fdf2e537215b35fc19d6c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.1.1"
|
||||
version: "6.0.0"
|
||||
dart_style:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dart_style
|
||||
sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368"
|
||||
sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.4"
|
||||
version: "2.3.6"
|
||||
data_table_2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -285,10 +285,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6"
|
||||
sha256: caa6bc229eab3e32eb2f37b53a5f9d22a6981474afd210c512a7546c1e1a04f6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
version: "6.2.0"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -370,10 +370,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_markdown
|
||||
sha256: "35108526a233cc0755664d445f8a6b4b61e6f8fe993b3658b80b4a26827fc196"
|
||||
sha256: cb44f7831b23a6bdd0f501718b0d2e8045cbc625a15f668af37ddb80314821db
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.18+2"
|
||||
version: "0.6.21"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -386,18 +386,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_riverpod
|
||||
sha256: da9591d1f8d5881628ccd5c25c40e74fc3eef50ba45e40c3905a06e1712412d5
|
||||
sha256: "0f1974eff5bbe774bf1d870e406fc6f29e3d6f1c46bd9c58e7172ff68a785d7d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.9"
|
||||
version: "2.5.1"
|
||||
flutter_svg:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_svg
|
||||
sha256: d39e7f95621fc84376bc0f7d504f05c3a41488c562f4a8ad410569127507402c
|
||||
sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.9"
|
||||
version: "2.0.10+1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -420,10 +420,10 @@ packages:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: freezed
|
||||
sha256: "6c5031daae12c7072b3a87eff98983076434b4889ef2a44384d0cae3f82372ba"
|
||||
sha256: "57247f692f35f068cae297549a46a9a097100685c6780fe67177503eea5ed4e5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.6"
|
||||
version: "2.4.7"
|
||||
freezed_annotation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -452,10 +452,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: google_fonts
|
||||
sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8
|
||||
sha256: b1ac0fe2832c9cc95e5e88b57d627c5e68c223b9657f4b96e1487aa9098c7b82
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
version: "6.2.1"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -564,8 +564,8 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "9fa58d7b51e65174ab11cbcae17bba88a4194dde"
|
||||
resolved-ref: "9fa58d7b51e65174ab11cbcae17bba88a4194dde"
|
||||
ref: b7dde2f85dff4f482eed7eda4ef2a71344ef8b3a
|
||||
resolved-ref: b7dde2f85dff4f482eed7eda4ef2a71344ef8b3a
|
||||
url: "https://github.com/foss42/json_data_explorer.git"
|
||||
source: git
|
||||
version: "0.1.2"
|
||||
@ -669,18 +669,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: lottie
|
||||
sha256: a93542cc2d60a7057255405f62252533f8e8956e7e06754955669fd32fb4b216
|
||||
sha256: ce2bb2605753915080e4ee47f036a64228c88dc7f56f7bc1dbe912d75b55b1e2
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.7.0"
|
||||
version: "3.1.0"
|
||||
markdown:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: markdown
|
||||
sha256: acf35edccc0463a9d7384e437c015a3535772e09714cf60e07eeef3a15870dcd
|
||||
sha256: ef2a1298144e3f985cc736b22e0ccdaf188b5b3970648f2d9dc13efd1d9df051
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.1.1"
|
||||
version: "7.2.2"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -765,10 +765,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: package_info_plus
|
||||
sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017"
|
||||
sha256: "88bc797f44a94814f2213db1c9bd5badebafdfb8290ca9f78d4b9ee2a3db4d79"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.0"
|
||||
version: "5.0.1"
|
||||
package_info_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -797,10 +797,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path_provider
|
||||
sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa
|
||||
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
path_provider_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -849,6 +849,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.10.7"
|
||||
pdf_widget_wrapper:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pdf_widget_wrapper
|
||||
sha256: "9c3ca36e5000c9682d52bbdc486867ba7c5ee4403d1a5d6d03ed72157753377b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -901,10 +909,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pointer_interceptor_web
|
||||
sha256: a6237528b46c411d8d55cdfad8fcb3269fc4cbb26060b14bff94879165887d1e
|
||||
sha256: "9386e064097fd16419e935c23f08f35b58e6aaec155dd39bd6a003b88f9c14b4"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.10.2"
|
||||
version: "0.10.1+2"
|
||||
pointycastle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -925,18 +933,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: printing
|
||||
sha256: ad39a42a5f83125952457dfd94f395c8cf0eb1f7759583dadb769be5c7f99d24
|
||||
sha256: "1c99cab90ebcc1fff65831d264627d5b529359d563e53f33ab9b8117f2d280bc"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.11.1"
|
||||
version: "5.12.0"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
|
||||
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
version: "6.1.2"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -962,13 +970,13 @@ packages:
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
riverpod:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: riverpod
|
||||
sha256: "942999ee48b899f8a46a860f1e13cee36f2f77609eb54c5b7a669bb20d550b11"
|
||||
sha256: f21b32ffd26a36555e501b04f4a5dca43ed59e16343f1a30c13632b2351dfa4d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.9"
|
||||
version: "2.5.1"
|
||||
rxdart:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -989,10 +997,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: scrollable_positioned_list
|
||||
sha256: "9566352ab9ba05794ee6c8864f154afba5d36c5637d0e3e32c615ba4ceb92772"
|
||||
sha256: "1b54d5f1329a1e263269abc9e2543d90806131aa14fe7c6062a8054d57249287"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.3"
|
||||
version: "0.3.8"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1178,10 +1186,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: e9aa5ea75c84cf46b3db4eea212523591211c3cf2e13099ee4ec147f54201c86
|
||||
sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.2"
|
||||
version: "6.2.5"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1226,10 +1234,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d"
|
||||
sha256: fff0932192afeedf63cdd50ecbb1bc825d31aed259f02bb8dba0f3b729a5e88b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
version: "2.2.3"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1242,34 +1250,34 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: uuid
|
||||
sha256: "22c94e5ad1e75f9934b766b53c742572ee2677c56bc871d850a57dad0f82127f"
|
||||
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.2"
|
||||
version: "4.3.3"
|
||||
vector_graphics:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics
|
||||
sha256: "0f0c746dd2d6254a0057218ff980fc7f5670fd0fcf5e4db38a490d31eed4ad43"
|
||||
sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+1"
|
||||
version: "1.1.11+1"
|
||||
vector_graphics_codec:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_codec
|
||||
sha256: "0edf6d630d1bfd5589114138ed8fada3234deacc37966bec033d3047c29248b7"
|
||||
sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+1"
|
||||
version: "1.1.11+1"
|
||||
vector_graphics_compiler:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: vector_graphics_compiler
|
||||
sha256: d24333727332d9bd20990f1483af4e09abdb9b1fc7c3db940b56ab5c42790c26
|
||||
sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+1"
|
||||
version: "1.1.11+1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1295,7 +1303,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
web:
|
||||
dependency: "direct main"
|
||||
dependency: "direct overridden"
|
||||
description:
|
||||
name: web
|
||||
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||
@ -1330,10 +1338,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: window_manager
|
||||
sha256: dcc865277f26a7dad263a47d0e405d77e21f12cb71f30333a52710a408690bd7
|
||||
sha256: b3c895bdf936c77b83c5254bec2e6b3f066710c1f89c38b20b8acc382b525494
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.7"
|
||||
version: "0.3.8"
|
||||
window_size:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -1369,4 +1377,4 @@ packages:
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.3.0 <4.0.0"
|
||||
flutter: ">=3.19.0"
|
||||
flutter: ">=3.19.2"
|
||||
|
57
pubspec.yaml
57
pubspec.yaml
@ -1,24 +1,24 @@
|
||||
name: apidash
|
||||
description: API Dash is a beautiful open-source cross-platform API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate Dart code on the go.
|
||||
publish_to: "none"
|
||||
version: 0.3.0+3
|
||||
version: 0.4.0+4
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
flutter: ">=3.16.0"
|
||||
flutter: ">=3.19.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
web: ^0.5.0
|
||||
multi_split_view: ^2.4.0
|
||||
url_launcher: ^6.1.12
|
||||
flutter_riverpod: ^2.3.7
|
||||
uuid: ^4.1.0
|
||||
http: ^1.1.0
|
||||
url_launcher: ^6.2.5
|
||||
flutter_riverpod: ^2.5.1
|
||||
riverpod: ^2.5.1
|
||||
uuid: ^4.3.3
|
||||
http: ^1.2.1
|
||||
http_parser: ^4.0.2
|
||||
collection: ^1.17.2
|
||||
google_fonts: ^6.1.0
|
||||
google_fonts: ^6.2.1
|
||||
highlighter: ^0.1.1
|
||||
xml: ^6.3.0
|
||||
jinja: ^0.5.0
|
||||
@ -27,44 +27,47 @@ dependencies:
|
||||
url: https://github.com/google/flutter-desktop-embedding.git
|
||||
path: plugins/window_size
|
||||
hive_flutter: ^1.1.0
|
||||
lottie: ^2.6.0
|
||||
lottie: ^3.1.0
|
||||
mime_dart: ^3.0.0
|
||||
path_provider: ^2.1.0
|
||||
window_manager: ^0.3.5
|
||||
path_provider: ^2.1.2
|
||||
window_manager: ^0.3.8
|
||||
path: ^1.8.3
|
||||
flutter_markdown: ^0.6.17+1
|
||||
markdown: ^7.1.1
|
||||
flutter_markdown: ^0.6.21
|
||||
markdown: ^7.2.2
|
||||
just_audio: ^0.9.34
|
||||
just_audio_mpv: ^0.1.7
|
||||
just_audio_windows: ^0.2.0
|
||||
freezed_annotation: ^2.4.1
|
||||
json_annotation: ^4.8.1
|
||||
printing: ^5.11.1
|
||||
package_info_plus: ^4.1.0
|
||||
printing: ^5.12.0
|
||||
package_info_plus: ^5.0.1
|
||||
flutter_typeahead: ^5.2.0
|
||||
provider: ^6.0.5
|
||||
provider: ^6.1.2
|
||||
json_data_explorer:
|
||||
git:
|
||||
url: https://github.com/foss42/json_data_explorer.git
|
||||
ref: 9fa58d7b51e65174ab11cbcae17bba88a4194dde
|
||||
scrollable_positioned_list: ^0.2.3
|
||||
file_picker: ^6.1.1
|
||||
flutter_svg: ^2.0.9
|
||||
ref: b7dde2f85dff4f482eed7eda4ef2a71344ef8b3a
|
||||
scrollable_positioned_list: ^0.3.8
|
||||
file_picker: ^6.2.0
|
||||
flutter_svg: ^2.0.10+1
|
||||
vector_graphics_compiler: ^1.1.9+1
|
||||
code_builder: ^4.9.0
|
||||
dart_style: ^2.3.4
|
||||
code_builder: ^4.10.0
|
||||
dart_style: ^2.3.6
|
||||
json_text_field: ^1.1.0
|
||||
csv: ^5.1.1
|
||||
csv: ^6.0.0
|
||||
data_table_2: ^2.5.11
|
||||
|
||||
dependency_overrides:
|
||||
web: ^0.5.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^3.0.0
|
||||
flutter_lints: ^3.0.1
|
||||
flutter_launcher_icons: ^0.13.1
|
||||
test: ^1.24.3
|
||||
build_runner: ^2.4.6
|
||||
freezed: ^2.4.1
|
||||
test: ^1.24.9
|
||||
build_runner: ^2.4.8
|
||||
freezed: ^2.4.7
|
||||
json_serializable: ^6.7.1
|
||||
|
||||
flutter:
|
||||
|
@ -8,21 +8,18 @@ void main() {
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -31,7 +28,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -40,15 +37,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -57,7 +51,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -66,15 +60,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -83,7 +74,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -96,15 +87,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -113,7 +101,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
headers: {
|
||||
@ -122,15 +110,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -139,7 +124,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -151,15 +136,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -168,21 +150,18 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -191,7 +170,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -203,15 +182,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -220,7 +196,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -230,15 +206,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -247,7 +220,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
headers: {
|
||||
@ -256,15 +229,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -277,7 +247,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -290,15 +260,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -307,21 +274,18 @@ axios(config)
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -332,21 +296,18 @@ axios(config)
|
||||
|
||||
group('HEAD Request', () {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -355,21 +316,18 @@ axios(config)
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'http://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -380,7 +338,7 @@ axios(config)
|
||||
|
||||
group('POST Request', () {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -390,15 +348,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -407,7 +362,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -417,15 +372,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -434,7 +386,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -445,26 +397,227 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost4,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
"User-Agent": "Test Agent"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost5,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 6', () {
|
||||
const expectedCode =
|
||||
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1997568083 for details regarding integration
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fileInput1.files[0]
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost6,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 7', () {
|
||||
const expectedCode =
|
||||
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1997568083 for details regarding integration
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fileInput1.files[0]
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost7,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
params: {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost8,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 9', () {
|
||||
const expectedCode =
|
||||
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1997568083 for details regarding integration
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
params: {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
"User-Agent": "Test Agent",
|
||||
"Keep-Alive": "true"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fileInput1.files[0]
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelPost9,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PUT Request', () {
|
||||
test('PUT 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'put',
|
||||
headers: {
|
||||
@ -474,15 +627,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -493,7 +643,7 @@ axios(config)
|
||||
|
||||
group('PATCH Request', () {
|
||||
test('PATCH 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'patch',
|
||||
headers: {
|
||||
@ -503,15 +653,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -522,21 +669,18 @@ axios(config)
|
||||
|
||||
group('DELETE Request', () {
|
||||
test('DELETE 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'delete'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -546,7 +690,7 @@ axios(config)
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
const expectedCode = r"""const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'delete',
|
||||
headers: {
|
||||
@ -556,15 +700,12 @@ axios(config)
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
|
@ -517,6 +517,35 @@ fun main() {
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 4', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.MultipartBody
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/form"
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("text","API")
|
||||
.addFormDataPart("sep","|")
|
||||
.addFormDataPart("times","3")
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
@ -548,6 +577,141 @@ fun main() {
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 6', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/img"
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("token","xyz")
|
||||
|
||||
.addFormDataPart("imfile",File("Documents/up/1.png").name,File("Documents/up/1.png").asRequestBody("application/octet-stream".toMediaType()))
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 7', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/img"
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("token","xyz")
|
||||
|
||||
.addFormDataPart("imfile",File("Documents/up/1.png").name,File("Documents/up/1.png").asRequestBody("application/octet-stream".toMediaType()))
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 8', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.MultipartBody
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/form".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("size", "2")
|
||||
.addQueryParameter("len", "3")
|
||||
.build()
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("text","API")
|
||||
.addFormDataPart("sep","|")
|
||||
.addFormDataPart("times","3")
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 9', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/img".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("size", "2")
|
||||
.addQueryParameter("len", "3")
|
||||
.build()
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("token","xyz")
|
||||
|
||||
.addFormDataPart("imfile",File("Documents/up/1.png").name,File("Documents/up/1.png").asRequestBody("application/octet-stream".toMediaType()))
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("User-Agent", "Test Agent")
|
||||
.addHeader("Keep-Alive", "true")
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PUT Request', () {
|
||||
|
@ -10,21 +10,18 @@ void main() {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -36,7 +33,7 @@ axios(config)
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -45,15 +42,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -65,7 +59,7 @@ axios(config)
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -74,15 +68,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -94,7 +85,7 @@ axios(config)
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -107,15 +98,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -127,7 +115,7 @@ axios(config)
|
||||
test('GET 5', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
headers: {
|
||||
@ -136,15 +124,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -156,7 +141,7 @@ axios(config)
|
||||
test('GET 6', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -168,15 +153,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -188,21 +170,18 @@ axios(config)
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -214,7 +193,7 @@ axios(config)
|
||||
test('GET 8', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -226,15 +205,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -246,7 +222,7 @@ axios(config)
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -256,15 +232,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -276,7 +249,7 @@ axios(config)
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
headers: {
|
||||
@ -285,15 +258,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -308,7 +278,7 @@ axios(config)
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
@ -321,15 +291,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -341,21 +308,18 @@ axios(config)
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -369,21 +333,18 @@ axios(config)
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -395,21 +356,18 @@ axios(config)
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'http://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -423,7 +381,7 @@ axios(config)
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -433,15 +391,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -453,7 +408,7 @@ axios(config)
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -463,15 +418,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -483,7 +435,7 @@ axios(config)
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
@ -494,15 +446,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -510,13 +459,223 @@ axios(config)
|
||||
CodegenLanguage.nodejsAxios, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost4,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
"User-Agent": "Test Agent"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost5,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 6', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
import fs from 'fs'
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fs.createReadStream("/Documents/up/1.png")
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost6,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 7', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
import fs from 'fs'
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fs.createReadStream("/Documents/up/1.png")
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost7,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/form',
|
||||
method: 'post',
|
||||
params: {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data"
|
||||
},
|
||||
data: {
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3"
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost8,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
test('POST 9', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
import fs from 'fs'
|
||||
|
||||
const config = {
|
||||
url: 'https://api.apidash.dev/io/img',
|
||||
method: 'post',
|
||||
params: {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
"User-Agent": "Test Agent",
|
||||
"Keep-Alive": "true"
|
||||
},
|
||||
data: {
|
||||
"token": "xyz",
|
||||
"imfile": fs.createReadStream("/Documents/up/1.png")
|
||||
}
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelPost9,
|
||||
"https",
|
||||
),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PUT Request', () {
|
||||
test('PUT 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'put',
|
||||
headers: {
|
||||
@ -526,15 +685,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -548,7 +704,7 @@ axios(config)
|
||||
test('PATCH 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'patch',
|
||||
headers: {
|
||||
@ -558,15 +714,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -580,21 +733,18 @@ axios(config)
|
||||
test('DELETE 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'delete'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
@ -606,7 +756,7 @@ axios(config)
|
||||
test('DELETE 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
const config = {
|
||||
url: 'https://reqres.in/api/users/2',
|
||||
method: 'delete',
|
||||
headers: {
|
||||
@ -616,15 +766,12 @@ let config = {
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
.then(res => {
|
||||
console.log(res.status);
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
|
Reference in New Issue
Block a user