调试一半的代码
This commit is contained in:
parent
a55cb66fd0
commit
7fb67b63ed
@ -66,7 +66,7 @@ type SwaggerPathConfigParameter struct {
|
|||||||
Name string `json:"name"` // 参数名称
|
Name string `json:"name"` // 参数名称
|
||||||
In string `json:"in"` // 参数位置
|
In string `json:"in"` // 参数位置
|
||||||
Required bool `json:"required"` // 是否必传
|
Required bool `json:"required"` // 是否必传
|
||||||
EnumList []interface{} `json:"enum_list"` // 枚举值列表
|
EnumList []interface{} `json:"enum_list,omitempty"` // 枚举值列表
|
||||||
Schema map[string]string `json:"schema"` // 参数schema
|
Schema map[string]string `json:"schema"` // 参数schema
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ type SwaggerParameterInput struct {
|
|||||||
Name string `json:"name"` // 参数名称
|
Name string `json:"name"` // 参数名称
|
||||||
In string `json:"in"` // 参数位置
|
In string `json:"in"` // 参数位置
|
||||||
Required bool `json:"required"` // 是否必传
|
Required bool `json:"required"` // 是否必传
|
||||||
EnumList []interface{} `json:"enum_list"` // 枚举值列表
|
EnumList []interface{} `json:"enum_list,omitempty"` // 枚举值列表
|
||||||
}
|
}
|
||||||
|
|
||||||
// SwaggerResponseItemInput 响应数据
|
// SwaggerResponseItemInput 响应数据
|
||||||
|
@ -129,20 +129,28 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// name 可能是 x.x.x 递归数组, 或者 x.x.[].x
|
// name 可能是 x.x.x 递归数组, 或者 x.x.[].x
|
||||||
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, "", itemParamInput.Name, itemParamInput)
|
|
||||||
namePath := strings.Split(itemParamInput.Name, ".")
|
namePath := strings.Split(itemParamInput.Name, ".")
|
||||||
|
realParamName := namePath[0]
|
||||||
|
parentPath := ""
|
||||||
|
if !strings.Contains(realParamName, ".") {
|
||||||
|
realParamName = "jsonBody"
|
||||||
|
parentPath = pathConfig.Uri + ".jsonBody"
|
||||||
|
}
|
||||||
|
generateParameterDefinitions(swaggerInfo, pathConfig.Uri, parentPath, itemParamInput.Name, itemParamInput)
|
||||||
if _, exist := hasDealTable[namePath[0]]; !exist {
|
if _, exist := hasDealTable[namePath[0]]; !exist {
|
||||||
hasDealTable[namePath[0]] = true
|
hasDealTable[namePath[0]] = true
|
||||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, &define.SwaggerPathConfigParameter{
|
generateParam := &define.SwaggerPathConfigParameter{
|
||||||
Type: itemParamInput.Type,
|
Type: itemParamInput.Type,
|
||||||
Description: itemParamInput.Description,
|
Description: itemParamInput.Description,
|
||||||
Name: namePath[0],
|
Name: realParamName,
|
||||||
In: itemParamInput.In,
|
In: itemParamInput.In,
|
||||||
Required: itemParamInput.Required,
|
Required: itemParamInput.Required,
|
||||||
Schema: map[string]string{
|
Schema: map[string]string{},
|
||||||
// "$ref": "#/definitions/" + pathConfig.Uri + ".input",
|
}
|
||||||
},
|
if len(parentPath) > 0 {
|
||||||
})
|
generateParam.Schema["$ref"] = "#/definitions/" + strings.TrimLeft(pathConfig.Uri, "/") + ".jsonBody"
|
||||||
|
}
|
||||||
|
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, generateParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,18 +195,33 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
|||||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(subPathArr) == 1 {
|
if len(subPathArr) == 1 {
|
||||||
if len(parentPath) == 0 {
|
if paramConfig.In != strings.ToLower(consts.RequestLocationBody) {
|
||||||
|
// 长度为1, 还不在 body, 无需生成结构体
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, exist := swaggerInfo.Definitions[parentPath]; !exist {
|
||||||
|
swaggerInfo.Definitions[parentPath] = &define.SwaggerDefinition{
|
||||||
|
Type: "object",
|
||||||
|
Required: make([]string, 0),
|
||||||
|
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||||
|
}
|
||||||
|
}
|
||||||
swaggerInfo.Definitions[parentPath].Type = paramConfig.Type
|
swaggerInfo.Definitions[parentPath].Type = paramConfig.Type
|
||||||
if paramConfig.Required {
|
if paramConfig.Required {
|
||||||
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
|
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
|
||||||
}
|
}
|
||||||
/*swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
|
if len(parentPath) > 0 {
|
||||||
|
swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
|
||||||
Description: paramConfig.Description,
|
Description: paramConfig.Description,
|
||||||
Type: paramConfig.Type,
|
Type: paramConfig.Type,
|
||||||
}*/
|
}
|
||||||
|
if paramConfig.Required {
|
||||||
|
swaggerInfo.Definitions[parentPath].Required = append(swaggerInfo.Definitions[parentPath].Required, paramConfig.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(parentPath) == 0 {
|
if len(parentPath) == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user