mirror of
https://github.com/foss42/apidash.git
synced 2025-12-04 20:13:56 +08:00
Merge branch 'foss42:main' into add-feature-460
This commit is contained in:
@@ -84,16 +84,15 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest(
|
|||||||
}
|
}
|
||||||
response = switch (requestModel.method) {
|
response = switch (requestModel.method) {
|
||||||
HTTPVerb.get => await client.get(requestUrl, headers: headers),
|
HTTPVerb.get => await client.get(requestUrl, headers: headers),
|
||||||
HTTPVerb.head => response =
|
HTTPVerb.head => await client.head(requestUrl, headers: headers),
|
||||||
await client.head(requestUrl, headers: headers),
|
HTTPVerb.post =>
|
||||||
HTTPVerb.post => response =
|
await client.post(requestUrl, headers: headers, body: body),
|
||||||
await client.post(requestUrl, headers: headers, body: body),
|
HTTPVerb.put =>
|
||||||
HTTPVerb.put => response =
|
await client.put(requestUrl, headers: headers, body: body),
|
||||||
await client.put(requestUrl, headers: headers, body: body),
|
HTTPVerb.patch =>
|
||||||
HTTPVerb.patch => response =
|
await client.patch(requestUrl, headers: headers, body: body),
|
||||||
await client.patch(requestUrl, headers: headers, body: body),
|
HTTPVerb.delete =>
|
||||||
HTTPVerb.delete => response =
|
await client.delete(requestUrl, headers: headers, body: body),
|
||||||
await client.delete(requestUrl, headers: headers, body: body),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (apiType == APIType.graphql) {
|
if (apiType == APIType.graphql) {
|
||||||
|
|||||||
@@ -427,3 +427,17 @@ const httpRequestModelGetBadSSL = HttpRequestModel(
|
|||||||
method: HTTPVerb.get,
|
method: HTTPVerb.get,
|
||||||
url: 'https://expired.badssl.com/',
|
url: 'https://expired.badssl.com/',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// POST request model with content type override having no charset
|
||||||
|
const httpRequestModelPost11 = HttpRequestModel(
|
||||||
|
method: HTTPVerb.post,
|
||||||
|
url: 'https://api.apidash.dev/case/lower',
|
||||||
|
headers: [
|
||||||
|
NameValueModel(name: 'Content-Type', value: 'application/json'),
|
||||||
|
],
|
||||||
|
isHeaderEnabledList: [true],
|
||||||
|
bodyContentType: ContentType.json,
|
||||||
|
body: r"""{
|
||||||
|
"text": "I LOVE Flutter"
|
||||||
|
}""",
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,177 +1,207 @@
|
|||||||
import 'package:apidash/models/models.dart';
|
import 'package:apidash/models/models.dart';
|
||||||
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'http_request_models.dart';
|
import 'http_request_models.dart';
|
||||||
import 'http_response_models.dart';
|
import 'http_response_models.dart';
|
||||||
|
|
||||||
/// Basic GET request model
|
/// Basic GET request model
|
||||||
const requestModelGet1 = RequestModel(
|
const requestModelGet1 = RequestModel(
|
||||||
id: 'get1',
|
id: 'get1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet1,
|
httpRequestModel: httpRequestModelGet1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with query params
|
/// GET request model with query params
|
||||||
const requestModelGet2 = RequestModel(
|
const requestModelGet2 = RequestModel(
|
||||||
id: 'get2',
|
id: 'get2',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet2,
|
httpRequestModel: httpRequestModelGet2,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with override query params
|
/// GET request model with override query params
|
||||||
const requestModelGet3 = RequestModel(
|
const requestModelGet3 = RequestModel(
|
||||||
id: 'get3',
|
id: 'get3',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet3,
|
httpRequestModel: httpRequestModelGet3,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with different types of query params
|
/// GET request model with different types of query params
|
||||||
const requestModelGet4 = RequestModel(
|
const requestModelGet4 = RequestModel(
|
||||||
id: 'get4',
|
id: 'get4',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet4,
|
httpRequestModel: httpRequestModelGet4,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with headers
|
/// GET request model with headers
|
||||||
const requestModelGet5 = RequestModel(
|
const requestModelGet5 = RequestModel(
|
||||||
id: 'get5',
|
id: 'get5',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet5,
|
httpRequestModel: httpRequestModelGet5,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with headers & query params
|
/// GET request model with headers & query params
|
||||||
const requestModelGet6 = RequestModel(
|
const requestModelGet6 = RequestModel(
|
||||||
id: 'get6',
|
id: 'get6',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet6,
|
httpRequestModel: httpRequestModelGet6,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with body
|
/// GET request model with body
|
||||||
const requestModelGet7 = RequestModel(
|
const requestModelGet7 = RequestModel(
|
||||||
id: 'get7',
|
id: 'get7',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet7,
|
httpRequestModel: httpRequestModelGet7,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with empty header & query param name
|
/// GET request model with empty header & query param name
|
||||||
const requestModelGet8 = RequestModel(
|
const requestModelGet8 = RequestModel(
|
||||||
id: 'get8',
|
id: 'get8',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet8,
|
httpRequestModel: httpRequestModelGet8,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET request model with some params enabled
|
/// GET request model with some params enabled
|
||||||
const requestModelGet9 = RequestModel(
|
const requestModelGet9 = RequestModel(
|
||||||
id: 'get9',
|
id: 'get9',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet9,
|
httpRequestModel: httpRequestModelGet9,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET Request model with some headers enabled
|
/// GET Request model with some headers enabled
|
||||||
const requestModelGet10 = RequestModel(
|
const requestModelGet10 = RequestModel(
|
||||||
id: 'get10',
|
id: 'get10',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet10,
|
httpRequestModel: httpRequestModelGet10,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// GET Request model with some headers & URL parameters enabled
|
/// GET Request model with some headers & URL parameters enabled
|
||||||
const requestModelGet11 = RequestModel(
|
const requestModelGet11 = RequestModel(
|
||||||
id: 'get11',
|
id: 'get11',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet11,
|
httpRequestModel: httpRequestModelGet11,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Request model with all headers & URL parameters disabled
|
/// Request model with all headers & URL parameters disabled
|
||||||
const requestModelGet12 = RequestModel(
|
const requestModelGet12 = RequestModel(
|
||||||
id: 'get12',
|
id: 'get12',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet12,
|
httpRequestModel: httpRequestModelGet12,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic HEAD request model
|
/// Basic HEAD request model
|
||||||
const requestModelHead1 = RequestModel(
|
const requestModelHead1 = RequestModel(
|
||||||
id: 'head1',
|
id: 'head1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelHead1,
|
httpRequestModel: httpRequestModelHead1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Without URI Scheme (pass default as http)
|
/// Without URI Scheme (pass default as http)
|
||||||
const requestModelHead2 = RequestModel(
|
const requestModelHead2 = RequestModel(
|
||||||
id: 'head2',
|
id: 'head2',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelHead2,
|
httpRequestModel: httpRequestModelHead2,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic POST request model (txt body)
|
/// Basic POST request model (txt body)
|
||||||
const requestModelPost1 = RequestModel(
|
const requestModelPost1 = RequestModel(
|
||||||
id: 'post1',
|
id: 'post1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost1,
|
httpRequestModel: httpRequestModelPost1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with JSON body
|
/// POST request model with JSON body
|
||||||
const requestModelPost2 = RequestModel(
|
const requestModelPost2 = RequestModel(
|
||||||
id: 'post2',
|
id: 'post2',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost2,
|
httpRequestModel: httpRequestModelPost2,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with headers
|
/// POST request model with headers
|
||||||
const requestModelPost3 = RequestModel(
|
const requestModelPost3 = RequestModel(
|
||||||
id: 'post3',
|
id: 'post3',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost3,
|
httpRequestModel: httpRequestModelPost3,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body(text)
|
/// POST request model with multipart body(text)
|
||||||
const requestModelPost4 = RequestModel(
|
const requestModelPost4 = RequestModel(
|
||||||
id: 'post4',
|
id: 'post4',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost4,
|
httpRequestModel: httpRequestModelPost4,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body and headers
|
/// POST request model with multipart body and headers
|
||||||
const requestModelPost5 = RequestModel(
|
const requestModelPost5 = RequestModel(
|
||||||
id: 'post5',
|
id: 'post5',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost5,
|
httpRequestModel: httpRequestModelPost5,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body(text, file)
|
/// POST request model with multipart body(text, file)
|
||||||
const requestModelPost6 = RequestModel(
|
const requestModelPost6 = RequestModel(
|
||||||
id: 'post6',
|
id: 'post6',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost6,
|
httpRequestModel: httpRequestModelPost6,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body and requestBody (the requestBody shouldn't be in codegen)
|
/// POST request model with multipart body and requestBody (the requestBody shouldn't be in codegen)
|
||||||
const requestModelPost7 = RequestModel(
|
const requestModelPost7 = RequestModel(
|
||||||
id: 'post7',
|
id: 'post7',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost7,
|
httpRequestModel: httpRequestModelPost7,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body and requestParams
|
/// POST request model with multipart body and requestParams
|
||||||
const requestModelPost8 = RequestModel(
|
const requestModelPost8 = RequestModel(
|
||||||
id: 'post8',
|
id: 'post8',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost8,
|
httpRequestModel: httpRequestModelPost8,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// POST request model with multipart body(file and text), requestParams, requestHeaders and requestBody
|
/// POST request model with multipart body(file and text), requestParams, requestHeaders and requestBody
|
||||||
const requestModelPost9 = RequestModel(
|
const requestModelPost9 = RequestModel(
|
||||||
id: 'post9',
|
id: 'post9',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost9,
|
httpRequestModel: httpRequestModelPost9,
|
||||||
);
|
);
|
||||||
|
|
||||||
const requestModelPost10 = RequestModel(
|
const requestModelPost10 = RequestModel(
|
||||||
id: 'post9',
|
id: 'post9',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost10,
|
httpRequestModel: httpRequestModelPost10,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// PUT request model
|
/// PUT request model
|
||||||
const requestModelPut1 = RequestModel(
|
const requestModelPut1 = RequestModel(
|
||||||
id: 'put1',
|
id: 'put1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPut1,
|
httpRequestModel: httpRequestModelPut1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// PATCH request model
|
/// PATCH request model
|
||||||
const requestModelPatch1 = RequestModel(
|
const requestModelPatch1 = RequestModel(
|
||||||
id: 'patch1',
|
id: 'patch1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPatch1,
|
httpRequestModel: httpRequestModelPatch1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic DELETE request model
|
/// Basic DELETE request model
|
||||||
const requestModelDelete1 = RequestModel(
|
const requestModelDelete1 = RequestModel(
|
||||||
id: 'delete1',
|
id: 'delete1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelDelete1,
|
httpRequestModel: httpRequestModelDelete1,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic DELETE with body
|
/// Basic DELETE with body
|
||||||
const requestModelDelete2 = RequestModel(
|
const requestModelDelete2 = RequestModel(
|
||||||
id: 'delete2',
|
id: 'delete2',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelDelete2,
|
httpRequestModel: httpRequestModelDelete2,
|
||||||
);
|
);
|
||||||
|
|
||||||
// full request model
|
// full request model
|
||||||
RequestModel testRequestModel = RequestModel(
|
RequestModel testRequestModel = RequestModel(
|
||||||
id: '1',
|
id: '1',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelPost10,
|
httpRequestModel: httpRequestModelPost10,
|
||||||
responseStatus: 200,
|
responseStatus: 200,
|
||||||
httpResponseModel: responseModel,
|
httpResponseModel: responseModel,
|
||||||
@@ -192,11 +222,19 @@ Map<String, dynamic> requestModelJson = {
|
|||||||
/// Basic GET request model for apidash.dev
|
/// Basic GET request model for apidash.dev
|
||||||
const requestModelGet13 = RequestModel(
|
const requestModelGet13 = RequestModel(
|
||||||
id: 'get13',
|
id: 'get13',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGet13,
|
httpRequestModel: httpRequestModelGet13,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Basic GET request model for badSSL
|
/// Basic GET request model for badSSL
|
||||||
const requestModelGetBadSSL = RequestModel(
|
const requestModelGetBadSSL = RequestModel(
|
||||||
id: 'badSSL',
|
id: 'badSSL',
|
||||||
|
apiType: APIType.rest,
|
||||||
httpRequestModel: httpRequestModelGetBadSSL,
|
httpRequestModel: httpRequestModelGetBadSSL,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const requestModelPost11 = RequestModel(
|
||||||
|
id: 'post11',
|
||||||
|
apiType: APIType.rest,
|
||||||
|
httpRequestModel: httpRequestModelPost11,
|
||||||
|
);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ void main() {
|
|||||||
test('Testing fromResponse for contentType not Json', () async {
|
test('Testing fromResponse for contentType not Json', () async {
|
||||||
var responseRec = await sendHttpRequest(
|
var responseRec = await sendHttpRequest(
|
||||||
requestModelGet13.id,
|
requestModelGet13.id,
|
||||||
requestModelGet1.apiType,
|
requestModelGet13.apiType,
|
||||||
requestModelGet13.httpRequestModel!,
|
requestModelGet13.httpRequestModel!,
|
||||||
defaultUriScheme: kDefaultUriScheme,
|
defaultUriScheme: kDefaultUriScheme,
|
||||||
noSSL: false,
|
noSSL: false,
|
||||||
@@ -47,10 +47,25 @@ void main() {
|
|||||||
expect(responseData.mediaType!.mimeType, 'text/html');
|
expect(responseData.mediaType!.mimeType, 'text/html');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Testing contentType override by the user having no charset (#630)',
|
||||||
|
() async {
|
||||||
|
var responseRec = await sendHttpRequest(
|
||||||
|
requestModelPost11.id,
|
||||||
|
requestModelPost11.apiType,
|
||||||
|
requestModelPost11.httpRequestModel!,
|
||||||
|
);
|
||||||
|
|
||||||
|
final responseData = responseModel.fromResponse(response: responseRec.$1!);
|
||||||
|
expect(responseData.statusCode, 200);
|
||||||
|
expect(responseData.body, '{"data":"i love flutter"}');
|
||||||
|
expect(responseData.contentType, 'application/json; charset=utf-8');
|
||||||
|
expect(responseData.requestHeaders?['content-type'], 'application/json');
|
||||||
|
});
|
||||||
|
|
||||||
test('Testing fromResponse for Bad SSL with certificate check', () async {
|
test('Testing fromResponse for Bad SSL with certificate check', () async {
|
||||||
var responseRec = await sendHttpRequest(
|
var responseRec = await sendHttpRequest(
|
||||||
requestModelGetBadSSL.id,
|
requestModelGetBadSSL.id,
|
||||||
requestModelGet1.apiType,
|
requestModelGetBadSSL.apiType,
|
||||||
requestModelGetBadSSL.httpRequestModel!,
|
requestModelGetBadSSL.httpRequestModel!,
|
||||||
defaultUriScheme: kDefaultUriScheme,
|
defaultUriScheme: kDefaultUriScheme,
|
||||||
noSSL: false,
|
noSSL: false,
|
||||||
@@ -62,7 +77,7 @@ void main() {
|
|||||||
test('Testing fromResponse for Bad SSL with no certificate check', () async {
|
test('Testing fromResponse for Bad SSL with no certificate check', () async {
|
||||||
var responseRec = await sendHttpRequest(
|
var responseRec = await sendHttpRequest(
|
||||||
requestModelGetBadSSL.id,
|
requestModelGetBadSSL.id,
|
||||||
requestModelGet1.apiType,
|
requestModelGetBadSSL.apiType,
|
||||||
requestModelGetBadSSL.httpRequestModel!,
|
requestModelGetBadSSL.httpRequestModel!,
|
||||||
defaultUriScheme: kDefaultUriScheme,
|
defaultUriScheme: kDefaultUriScheme,
|
||||||
noSSL: true,
|
noSSL: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user