refactor(接口测试): 优化swagger文件默认响应码的展示

This commit is contained in:
wxg0103 2024-04-29 10:59:47 +08:00 committed by 刘瑞斌
parent 46afc6c124
commit 4263347d7e
3 changed files with 7 additions and 4 deletions

View File

@ -15,7 +15,7 @@ public class TempFileUtils {
} }
public static boolean isImage(String type) { public static boolean isImage(String type) {
return StringUtils.equalsAnyIgnoreCase(type, "jpg", "jpeg", "png", "gif", "bmp", "svg", "ico", "webp", "apng", "avif"); return StringUtils.equalsAnyIgnoreCase(type, "jpg", "jpeg", "png", "gif", "bmp", "svg", "ico", "webp", "apng", "avif","pdf");
} }
public static String getFileNameByPath(String filePath) { public static String getFileNameByPath(String filePath) {

View File

@ -186,7 +186,7 @@ public class Swagger3Parser<T> extends ApiImportAbstractParser<ApiDefinitionImpo
responseBody.forEach((key, value) -> { responseBody.forEach((key, value) -> {
HttpResponse httpResponse = new HttpResponse(); HttpResponse httpResponse = new HttpResponse();
//TODO headers //TODO headers
httpResponse.setStatusCode(key); httpResponse.setStatusCode(StringUtils.equals("default", key) ? "200" :key);
ResponseBody body = new ResponseBody(); ResponseBody body = new ResponseBody();
Map<String, io.swagger.v3.oas.models.headers.Header> headers = value.getHeaders(); Map<String, io.swagger.v3.oas.models.headers.Header> headers = value.getHeaders();
if (MapUtils.isNotEmpty(headers)) { if (MapUtils.isNotEmpty(headers)) {

View File

@ -183,11 +183,14 @@ public class MockServerService {
String fileId = responseBody.getBinaryBody().getFile().getFileId(); String fileId = responseBody.getBinaryBody().getFile().getFileId();
String fileName = responseBody.getBinaryBody().getFile().getFileName(); String fileName = responseBody.getBinaryBody().getFile().getFileName();
String fileType = StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1); String fileType = StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1);
MediaType mediaType = MediaType.parseMediaType("application/octet-stream"); MediaType mediaType = MediaType.parseMediaType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
if (responseBody.getBinaryBody().isSendAsBody()) { if (responseBody.getBinaryBody().isSendAsBody()) {
String contentType = "text/plain"; String contentType = MediaType.TEXT_PLAIN_VALUE;
if (TempFileUtils.isImage(fileType)) { if (TempFileUtils.isImage(fileType)) {
contentType = "image/" + fileType; contentType = "image/" + fileType;
if (StringUtils.equalsIgnoreCase(fileType, "pdf")) {
contentType = MediaType.APPLICATION_PDF_VALUE;
}
} }
mediaType = MediaType.parseMediaType(contentType); mediaType = MediaType.parseMediaType(contentType);
} }