Skip to content

Commit

Permalink
Merge pull request #807 from YorushikaTopFans/dev
Browse files Browse the repository at this point in the history
fixed:请求参数中当参数为枚举列表时,没有展示枚举的可用值。
  • Loading branch information
xiaoymin authored Aug 13, 2024
2 parents fe4c716 + 85f8180 commit f1b6f22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
27 changes: 15 additions & 12 deletions knife4j-vue/src/core/Knife4jAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2095,8 +2095,7 @@ SwaggerBootstrapUi.prototype.dynamicAddSchema = function (name) {
* @param {model对象} treeTableModel
*/
SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanceId, treeTableModel) {
// console.log('analysisDefinitionRefTableModel-异步解析Model的名称-SwaggerModel功能需要');
//console.log(treeTableModel);
// console.log("当前treeTableModel:", JSON.parse(JSON.stringify(treeTableModel)));
var that = this;
var originalTreeTableModel = treeTableModel;
if (!treeTableModel.init) {
Expand All @@ -2106,8 +2105,7 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
instance = ins;
}
})
// console.log('当前实例')
// console.log(instance)
// console.log("当前实例:", JSON.parse(JSON.stringify(instance)));
for (name in instance.swaggerTreeTableModels) {
if (name == treeTableModel.name) {
originalTreeTableModel = instance.swaggerTreeTableModels[name];
Expand All @@ -2118,14 +2116,15 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
// var definitions=instance.swaggerData['definitions'];
// console.log(instance)
var definitions = instance.getOASDefinitions();
// console.log("当前definitions:", JSON.parse(JSON.stringify(definitions)));
var oas2 = instance.oas2();
// console.log('analysisDefinitionRefTableModel:----------------'+oas2);
// console.log(definitions)
if (KUtils.checkUndefined(definitions)) {
for (var key in definitions) {
if (key == originalTreeTableModel.name) {
var def = definitions[key];
//console.log('def', def);
// console.log("当前def:", JSON.parse(JSON.stringify(def)));
// 根据def的properties解析
if (KUtils.checkUndefined(def)) {
//response对象的值赋值一个description
Expand All @@ -2135,12 +2134,10 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
// console.log(props)
// 获取required属性
var requiredArrs = def.hasOwnProperty('required') ? def['required'] : new Array();
// console.log(props);
for (var pkey in props) {
var p = props[pkey];
p.refType = that.getSwaggerModelRefType(p, oas2);
//console.log('------------------analyslsldiflsjfdlsfaaaaaaaaaaaaaaaaaaa')
//console.log(p);
// console.log("当前p:", JSON.parse(JSON.stringify(p)));
var refp = new SwaggerBootstrapUiParameter();
refp.pid = originalTreeTableModel.id;
refp.readOnly = p.readOnly;
Expand Down Expand Up @@ -2182,8 +2179,13 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
var description = KUtils.propValue('description', p, '');
// 判断是否包含枚举
if (p.hasOwnProperty('enum')) {
//description = description + '可用值:' + p.enum.join(',');
description = KUtils.enumAvalibleLabel(that.i18nInstance, p.enum, description);
// console.log("当前枚举description:", description);
}
// 处理枚举列表类型的参数
else if (p.items && p.items.hasOwnProperty('enum')) {
description = KUtils.enumAvalibleLabel(that.i18nInstance, p.items.enum, description);
// console.log("当前枚举description:", description);
}
refp.description = KUtils.replaceMultipLineStr(description);
//console.log('key:', pkey, ",desc:", KUtils.replaceMultipLineStr(description))
Expand All @@ -2196,8 +2198,6 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
}
}
that.validateJSR303(refp, p);
// models添加所有属性
originalTreeTableModel.params.push(refp);
// 判断类型是否基础类型
if (KUtils.checkUndefined(p.refType) && !KUtils.checkIsBasicType(p.refType)) {
//console.log('schema类型--------------' + p.refType)
Expand Down Expand Up @@ -2252,6 +2252,9 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc

}
}
// console.log("最终的refp:", JSON.parse(JSON.stringify(refp)));
// models添加所有属性
originalTreeTableModel.params.push(refp);
}
} else if (def.hasOwnProperty('additionalProperties')) {
// map类型
Expand Down Expand Up @@ -2296,7 +2299,6 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
refp.description = KUtils.replaceMultipLineStr(description);
// models添加所有属性
originalTreeTableModel.params.push(refp);

}
}
}
Expand All @@ -2307,6 +2309,7 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
}
}
}
// console.log("最终的originalTreeTableModel:", JSON.parse(JSON.stringify(originalTreeTableModel)))
return originalTreeTableModel;
}

Expand Down
26 changes: 11 additions & 15 deletions knife4j-vue/src/views/api/Document.vue
Original file line number Diff line number Diff line change
Expand Up @@ -431,32 +431,28 @@ export default {
}
let reqParameters = [];
if (data != null && data.length > 0) {
// console("初始化请求参数----------");
// console(data);
// console.log("初始化请求参数:", JSON.parse(JSON.stringify(data)));
data.forEach(function (param) {
if (param.pid == "-1") {
param.children = null;
// 判断该参数是否存在schema参数
if (param.schema) {
// 判断当前缓存是否存在
var schemaName = param.schemaValue;
// console.log("param,", param)
// console.log("param:", param);
if (KUtils.checkUndefined(schemaName)) {
// //console("schemaValue--checkUndefined");
// console.log("key:", key);
// console.log("schemaName:", schemaName);
// console.log("that.$Knife4jModels.exists:", that.$Knife4jModels.exists(key, schemaName));
if (that.$Knife4jModels.exists(key, schemaName)) {
// //console("存在-不用查找---" + schemaName);
// //console(that.$Knife4jModels.instance);
var model = that.$Knife4jModels.getByModelName(
key,
schemaName
);
var model = that.$Knife4jModels.getByModelName(key, schemaName);
// console.log("当前model:", JSON.parse(JSON.stringify(model)));
model = that.swagger.analysisDefinitionRefTableModel(that.swaggerInstance.id, model);
// console.log("findmodel")
// console.log(model)
// console.log("当前model:", JSON.parse(JSON.stringify(model)));
if (model && model.params) {
const childrens = model.params
.filter(({ name }) => {
// 过滤第一层忽略的参数
// 过滤第一层忽略的参数
return !(
(
ignoreParameterAllKeys.includes(name) || // 处理 form 表单提交
Expand Down Expand Up @@ -510,6 +506,7 @@ export default {
reqParameters.push(param);
}
});
// console.log("当前reqParameters:", JSON.parse(JSON.stringify(reqParameters)));
}
// 此处需要递归去除include之外的parameters
if (apiInfo.includeParameters != null) {
Expand Down Expand Up @@ -551,8 +548,7 @@ export default {
} else {
that.reqParameters = reqParameters;
}
// console.log("document")
//console.log(reqParameters);
// console.log("当前reqParameters:", JSON.parse(JSON.stringify(reqParameters)));
},
deepRootKeys(tmpIncludeKeys, rootKeys) {
var tmpRooks = [];
Expand Down

0 comments on commit f1b6f22

Please sign in to comment.