Skip to content

Commit

Permalink
perf:openapi3规范响应字段描述缺失不显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoymin committed Dec 31, 2023
1 parent d18e62e commit 658a2c1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
16 changes: 13 additions & 3 deletions knife4j-vue/src/core/Knife4jAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,9 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
// console.log('def');
// 根据def的properties解析
if (KUtils.checkUndefined(def)) {
//response对象的值赋值一个description
originalTreeTableModel.description = KUtils.propValue("description", def, "");

if (def.hasOwnProperty('properties')) {
var props = def['properties'];
// console.log(props)
Expand All @@ -2145,8 +2148,8 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
for (var pkey in props) {
var p = props[pkey];
p.refType = that.getSwaggerModelRefType(p, oas2);
// console.log('------------------analyslsldiflsjfdlsfaaaaaaaaaaaaaaaaaaa')
// console.log(p);
//console.log('------------------analyslsldiflsjfdlsfaaaaaaaaaaaaaaaaaaa')
//console.log(p);
var refp = new SwaggerBootstrapUiParameter();
refp.pid = originalTreeTableModel.id;
refp.readOnly = p.readOnly;
Expand Down Expand Up @@ -2204,12 +2207,18 @@ SwaggerBootstrapUi.prototype.analysisDefinitionRefTableModel = function (instanc
originalTreeTableModel.params.push(refp);
// 判断类型是否基础类型
if (KUtils.checkUndefined(p.refType) && !KUtils.checkIsBasicType(p.refType)) {
// //console('schema类型--------------' + p.refType)
//console.log('schema类型--------------' + p.refType)
refp.schemaValue = p.refType;
refp.schema = true;
// console.log(refp)
// 属性名称不同,或者ref类型不同
var deepDef = that.getOriginalDefinitionByName(p.refType, definitions);
//判断description,如果是class,再赋值一次
if (KUtils.checkUndefined(refp.description)) {
refp.description = KUtils.propValue('description', deepDef, '');
}
//console.log(refp)
//console.log('def,', definitions)
// console.log('find-deepdef')
// console.log(deepDef)
if (KUtils.checkUndefined(deepDef)) {
Expand Down Expand Up @@ -2317,6 +2326,7 @@ SwaggerBootstrapUi.prototype.getOriginalDefinitionByName = function (name, defin
for (var key in definitions) {
if (key == name) {
def['properties'] = definitions[key];
def['description'] = KUtils.propValue('description', definitions[key], '');
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions knife4j-vue/src/layouts/BasicLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export default {
},
beforeCreate() { },
created() {
//this.initSpringDocOpenApi();
this.initKnife4jSpringUi();
this.initSpringDocOpenApi();
//this.initKnife4jSpringUi();
//this.initKnife4jInsight();
//this.initKnife4jJFinal();
//this.initKnife4jFront();
Expand Down
38 changes: 20 additions & 18 deletions knife4j-vue/src/views/api/Document.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@
响应示例
</div>
<a-row :id="'knife4jDocumentShowEditor' + api.id + resp.code">
<editor-show @showDescription="showResponseEditFieldDescription" :value="
resp.responseBasicType ? resp.responseText : resp.responseValue
"></editor-show>
<editor-show @showDescription="showResponseEditFieldDescription" :value="resp.responseBasicType ? resp.responseText : resp.responseValue
"></editor-show>
</a-row>

<!-- <editor :value="resp.responseBasicType ? resp.responseText : resp.responseValue" @init="multiResponseSampleEditorInit" lang="json" theme="eclipse" width="100%" :height="editorMultiHeight"></editor> -->
Expand Down Expand Up @@ -157,11 +156,10 @@
响应示例
</div>
<a-row :id="'knife4jDocumentShowEditor' + api.id">
<editor-show @showDescription="showResponseEditFieldDescription" :value="
multipData.responseBasicType
? multipData.responseText
: multipData.responseValue
"></editor-show>
<editor-show @showDescription="showResponseEditFieldDescription" :value="multipData.responseBasicType
? multipData.responseText
: multipData.responseValue
"></editor-show>

</a-row>
</div>
Expand Down Expand Up @@ -697,9 +695,9 @@ export default {
//console.log("rcodes")
//console.log(rcodes)
if (rcodes != null && rcodes != undefined) {
for(let i=0;i<rcodes.length;i++){
let rc=rcodes[i];
for (let i = 0; i < rcodes.length; i++) {
let rc = rcodes[i];
// 遍历
if (rc.schema != undefined && rc.schema != null) {
var respdata = [];
Expand Down Expand Up @@ -738,6 +736,10 @@ export default {
schemaName
);
model = that.swagger.analysisDefinitionRefTableModel(that.swaggerInstance.id, model);
if (KUtils.checkUndefined(model.description)) {
param.description = model.description;
}
//console.log('params-model', model)
if (model && model.params) {
param.children = model.params.map(child => {
const newObj = that.copyNewParameter(child);
Expand All @@ -748,10 +750,10 @@ export default {
} else {
//console.log("schemavalue--Not Existis,",schemaName)
//非ref类型,在当前自己的params在过滤一边
let childrenParamArray=respdata.filter(childrenParam=>childrenParam.pid==param.id);
let childrenParamArray = respdata.filter(childrenParam => childrenParam.pid == param.id);
//console.log(childrenParamArray)
if(KUtils.checkUndefined(childrenParamArray)){
param.children=childrenParamArray.map(cd=>{
if (KUtils.checkUndefined(childrenParamArray)) {
param.children = childrenParamArray.map(cd => {
const newObj = that.copyNewParameter(cd);
newObj.pid = param.id;
return newObj;
Expand All @@ -776,14 +778,14 @@ export default {
that.multipData = nresobj;
}
that.multipCodeDatas.push(nresobj);
}else{
} else {
// 只获取第一个
// https://gitee.com/xiaoym/knife4j/issues/I5W145
if(i==0){
if (i == 0) {
//不存在schema,直接赋值
that.multipData=rc;
that.multipData = rc;
}
}
}
var multipKeys = Object.keys(that.multipData);
Expand Down

0 comments on commit 658a2c1

Please sign in to comment.