mirror of
https://github.com/foss42/apidash.git
synced 2025-05-31 22:33:59 +08:00
fixes
This commit is contained in:
@ -1,45 +1,38 @@
|
|||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'package:jinja/jinja.dart' as jj;
|
import 'package:jinja/jinja.dart' as jj;
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
import 'package:apidash/utils/utils.dart'
|
import 'package:apidash/utils/utils.dart' show getValidRequestUri;
|
||||||
show getValidRequestUri;
|
|
||||||
import 'package:apidash/models/models.dart';
|
import 'package:apidash/models/models.dart';
|
||||||
|
|
||||||
|
|
||||||
class RustHyperCodeGen {
|
class RustHyperCodeGen {
|
||||||
final String kTemplateStart = """
|
final String kTemplateStart = """
|
||||||
{% if hasForm %}extern crate hyper_multipart_rfc7578 as hyper_multipart;{% endif %}
|
{% if hasForm %}extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
{% endif %}use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
{% if isHttps %}use hyper_tls::HttpsConnector;
|
||||||
use hyper_tls::HttpsConnector;
|
{% else %}use hyper::client::HttpConnector;
|
||||||
{% if hasForm %}use hyper_multipart::client::multipart;{% endif %}
|
{% endif %}{% if hasForm %}use hyper_multipart::client::multipart;
|
||||||
{% if hasJsonBody %}use serde_json::json;{% endif %}
|
{% endif %}{% if hasJsonBody %}use serde_json::json;
|
||||||
use tokio;
|
{% endif %}use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let https = HttpsConnector::new();
|
let http{% if isHttps %}s{% endif %} = Http{% if isHttps %}s{% endif %}Connector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(http{% if isHttps %}s{% endif %});
|
||||||
let url = "{{ url }}".parse::<Uri>().unwrap();
|
let url = "{{ url }}".parse::<Uri>().unwrap();
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateMethod = """
|
final String kTemplateMethod = """
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("{{ method }}")
|
.method("{{ method }}")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
""";
|
""";
|
||||||
final String kTemplateMethodNoHeadersButForm = """
|
final String kTemplateMethodNoHeadersButForm = """
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("{{ method }}")
|
.method("{{ method }}")
|
||||||
.uri(url);
|
.uri(url);
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateHeaders = """
|
final String kTemplateHeaders = """
|
||||||
{% for key, val in headers %}
|
{% for key, val in headers %}
|
||||||
.header("{{ key }}", "{{ val }}")
|
.header("{{ key }}", "{{ val }}")
|
||||||
@ -51,7 +44,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateBody = """
|
final String kTemplateBody = """
|
||||||
|
|
||||||
.body(Body::from(r#"{{ body }}"#))?;\n
|
.body(Body::from(r#"{{ body }}"#))?;\n
|
||||||
@ -67,10 +59,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.body(Body::empty())?;\n
|
.body(Body::empty())?;\n
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateFormData = """
|
final String kTemplateFormData = """
|
||||||
|
|
||||||
let mut form = multipart::Form::default();
|
let mut form = multipart::Form::default();
|
||||||
@ -82,11 +70,10 @@ final String kTemplateFormData = """
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateEndForm = """
|
final String kTemplateEndForm = """
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -100,7 +87,7 @@ final String kTemplateFormData = """
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
final String kTemplateRequestEnd = """
|
final String kTemplateRequestEnd = """
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -110,21 +97,14 @@ final String kTemplateFormData = """
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
final String kTemplateEnd = """
|
final String kTemplateEnd = """
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String? getCode(HttpRequestModel requestModel) {
|
String? getCode(HttpRequestModel requestModel) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
String url = requestModel.url;
|
String url = requestModel.url;
|
||||||
@ -132,11 +112,11 @@ final String kTemplateFormData = """
|
|||||||
Uri? uri = rec.$1;
|
Uri? uri = rec.$1;
|
||||||
|
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
|
|
||||||
var headers = requestModel.enabledHeadersMap;
|
var headers = requestModel.enabledHeadersMap;
|
||||||
result += jj.Template(kTemplateStart).render({
|
result += jj.Template(kTemplateStart).render({
|
||||||
"url": uri,
|
"url": uri,
|
||||||
'hasJsonBody': requestModel.bodyContentType == ContentType.json,
|
"isHttps": uri.scheme == "https" ? true : false,
|
||||||
|
'hasJsonBody': requestModel.hasJsonData,
|
||||||
'hasForm': requestModel.hasFormData,
|
'hasForm': requestModel.hasFormData,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -148,33 +128,34 @@ final String kTemplateFormData = """
|
|||||||
result += jj.Template(kTemplateMethod).render({
|
result += jj.Template(kTemplateMethod).render({
|
||||||
"method": requestModel.method.name.toUpperCase(),
|
"method": requestModel.method.name.toUpperCase(),
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add headers if available
|
// Add headers if available
|
||||||
|
|
||||||
if (headers.isNotEmpty) {
|
if (headers.isNotEmpty) {
|
||||||
if (requestModel.hasFormData) {
|
if (requestModel.hasFormData) {
|
||||||
result += jj.Template(kTemplateHeadersFormData).render({"headers": headers});
|
result += jj.Template(kTemplateHeadersFormData)
|
||||||
|
.render({"headers": headers});
|
||||||
} else {
|
} else {
|
||||||
result += jj.Template(kTemplateHeaders).render({"headers": headers});
|
result +=
|
||||||
|
jj.Template(kTemplateHeaders).render({"headers": headers});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle body (JSON or raw)
|
// Handle body (JSON or raw)
|
||||||
var requestBody = requestModel.body;
|
var requestBody = requestModel.body;
|
||||||
if (requestModel.hasFormData) {
|
if (requestModel.hasFormData) {
|
||||||
|
|
||||||
result += jj.Template(kTemplateFormData).render({
|
result += jj.Template(kTemplateFormData).render({
|
||||||
"fields_list": requestModel.formDataMapList,
|
"fields_list": requestModel.formDataMapList,
|
||||||
});
|
});
|
||||||
}else if (requestBody == "" || requestBody == null|| requestModel.method ==HTTPVerb.get || requestModel.method == HTTPVerb.head) {
|
} else if (requestBody == "" ||
|
||||||
|
requestBody == null ||
|
||||||
|
requestModel.method == HTTPVerb.get ||
|
||||||
|
requestModel.method == HTTPVerb.head) {
|
||||||
result += kTemplateEmptyBody;
|
result += kTemplateEmptyBody;
|
||||||
} else if (requestModel.hasJsonData) {
|
} else if (requestModel.hasJsonData) {
|
||||||
result += jj.Template(kTemplateJsonBody).render({"body": requestBody});
|
result +=
|
||||||
|
jj.Template(kTemplateJsonBody).render({"body": requestBody});
|
||||||
} else if (requestModel.hasTextData) {
|
} else if (requestModel.hasTextData) {
|
||||||
result += jj.Template(kTemplateBody).render({"body": requestBody});
|
result += jj.Template(kTemplateBody).render({"body": requestBody});
|
||||||
}
|
}
|
||||||
@ -184,7 +165,6 @@ final String kTemplateFormData = """
|
|||||||
result += kTemplateEndForm;
|
result += kTemplateEndForm;
|
||||||
} else {
|
} else {
|
||||||
result += kTemplateRequestEnd;
|
result += kTemplateRequestEnd;
|
||||||
|
|
||||||
}
|
}
|
||||||
result += kTemplateEnd;
|
result += kTemplateEnd;
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,13 @@ import 'package:apidash/consts.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import '../models/request_models.dart';
|
import '../models/request_models.dart';
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
final codeGen = Codegen();
|
final codeGen = Codegen();
|
||||||
group('GET Request', () {
|
group('GET Request', () {
|
||||||
test('GET1', () {
|
test('GET1', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -23,12 +17,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -46,12 +40,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
});
|
});
|
||||||
test('GET2', () {
|
test('GET2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -59,12 +49,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/country/data?code=US".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/country/data?code=US".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -83,12 +73,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
test('GET3', () {
|
test('GET3', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -96,12 +82,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/country/data?code=IND".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/country/data?code=IND".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -120,12 +106,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
test('GET4', () {
|
test('GET4', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -133,12 +115,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -155,15 +137,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('GET5', () {
|
test('GET5', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -171,14 +148,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.github.com/repos/foss42/apidash".parse::<Uri>().unwrap();
|
let url = "https://api.github.com/repos/foss42/apidash".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
|
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -195,16 +172,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test('GET6', () {
|
test('GET6', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -212,14 +183,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.github.com/repos/foss42/apidash?raw=true".parse::<Uri>().unwrap();
|
let url = "https://api.github.com/repos/foss42/apidash?raw=true".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
|
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -236,17 +207,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test('GET7', () {
|
test('GET7', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -254,12 +218,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -276,17 +240,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test('GET8', () {
|
test('GET8', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -294,14 +251,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.github.com/repos/foss42/apidash?raw=true".parse::<Uri>().unwrap();
|
let url = "https://api.github.com/repos/foss42/apidash?raw=true".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
|
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -319,12 +276,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
});
|
});
|
||||||
test('GET9', () {
|
test('GET9', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -332,12 +285,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/humanize/social?num=8700000&add_space=true".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/humanize/social?num=8700000&add_space=true".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -356,12 +309,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
test('GET10', () {
|
test('GET10', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -369,14 +318,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/humanize/social".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/humanize/social".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
|
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -389,20 +338,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelGet10, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelGet10, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test('GET11', () {
|
test('GET11', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -410,14 +354,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/humanize/social?num=8700000&digits=3".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/humanize/social?num=8700000&digits=3".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
|
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -430,19 +374,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelGet11, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelGet11, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('GET12', () {
|
test('GET12', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -450,12 +390,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/humanize/social".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/humanize/social".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -468,22 +408,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelGet12, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelGet12, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
group('HEAD Request', () {
|
group('HEAD Request', () {
|
||||||
test('HEAD1', () {
|
test('HEAD1', () {
|
||||||
const expectedCode = """
|
const expectedCode = """
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -491,12 +426,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("HEAD")
|
.method("HEAD")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -508,74 +443,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
""";
|
""";
|
||||||
expect(codeGen.getCode(CodegenLanguage.rustHyper, requestModelHead1, "https"),
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelHead1, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('HEAD2', () {
|
test('HEAD2', () {
|
||||||
const expectedCode = """
|
const expectedCode = """
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
use hyper::client::HttpConnector;
|
||||||
use hyper_tls::HttpsConnector;
|
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let https = HttpsConnector::new();
|
let http = HttpConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(http);
|
||||||
let url = "https://api.apidash.dev".parse::<Uri>().unwrap();
|
let url = "http://api.apidash.dev".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("HEAD")
|
.method("HEAD")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
|
||||||
|
|
||||||
println!("Response Status: {}", status);
|
|
||||||
println!("Response: {:?}", body);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
""";
|
|
||||||
expect(codeGen.getCode(CodegenLanguage.rustHyper, requestModelHead2, "https"),
|
|
||||||
expectedCode);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
group('POST Request', () {
|
|
||||||
test('POST1', () {
|
|
||||||
const expectedCode = r"""
|
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
|
||||||
|
|
||||||
|
|
||||||
use tokio;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let https = HttpsConnector::new();
|
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
|
||||||
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
|
||||||
let reqBuilder = Request::builder()
|
|
||||||
.method("POST")
|
|
||||||
.uri(url)
|
|
||||||
.body(Body::from(r#"{
|
|
||||||
"text": "I LOVE Flutter"
|
|
||||||
}"#))?;
|
|
||||||
let res = client.request(reqBuilder).await?;
|
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -588,16 +478,50 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost1, "https"),
|
codeGen.getCode(CodegenLanguage.rustHyper, requestModelHead2, "http"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('POST Request', () {
|
||||||
|
test('POST1', () {
|
||||||
|
const expectedCode = r"""
|
||||||
|
use hyper::{Body, Client, Request, Uri};
|
||||||
|
use hyper_tls::HttpsConnector;
|
||||||
|
use tokio;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let https = HttpsConnector::new();
|
||||||
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
|
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
||||||
|
let req_builder = Request::builder()
|
||||||
|
.method("POST")
|
||||||
|
.uri(url)
|
||||||
|
.body(Body::from(r#"{
|
||||||
|
"text": "I LOVE Flutter"
|
||||||
|
}"#))?;
|
||||||
|
let res = client.request(req_builder).await?;
|
||||||
|
let status = res.status();
|
||||||
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
|
|
||||||
|
println!("Response Status: {}", status);
|
||||||
|
println!("Response: {:?}", body);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost1, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST2', () {
|
test('POST2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
@ -606,7 +530,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::from(json!({
|
.body(Body::from(json!({
|
||||||
@ -617,7 +541,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
"no": 1.2,
|
"no": 1.2,
|
||||||
"arr": ["null", "true", "false", null]
|
"arr": ["null", "true", "false", null]
|
||||||
}).to_string()))?;
|
}).to_string()))?;
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -630,16 +554,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost2, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost2, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST3', () {
|
test('POST3', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
@ -648,7 +570,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/case/lower".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
@ -656,7 +578,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.body(Body::from(json!({
|
.body(Body::from(json!({
|
||||||
"text": "I LOVE Flutter"
|
"text": "I LOVE Flutter"
|
||||||
}).to_string()))?;
|
}).to_string()))?;
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -669,17 +591,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost3, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost3, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST4', () {
|
test('POST4', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -687,7 +608,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/form".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/form".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url);
|
.uri(url);
|
||||||
let mut form = multipart::Form::default();
|
let mut form = multipart::Form::default();
|
||||||
@ -695,7 +616,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
form.add_text("sep", "|");
|
form.add_text("sep", "|");
|
||||||
form.add_text("times", "3");
|
form.add_text("times", "3");
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -711,17 +632,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost4, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost4, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST5', () {
|
test('POST5', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -729,7 +649,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/form".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/form".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent");
|
.header("User-Agent", "Test Agent");
|
||||||
@ -739,7 +659,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
form.add_text("sep", "|");
|
form.add_text("sep", "|");
|
||||||
form.add_text("times", "3");
|
form.add_text("times", "3");
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -755,17 +675,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost5, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost5, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST6', () {
|
test('POST6', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -773,14 +692,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/img".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/img".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url);
|
.uri(url);
|
||||||
let mut form = multipart::Form::default();
|
let mut form = multipart::Form::default();
|
||||||
form.add_text("token", "xyz");
|
form.add_text("token", "xyz");
|
||||||
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -796,17 +715,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost6, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost6, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST7', () {
|
test('POST7', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -814,14 +732,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/img".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/img".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url);
|
.uri(url);
|
||||||
let mut form = multipart::Form::default();
|
let mut form = multipart::Form::default();
|
||||||
form.add_text("token", "xyz");
|
form.add_text("token", "xyz");
|
||||||
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -837,17 +755,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost7, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost7, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST8', () {
|
test('POST8', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -855,7 +772,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/form?size=2&len=3".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/form?size=2&len=3".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url);
|
.uri(url);
|
||||||
let mut form = multipart::Form::default();
|
let mut form = multipart::Form::default();
|
||||||
@ -863,7 +780,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
form.add_text("sep", "|");
|
form.add_text("sep", "|");
|
||||||
form.add_text("times", "3");
|
form.add_text("times", "3");
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -879,17 +796,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost8, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost8, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
test('POST9', () {
|
test('POST9', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
extern crate hyper_multipart_rfc7578 as hyper_multipart;
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
use hyper_multipart::client::multipart;
|
use hyper_multipart::client::multipart;
|
||||||
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -897,7 +813,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://api.apidash.dev/io/img?size=2&len=3".parse::<Uri>().unwrap();
|
let url = "https://api.apidash.dev/io/img?size=2&len=3".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header("User-Agent", "Test Agent")
|
.header("User-Agent", "Test Agent")
|
||||||
@ -908,7 +824,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
form.add_text("token", "xyz");
|
form.add_text("token", "xyz");
|
||||||
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
form.add_file("imfile", r"/Documents/up/1.png").unwrap();
|
||||||
|
|
||||||
let req = form.set_body_convert::<Body, multipart::Body>(reqBuilder).unwrap();
|
let req = form.set_body_convert::<Body, multipart::Body>(req_builder).unwrap();
|
||||||
|
|
||||||
let res = client.request(req).await?;
|
let res = client.request(req).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
@ -924,20 +840,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPost9, "https"),
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPost9, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
group('PUT Request', () {
|
group('PUT Request', () {
|
||||||
test('PUT1', () {
|
test('PUT1', () {
|
||||||
const expectedCode = """
|
const expectedCode = """
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
@ -946,14 +859,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("PUT")
|
.method("PUT")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::from(json!({
|
.body(Body::from(json!({
|
||||||
"name": "morpheus",
|
"name": "morpheus",
|
||||||
"job": "zion resident"
|
"job": "zion resident"
|
||||||
}).to_string()))?;
|
}).to_string()))?;
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -965,22 +878,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
""";
|
""";
|
||||||
expect(codeGen.getCode(CodegenLanguage.rustHyper, requestModelPut1, "https"),
|
expect(
|
||||||
|
codeGen.getCode(CodegenLanguage.rustHyper, requestModelPut1, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
group('PATCH Request', () {
|
group('PATCH Request', () {
|
||||||
test('PATCH1', () {
|
test('PATCH1', () {
|
||||||
const expectedCode = """
|
const expectedCode = """
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
@ -989,14 +897,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("PATCH")
|
.method("PATCH")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::from(json!({
|
.body(Body::from(json!({
|
||||||
"name": "marfeus",
|
"name": "marfeus",
|
||||||
"job": "accountant"
|
"job": "accountant"
|
||||||
}).to_string()))?;
|
}).to_string()))?;
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -1008,7 +916,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
""";
|
""";
|
||||||
expect(codeGen.getCode(CodegenLanguage.rustHyper, requestModelPatch1, "https"),
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.rustHyper, requestModelPatch1, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1016,12 +926,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
group('DELETE Request', () {
|
group('DELETE Request', () {
|
||||||
test('DELETE1', () {
|
test('DELETE1', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@ -1029,12 +935,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::empty())?;
|
.body(Body::empty())?;
|
||||||
|
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -1053,11 +959,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
});
|
});
|
||||||
test('DELETE2', () {
|
test('DELETE2', () {
|
||||||
const expectedCode = r"""
|
const expectedCode = r"""
|
||||||
|
|
||||||
use hyper::{Body, Client, Request, Uri};
|
use hyper::{Body, Client, Request, Uri};
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio;
|
use tokio;
|
||||||
|
|
||||||
@ -1066,14 +969,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
let url = "https://reqres.in/api/users/2".parse::<Uri>().unwrap();
|
||||||
let reqBuilder = Request::builder()
|
let req_builder = Request::builder()
|
||||||
.method("DELETE")
|
.method("DELETE")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.body(Body::from(json!({
|
.body(Body::from(json!({
|
||||||
"name": "marfeus",
|
"name": "marfeus",
|
||||||
"job": "accountant"
|
"job": "accountant"
|
||||||
}).to_string()))?;
|
}).to_string()))?;
|
||||||
let res = client.request(reqBuilder).await?;
|
let res = client.request(req_builder).await?;
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let body_bytes = hyper::body::to_bytes(res).await?;
|
let body_bytes = hyper::body::to_bytes(res).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
let body = String::from_utf8(body_bytes.to_vec())?;
|
||||||
@ -1091,7 +994,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user