mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-09 10:23:53 +08:00
[*]优化兼容swagger文档,requestBody&responseBody数组类型属性显示优化
This commit is contained in:
@@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.ssssssss.magicapi.config.MappingHandlerMapping;
|
||||
import org.ssssssss.magicapi.model.ApiInfo;
|
||||
import org.ssssssss.magicapi.model.BaseDefinition;
|
||||
import org.ssssssss.magicapi.model.DataType;
|
||||
import org.ssssssss.magicapi.model.Path;
|
||||
import org.ssssssss.magicapi.provider.GroupServiceProvider;
|
||||
import org.ssssssss.script.parsing.ast.literal.BooleanLiteral;
|
||||
@@ -137,15 +138,19 @@ public class SwaggerProvider {
|
||||
String groupName = groupServiceProvider.getFullName(info.getGroupId()).replace("/", "-");
|
||||
String voName = groupName + "«" + info.getPath().replaceFirst("/", "").replaceAll("/", "_") + "«request«";
|
||||
if (VAR_NAME_REQUEST_BODY_VALUE_TYPE_ARRAY.equalsIgnoreCase(baseDefinition.getDataType().getJavascriptType())) {
|
||||
voName += "root_" + (StringUtils.isNotBlank(baseDefinition.getChildren().get(0).getName()) ? "_" + baseDefinition.getChildren().get(0).getName() : "") + "»»»";
|
||||
voName += "root_" + (StringUtils.isNotBlank(baseDefinition.getChildren().get(0).getName()) ? "_" + baseDefinition.getChildren().get(0).getName() : "_") + "»»»";
|
||||
|
||||
Map<String, Object> items = new HashMap<>(2);
|
||||
items.put("originalRef", voName);
|
||||
items.put("$ref", DEFINITION + voName);
|
||||
schema.put("items", items);
|
||||
schema.put("type", VAR_NAME_REQUEST_BODY_VALUE_TYPE_ARRAY);
|
||||
} else {
|
||||
voName += "root_" + baseDefinition.getName() + "»»»";
|
||||
schema.put("originalRef", voName);
|
||||
schema.put("$ref", DEFINITION + voName);
|
||||
}
|
||||
|
||||
schema.put("originalRef", voName);
|
||||
schema.put("$ref", DEFINITION + voName);
|
||||
parameter.put("schema", schema);
|
||||
// parameter.setSchema(schema);
|
||||
parameter.put("schema", schema);
|
||||
parameters.add(parameter);
|
||||
}else{
|
||||
Object object = mapper.readValue(info.getRequestBody(), Object.class);
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
}
|
||||
|
||||
.json-view {
|
||||
width: 35vw;
|
||||
width: 30vw;
|
||||
overflow: scroll;
|
||||
margin: 0px 10px;
|
||||
border: 1px solid var(--border-color);
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
<div v-show="showIndex === 3" class="ma-layout-container">
|
||||
|
||||
<div style="display: flex; flex-direction: row; height: calc(100% - 24px);">
|
||||
<div style="width: 40%">
|
||||
<div style="width: 50%">
|
||||
<div class="header">编辑器</div>
|
||||
<div ref="bodyEditor" class="ma-body-editor"></div>
|
||||
</div>
|
||||
@@ -374,12 +374,11 @@
|
||||
expression: '',
|
||||
error: '',
|
||||
description: '',
|
||||
children: this.processBody(body, 0),
|
||||
children: this.processBody('Array' === this.getType(body) ? deepClone([body[0]]) : body, 0),
|
||||
level: 0,
|
||||
selected: this.requestBody.length <= 0
|
||||
})
|
||||
|
||||
this.requestBody = this.valueCopy(reqBody, this.requestBody)
|
||||
this.requestBody = deepClone(this.valueCopy(reqBody, this.requestBody))
|
||||
this.forceUpdate = !this.forceUpdate;
|
||||
} catch (e) {
|
||||
// console.error(e)
|
||||
@@ -389,7 +388,7 @@
|
||||
let arr = [], that = this
|
||||
Object.keys(body).forEach((key) => {
|
||||
let param = {
|
||||
name: 'Array' !== this.getType(body) ? key : '',
|
||||
name: 'Array' !== this.getType(body) ? key : 'Array' === this.getType(body) && 'Object' !== that.getType(body[key]) ? key : '',
|
||||
value: 'Object' !== that.getType(body[key]) && 'Array' !== that.getType(body[key]) ? body[key] : '',
|
||||
dataType: this.getType(body[key]),
|
||||
validateType: '',
|
||||
@@ -401,7 +400,7 @@
|
||||
selected: false
|
||||
}
|
||||
if ('Object' === that.getType(body[key]) || 'Array' === that.getType(body[key])) {
|
||||
param.children = that.processBody(body[key], level + 1);
|
||||
param.children = that.processBody('Array' === that.getType(body[key]) ? deepClone([body[key][0]]) : body[key], level + 1);
|
||||
}
|
||||
arr.push(param)
|
||||
|
||||
@@ -458,7 +457,6 @@
|
||||
item.expression = oldItemArr[0].expression
|
||||
item.error = oldItemArr[0].error
|
||||
}
|
||||
item.name = oldItemArr[0].name
|
||||
item.description = oldItemArr[0].description
|
||||
item.selected = oldItemArr[0].selected
|
||||
item.required = oldItemArr[0].required
|
||||
|
||||
@@ -131,7 +131,7 @@ export default {
|
||||
let arr = [], that = this
|
||||
Object.keys(body).forEach((key) => {
|
||||
let param = {
|
||||
name: 'Array' !== this.getType(body) ? key : '',
|
||||
name: 'Array' !== this.getType(body) ? key : 'Array' === this.getType(body) && 'Object' !== that.getType(body[key]) ? key : '',
|
||||
value: 'Object' !== that.getType(body[key]) && 'Array' !== that.getType(body[key]) ? body[key] : '',
|
||||
dataType: this.getType(body[key]),
|
||||
validateType: '',
|
||||
@@ -143,7 +143,7 @@ export default {
|
||||
selected: false
|
||||
}
|
||||
if ('Object' === that.getType(body[key]) || 'Array' === that.getType(body[key])) {
|
||||
param.children = that.processBody(body[key], level + 1);
|
||||
param.children = that.processBody('Array' === that.getType(body[key]) ? deepClone([body[key][0]]) : body[key], level + 1);
|
||||
}
|
||||
arr.push(param)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user