mirror of
https://github.com/foss42/apidash.git
synced 2025-05-22 00:36:43 +08:00
Update ContentType & ResponseBodyView enums
This commit is contained in:
@ -22,7 +22,7 @@ class DartHttpCodeGen {
|
|||||||
queryParams: requestModel.enabledParamsMap,
|
queryParams: requestModel.enabledParamsMap,
|
||||||
headers: {...requestModel.enabledHeadersMap},
|
headers: {...requestModel.enabledHeadersMap},
|
||||||
contentType: requestModel.requestBodyContentType,
|
contentType: requestModel.requestBodyContentType,
|
||||||
hasContentTypeHeader: requestModel.hasContentTypeHeader,
|
hasContentTypeHeader: requestModel.hasContentTypeHeader,
|
||||||
body: requestModel.requestBody,
|
body: requestModel.requestBody,
|
||||||
formData: requestModel.formDataMapList,
|
formData: requestModel.formDataMapList,
|
||||||
);
|
);
|
||||||
@ -57,8 +57,8 @@ class DartHttpCodeGen {
|
|||||||
final strContent = CodeExpression(Code('r\'\'\'$body\'\'\''));
|
final strContent = CodeExpression(Code('r\'\'\'$body\'\'\''));
|
||||||
dataExp = declareVar('body', type: refer('String')).assign(strContent);
|
dataExp = declareVar('body', type: refer('String')).assign(strContent);
|
||||||
if (!hasContentTypeHeader) {
|
if (!hasContentTypeHeader) {
|
||||||
headers.putIfAbsent(HttpHeaders.contentTypeHeader,
|
headers.putIfAbsent(
|
||||||
() => kContentTypeMap[contentType] ?? '');
|
HttpHeaders.contentTypeHeader, () => contentType.header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,7 @@ import okhttp3.MediaType.Companion.toMediaType""";
|
|||||||
var contentLength = utf8.encode(requestBody).length;
|
var contentLength = utf8.encode(requestBody).length;
|
||||||
if (contentLength > 0) {
|
if (contentLength > 0) {
|
||||||
hasBody = true;
|
hasBody = true;
|
||||||
String contentType =
|
String contentType = requestModel.requestBodyContentType.header;
|
||||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
|
||||||
var templateBody = jj.Template(kTemplateRequestBody);
|
var templateBody = jj.Template(kTemplateRequestBody);
|
||||||
result += templateBody
|
result += templateBody
|
||||||
.render({"contentType": contentType, "body": requestBody});
|
.render({"contentType": contentType, "body": requestBody});
|
||||||
|
@ -154,7 +154,7 @@ body = b'\r\n'.join(dataList)
|
|||||||
hasHeaders = true;
|
hasHeaders = true;
|
||||||
if (hasBody && !requestModel.hasContentTypeHeader) {
|
if (hasBody && !requestModel.hasContentTypeHeader) {
|
||||||
headers[HttpHeaders.contentTypeHeader] =
|
headers[HttpHeaders.contentTypeHeader] =
|
||||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
requestModel.requestBodyContentType.header;
|
||||||
}
|
}
|
||||||
var headersString = kEncoder.convert(headers);
|
var headersString = kEncoder.convert(headers);
|
||||||
headersString = padMultilineString(headersString, kHeadersPadding);
|
headersString = padMultilineString(headersString, kHeadersPadding);
|
||||||
|
@ -162,7 +162,7 @@ print('Response Body:', response.text)
|
|||||||
hasHeaders = true;
|
hasHeaders = true;
|
||||||
if (hasBody) {
|
if (hasBody) {
|
||||||
headers[HttpHeaders.contentTypeHeader] =
|
headers[HttpHeaders.contentTypeHeader] =
|
||||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
requestModel.requestBodyContentType.header;
|
||||||
}
|
}
|
||||||
var headersString = kEncoder.convert(headers);
|
var headersString = kEncoder.convert(headers);
|
||||||
headersString = padMultilineString(headersString, kHeadersPadding);
|
headersString = padMultilineString(headersString, kHeadersPadding);
|
||||||
|
@ -242,8 +242,6 @@ enum RequestItemMenuOption { edit, delete, duplicate }
|
|||||||
|
|
||||||
enum HTTPVerb { get, head, post, put, patch, delete }
|
enum HTTPVerb { get, head, post, put, patch, delete }
|
||||||
|
|
||||||
enum ContentType { json, text, formdata }
|
|
||||||
|
|
||||||
enum FormDataType { text, file }
|
enum FormDataType { text, file }
|
||||||
|
|
||||||
const kSupportedUriSchemes = ["https", "http"];
|
const kSupportedUriSchemes = ["https", "http"];
|
||||||
@ -312,25 +310,25 @@ const kTypeVideo = 'video';
|
|||||||
|
|
||||||
const kSubTypeDefaultViewOptions = 'all';
|
const kSubTypeDefaultViewOptions = 'all';
|
||||||
|
|
||||||
const kContentTypeMap = {
|
enum ContentType {
|
||||||
ContentType.json: "$kTypeApplication/$kSubTypeJson",
|
json("$kTypeApplication/$kSubTypeJson"),
|
||||||
ContentType.text: "$kTypeText/$kSubTypePlain",
|
text("$kTypeText/$kSubTypePlain"),
|
||||||
ContentType.formdata: "multipart/form-data",
|
formdata("multipart/form-data");
|
||||||
};
|
|
||||||
|
|
||||||
enum ResponseBodyView { preview, code, raw, none }
|
const ContentType(this.header);
|
||||||
|
final String header;
|
||||||
|
}
|
||||||
|
|
||||||
const kKeyIcon = "icon";
|
enum ResponseBodyView {
|
||||||
const kKeyName = "name";
|
preview("Preview", Icons.visibility_rounded),
|
||||||
const Map<ResponseBodyView, Map> kResponseBodyViewIcons = {
|
code("Preview", Icons.code_rounded),
|
||||||
ResponseBodyView.none: {kKeyName: "Preview", kKeyIcon: Icons.warning},
|
raw("Raw", Icons.text_snippet_rounded),
|
||||||
ResponseBodyView.preview: {
|
none("Preview", Icons.warning);
|
||||||
kKeyName: "Preview",
|
|
||||||
kKeyIcon: Icons.visibility_rounded
|
const ResponseBodyView(this.label, this.icon);
|
||||||
},
|
final String label;
|
||||||
ResponseBodyView.code: {kKeyName: "Preview", kKeyIcon: Icons.code_rounded},
|
final IconData icon;
|
||||||
ResponseBodyView.raw: {kKeyName: "Raw", kKeyIcon: Icons.text_snippet_rounded}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const kNoBodyViewOptions = [ResponseBodyView.none];
|
const kNoBodyViewOptions = [ResponseBodyView.none];
|
||||||
const kNoRawBodyViewOptions = [ResponseBodyView.none, ResponseBodyView.raw];
|
const kNoRawBodyViewOptions = [ResponseBodyView.none, ResponseBodyView.raw];
|
||||||
|
@ -31,7 +31,7 @@ Future<(http.Response?, Duration?, String?)> request(
|
|||||||
headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
|
headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
|
||||||
if (!requestModel.hasContentTypeHeader) {
|
if (!requestModel.hasContentTypeHeader) {
|
||||||
headers[HttpHeaders.contentTypeHeader] =
|
headers[HttpHeaders.contentTypeHeader] =
|
||||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
requestModel.requestBodyContentType.header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ Map<String, dynamic> requestModelToHARJsonRequest(
|
|||||||
hasBody = true;
|
hasBody = true;
|
||||||
json["postData"] = {};
|
json["postData"] = {};
|
||||||
json["postData"]["mimeType"] =
|
json["postData"]["mimeType"] =
|
||||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
requestModel.requestBodyContentType.header;
|
||||||
json["postData"]["text"] = requestBody;
|
json["postData"]["text"] = requestBody;
|
||||||
if (exportMode) {
|
if (exportMode) {
|
||||||
json["postData"]["comment"] = "";
|
json["postData"]["comment"] = "";
|
||||||
@ -139,7 +139,7 @@ Map<String, dynamic> requestModelToHARJsonRequest(
|
|||||||
if (hasBody && !requestModel.hasContentTypeHeader) {
|
if (hasBody && !requestModel.hasContentTypeHeader) {
|
||||||
var m = {
|
var m = {
|
||||||
"name": "Content-Type",
|
"name": "Content-Type",
|
||||||
"value": kContentTypeMap[requestModel.requestBodyContentType] ?? ""
|
"value": requestModel.requestBodyContentType.header
|
||||||
};
|
};
|
||||||
if (exportMode) {
|
if (exportMode) {
|
||||||
m["comment"] = "";
|
m["comment"] = "";
|
||||||
|
@ -397,16 +397,13 @@ class _BodySuccessState extends State<BodySuccess> {
|
|||||||
(widget.options == kRawBodyViewOptions)
|
(widget.options == kRawBodyViewOptions)
|
||||||
? const SizedBox()
|
? const SizedBox()
|
||||||
: SegmentedButton<ResponseBodyView>(
|
: SegmentedButton<ResponseBodyView>(
|
||||||
selectedIcon: Icon(
|
selectedIcon: Icon(currentSeg.icon),
|
||||||
kResponseBodyViewIcons[currentSeg]![kKeyIcon]),
|
|
||||||
segments: widget.options
|
segments: widget.options
|
||||||
.map<ButtonSegment<ResponseBodyView>>(
|
.map<ButtonSegment<ResponseBodyView>>(
|
||||||
(e) => ButtonSegment<ResponseBodyView>(
|
(e) => ButtonSegment<ResponseBodyView>(
|
||||||
value: e,
|
value: e,
|
||||||
label: Text(
|
label: Text(e.label),
|
||||||
kResponseBodyViewIcons[e]![kKeyName]),
|
icon: Icon(e.icon),
|
||||||
icon: Icon(
|
|
||||||
kResponseBodyViewIcons[e]![kKeyIcon]),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
|
Reference in New Issue
Block a user