修复响应数据生成的BUG
This commit is contained in:
parent
aadb6f15ee
commit
48bb818654
@ -298,7 +298,7 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
||||
//
|
||||
// Date : 16:50 2024/4/25
|
||||
func handleOneLevelSubPath(swaggerInfo *define.Swagger, uri string, parentPath string, subPath string, paramConfig *define.SwaggerParameterInput) {
|
||||
if paramConfig.In != strings.ToLower(consts.RequestLocationBody) {
|
||||
if paramConfig.In != strings.ToLower(consts.RequestLocationBody) && !isGenerateOutput(parentPath) {
|
||||
// 长度为1, 还不在 body, 无需生成结构体
|
||||
return
|
||||
}
|
||||
@ -419,8 +419,25 @@ func addRequiredField(swaggerInfo *define.Swagger, definitionName string, field
|
||||
// Date : 17:01 2024/4/25
|
||||
func getCheckPath(parentPath string) string {
|
||||
parentPathArr := strings.Split(parentPath, ".")
|
||||
if len(parentPathArr) >= 2 {
|
||||
return strings.Join([]string{parentPathArr[0], parentPathArr[1]}, ".")
|
||||
if isGenerateOutput(parentPath) {
|
||||
return strings.Join([]string{parentPathArr[0], parentPathArr[1], parentPathArr[2]}, ".")
|
||||
} else {
|
||||
if len(parentPathArr) >= 2 {
|
||||
return strings.Join([]string{parentPathArr[0], parentPathArr[1]}, ".")
|
||||
}
|
||||
}
|
||||
return parentPath
|
||||
}
|
||||
|
||||
// isGenerateOutput ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:52 2024/4/25
|
||||
func isGenerateOutput(parentPath string) bool {
|
||||
parentPathArr := strings.Split(parentPath, ".")
|
||||
if len(parentPathArr) >= 3 && parentPathArr[2] == "output" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -135,6 +135,12 @@ func TestGenerate(t *testing.T) {
|
||||
Field: "person.nick_name",
|
||||
IsRequired: false,
|
||||
},
|
||||
&define.SwaggerResponseItemInput{
|
||||
Type: consts.DataTypeMapAnyAny,
|
||||
Description: "测试返回生成map",
|
||||
Field: "obj",
|
||||
IsRequired: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user