Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Somebody-JIAN committed Mar 24, 2021
2 parents 6ee42fb + f9eba24 commit 27e405f
Show file tree
Hide file tree
Showing 20 changed files with 209 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public class SwaggerApiExportResult extends ApiExportResult{
private String openapi;
private SwaggerInfo info;
private String externalDocs;
private JSONObject externalDocs;
private List<String> servers;
private List<SwaggerTag> tags;
private JSONObject paths; // Map<String, Object>, Object 里放 Operation 对象
private List<String> components;
private JSONObject components;
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ private void parseBody(Content content, Body body) {
MediaType mediaType = content.get(contentType);
if (mediaType == null) {
Set<String> contentTypes = content.keySet();
if(contentTypes.size() == 0) { // 防止空指针
return;
}
contentType = contentTypes.iterator().next();
if (StringUtils.isBlank(contentType)) {
return;
Expand Down Expand Up @@ -410,26 +413,34 @@ public SwaggerApiExportResult swagger3Export(List<ApiDefinitionWithBLOBs> apiDef
result.setInfo(new SwaggerInfo());
result.setServers(new ArrayList<>());
result.setTags(new ArrayList<>());
result.setComponents(new ArrayList<>());
result.setComponents(new JSONObject());
result.setExternalDocs(new JSONObject());

JSONObject paths = new JSONObject();
JSONObject swaggerPath = new JSONObject();
for(ApiDefinitionWithBLOBs apiDefinition : apiDefinitionList) {
SwaggerApiInfo swaggerApiInfo = new SwaggerApiInfo(); // {tags:, summary:, description:, parameters:}
swaggerApiInfo.setSummary(apiDefinition.getName());
// 设置导入后的模块名 (根据 api 的 moduleID 查库获得所属模块,作为导出的模块名)
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
String moduleName = apiModuleService.getNode(apiDefinition.getModuleId()).getName();
String moduleName = "";
if(apiDefinition.getModuleId() != null) { // module_id 可能为空
moduleName = apiModuleService.getNode(apiDefinition.getModuleId()).getName();
}
swaggerApiInfo.setTags(Arrays.asList(moduleName));
// 设置请求体
JSONObject requestObject = JSON.parseObject(apiDefinition.getRequest()); // 将api的request属性转换成JSON对象以便获得参数
JSONObject requestBody = buildRequestBody(requestObject);
swaggerApiInfo.setRequestBody(requestBody);
// 设置响应体
swaggerApiInfo.setResponses(new JSONObject());
// 设置请求参数列表
List<JSONObject> paramsList = buildParameters(requestObject);
swaggerApiInfo.setParameters(paramsList);
swaggerPath.put(apiDefinition.getMethod().toLowerCase(), JSON.parseObject(JSON.toJSONString(swaggerApiInfo))); // 设置api的请求类型和api定义、参数
paths.put(apiDefinition.getPath(), swaggerPath);
JSONObject methodDetail = JSON.parseObject(JSON.toJSONString(swaggerApiInfo));
if(paths.getJSONObject(apiDefinition.getPath()) == null) {
paths.put(apiDefinition.getPath(), new JSONObject());
} // 一个路径下有多个发方法,如post,get,因此是一个 JSONObject 类型
paths.getJSONObject(apiDefinition.getPath()).put(apiDefinition.getMethod().toLowerCase(), methodDetail);
}
result.setPaths(paths);
return result;
Expand Down Expand Up @@ -477,7 +488,9 @@ private JSONObject buildRequestBody(JSONObject request) {
schema.put("format", null);
typeName.put("schema", schema);
JSONObject content = new JSONObject();
content.put(typeMap.get(type), typeName);
if (type != null && StringUtils.isNotBlank(type)) {
content.put(typeMap.get(type), typeName);
}
requestBody.put("content", content);
return requestBody;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class SwaggerApiInfo {
private String summary; // 对应 API 的名字
private List<JSONObject> parameters; // 对应 API 的请求参数
private JSONObject requestBody;
private JSONObject responses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
open(api) {
if (api) {
let data = JSON.parse(JSON.stringify(api));
if (data.protocol === "dubbo://") {
data.protocol = "DUBBO";
}
data.id = getUUID();
this.httpForm = {id: data.id, name: data.name, protocol: data.protocol, path: data.path, method: api.method, userId: getCurrentUser().id, request: data};
this.getMaintainerOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
.script-content {
height: calc(100vh - 570px);
min-height: 250px;
}
.script-index {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</span>
</el-tooltip>
<el-row>
<el-link class="ms-variable-link" @click="batchAdd" style="color: #783887"> {{ $t("commons.batch_add") }}
<el-link class="ms-variable-link" @click="batchAdd" style="color: #783887" :disabled="disabled"> {{ $t("commons.batch_add") }}
</el-link>
</el-row>
<div style="min-height: 400px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ description }}
</span>
<el-row>
<el-checkbox v-model="isSelectAll" v-if="items.length > 1"/>
<el-checkbox v-model="isSelectAll" v-if="isShowEnable === true && items.length > 1"/>
</el-row>
<div class="kv-row item" v-for="(item, index) in items" :key="index">
<el-row type="flex" :gutter="20" justify="space-between" align="middle">
Expand Down Expand Up @@ -52,7 +52,6 @@
valuePlaceholder: String,
isShowEnable: {
type: Boolean,
default: true
},
description: String,
items: Array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
created() {
this.getEnvironments();
},
computed: {
projectId() {
return this.$store.state.projectId
},
},
methods: {
addPre() {
let jsr223PreProcessor = createComponent("JSR223PreProcessor");
Expand Down Expand Up @@ -210,7 +215,8 @@
getEnvironments() {
this.environments = [];
this.$get('/api/environment/list/' + getCurrentProjectID(), response => {
let id = this.request.projectId ? this.request.projectId : this.projectId;
this.$get('/api/environment/list/' + id, response => {
this.environments = response.data;
this.environments.forEach(environment => {
parseEnvironment(environment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<el-form :model="request" :rules="rules" ref="request" label-width="100px" size="small" v-loading="loading"
:disabled="isReadOnly">
<el-button class="get-provider" type="primary" size="small" @click="getProviderList">Get Provider List</el-button>
<el-button class="get-provider" type="primary" size="mini" @click="getProviderList">Get Provider List</el-button>
<el-row>
<el-col :span="12">
<el-form-item label="Interfaces" prop="interfaces">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@
</el-tab-pane>

<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
<!--<div style="width: 400px">-->
<!--<pre>{{ response.responseResult.headers }}</pre>-->
<!--</div>-->
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="response.responseResult.headers"/>

</el-tab-pane>
<!--<el-tab-pane label="Cookie" name="cookie" class="pane cookie">-->
<!--<pre>{{response.cookies}}</pre>-->
<!--</el-tab-pane>-->

<el-tab-pane :label="$t('api_test.definition.request.console')" name="console" class="pane">
<!--<div style="width: 400px">-->
<!--<pre>{{response.responseResult.console}}</pre>-->
<!--</div>-->
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="response.responseResult.console"/>
</el-tab-pane>

Expand All @@ -30,29 +20,10 @@
</el-tab-pane>

<el-tab-pane :label="$t('api_test.request.extract.label')" name="label" class="pane">
<!--<div style="width: 400px">-->
<!--<pre>{{response.responseResult.vars}}</pre>-->
<!--</div>-->
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="response.responseResult.vars"/>
</el-tab-pane>

<el-tab-pane :label="$t('api_report.request_body')" name="request_body" class="pane">
<!--<div class="ms-div">-->
<!--{{$t('api_test.request.address')}} :-->
<!--<pre>{{ response.url }}</pre>-->
<!--</div>-->
<!--<div class="ms-div">-->
<!--{{$t('api_test.scenario.headers')}} :-->
<!--<pre>{{ response.headers }}</pre>-->
<!--</div>-->
<!--<div class="ms-div">-->
<!--Cookies :-->
<!--<pre>{{response.cookies}}</pre>-->
<!--</div>-->
<!--<div class="ms-div">-->
<!--Body :-->
<!--<pre>{{response.body ? response.body:""}}</pre>-->
<!--</div>-->
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="reqMessages"/>
</el-tab-pane>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export default {
let req = this.api.request;
req.id = getUUID();
data.request = JSON.stringify(req);
data.method = this.api.method;
data.path = this.api.path;
data.method = req.method;
data.path = req.path;
data.url = this.api.url;
data.status = this.api.status;
data.userId = this.api.userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<el-popover
placement="right-end"
title="示例"
width="400"
trigger="click"
:content="title">
width="600"
trigger="click">
<ms-code-edit :read-only="true" height="400px" :data.sync="title" :modes="modes" :mode="'html'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.mail_template_example') }}
</el-button>
Expand All @@ -22,6 +22,7 @@
width="400"
trigger="click"
:content="robotTitle">
<ms-code-edit :read-only="true" height="200px" :data.sync="robotTitle" :modes="modes" :mode="'text'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.robot_template') }}
</el-button>
Expand Down Expand Up @@ -132,6 +133,7 @@

<script>
import {hasLicense} from "@/common/js/utils";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
const TASK_TYPE = 'DEFECT_TASK';
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
Expand All @@ -140,6 +142,7 @@ const noticeTemplate = requireComponent.keys().length > 0 ? requireComponent("./
export default {
name: "DefectTaskNotification",
components: {
MsCodeEdit,
"NoticeTemplate": noticeTemplate.default
},
props: {
Expand All @@ -149,6 +152,7 @@ export default {
},
data() {
return {
modes: ['text', 'html'],
title: "<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
Expand Down Expand Up @@ -274,6 +278,7 @@ export default {
.el-row {
margin-bottom: 10px;
}
.el-button {
margin-left: 10px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<el-popover
placement="right-end"
title="示例"
width="400"
trigger="click"
:content="title">
width="600"
trigger="click">
<ms-code-edit :read-only="true" height="400px" :data.sync="title" :modes="modes" :mode="'html'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.mail_template_example') }}
</el-button>
</el-popover>
<el-popover
placement="right-end"
title="示例"
width="400"
trigger="click"
:content="robotTitle">
width="600"
trigger="click">
<ms-code-edit :read-only="true" height="200px" :data.sync="robotTitle" :modes="modes" :mode="'text'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.robot_template') }}
</el-button>
Expand Down Expand Up @@ -136,6 +136,7 @@

<script>
import {hasLicense} from "@/common/js/utils";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
const TASK_TYPE = 'JENKINS_TASK';
Expand All @@ -145,6 +146,7 @@ const noticeTemplate = requireComponent.keys().length > 0 ? requireComponent("./
export default {
name: "JenkinsNotification",
components: {
MsCodeEdit,
"NoticeTemplate": noticeTemplate.default
},
props: {
Expand All @@ -154,6 +156,7 @@ export default {
},
data() {
return {
modes: ['text', 'html'],
title: '<!DOCTYPE html>\n' +
'<html lang="en">\n' +
'<head>\n' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<el-popover
placement="right-end"
title="示例"
width="400"
trigger="click"
:content="title">
width="600"
trigger="click">
<ms-code-edit :read-only="true" height="400px" :data.sync="title" :modes="modes" :mode="'html'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.mail_template_example') }}
</el-button>
</el-popover>
<el-popover
placement="right-end"
title="示例"
width="400"
trigger="click"
:content="robotTitle">
width="200"
trigger="click" >
<ms-code-edit :read-only="true" height="200px" :data.sync="robotTitle" :modes="modes" :mode="'text'"/>
<el-button icon="el-icon-warning" plain size="mini" slot="reference">
{{ $t('organization.message.robot_template') }}
</el-button>
Expand Down Expand Up @@ -136,13 +136,15 @@

<script>
import {hasLicense} from "@/common/js/utils";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const noticeTemplate = requireComponent.keys().length > 0 ? requireComponent("./notice/NoticeTemplate.vue") : {};
export default {
name: "ScheduleTaskNotification",
components: {
MsCodeEdit,
"NoticeTemplate": noticeTemplate.default
},
props: {
Expand All @@ -155,6 +157,7 @@ export default {
},
data() {
return {
modes: ['text', 'html'],
title: '<!DOCTYPE html>\n' +
'<html lang="en">\n' +
'<head>\n' +
Expand Down
Loading

0 comments on commit 27e405f

Please sign in to comment.