优化代码

This commit is contained in:
2024-12-25 12:04:30 +08:00
parent cc4ef13e23
commit f58f8da722
2 changed files with 17 additions and 19 deletions

View File

@ -123,7 +123,7 @@ func buildSwagger2ParamConfig(swaggerDoc *define.Swagger, paramConfigList []*def
Location: GetParamLocation(paramConfig.In).String(),
Path: paramName,
Type: GetDataType(paramMoreConfig.Type, "").String(),
Title: paramMoreConfig.Description,
Title: paramName,
Description: paramMoreConfig.Description,
Required: requiredTable[paramName],
}
@ -172,24 +172,20 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
// 不是引用类型, 直接定义的具体类型
responseKey := GetRealResponseKey(successResponseConfig.Ref)
responseTypeDefine := swaggerDoc.Responses[responseKey]
if nil == responseTypeDefine.Schema {
// 204 场景下可能没有响应body
res = append(res, &define.ResultConfig{
Location: consts.ResponseDataLocationBody.String(),
Path: consts.ResponseDataLocationBodyRoot.String(),
Type: consts.DataTypeAny.String(),
Title: "response body",
Description: responseTypeDefine.Description,
})
responseType := ""
if nil != responseTypeDefine.Schema {
// 204 等场景下可能没有响应body
responseType = consts.DataTypeAny.String()
} else {
res = append(res, &define.ResultConfig{
Location: consts.ResponseDataLocationBody.String(),
Path: consts.ResponseDataLocationBodyRoot.String(),
Type: GetDataType(responseTypeDefine.Schema.Type, "").String(),
Title: "response body",
Description: responseTypeDefine.Description,
})
responseType = GetDataType(responseTypeDefine.Schema.Type, "").String()
}
res = append(res, &define.ResultConfig{
Location: consts.ResponseDataLocationBody.String(),
Path: consts.ResponseDataLocationBodyRoot.String(),
Type: responseType,
Title: "response body",
Description: "response body",
})
} else {
responseTypeDefine := swaggerDoc.Definitions[definitionsKey]
for responseKey, responseKeyConfig := range responseTypeDefine.Properties {
@ -198,7 +194,7 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
Path: responseKey,
Type: GetDataType(responseKeyConfig.Type, "").String(),
Title: responseKey,
Description: responseKeyConfig.Description,
Description: responseKey,
})
}
}