优化一波api-doc代码
This commit is contained in:
@ -110,6 +110,8 @@ func generatePathConfig(swaggerInfo *define.Swagger, docConfig *define.SwaggerIn
|
||||
}
|
||||
// 生成参数配置
|
||||
generatePathParameterConfig(swaggerInfo, itemPath)
|
||||
// 生成相应配置
|
||||
generatePathResponseConfig(swaggerInfo, itemPath)
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +123,6 @@ func generatePathConfig(swaggerInfo *define.Swagger, docConfig *define.SwaggerIn
|
||||
func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define.SwaggerPathInput) {
|
||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = make([]*define.SwaggerPathConfigParameter, 0)
|
||||
hasDealTable := map[string]bool{}
|
||||
hasDealResponseTable := map[string]bool{}
|
||||
|
||||
for _, itemParamInput := range pathConfig.ParameterList {
|
||||
if len(itemParamInput.Name) == 0 {
|
||||
@ -132,7 +133,7 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
namePath := strings.Split(itemParamInput.Name, ".")
|
||||
realParamName := namePath[0]
|
||||
parentPath := ""
|
||||
if !strings.Contains(realParamName, ".") {
|
||||
if strings.ToUpper(itemParamInput.In) == consts.RequestLocationBody && !strings.Contains(realParamName, ".") {
|
||||
realParamName = "jsonBody"
|
||||
parentPath = pathConfig.Uri + ".jsonBody"
|
||||
}
|
||||
@ -148,13 +149,22 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
Schema: map[string]string{},
|
||||
}
|
||||
if len(parentPath) > 0 {
|
||||
generateParam.Schema["$ref"] = getRefValue(pathConfig.Uri + ".jsonBody")
|
||||
generateParam.Schema[consts.SwaggerRefKey] = getRefValue(pathConfig.Uri + ".jsonBody")
|
||||
generateParam.Type = ""
|
||||
}
|
||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters = append(swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Parameters, generateParam)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// generatePathResponseConfig 生成响应配置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:43 2024/4/25
|
||||
func generatePathResponseConfig(swaggerInfo *define.Swagger, pathConfig *define.SwaggerPathInput) {
|
||||
hasDealResponseTable := map[string]bool{}
|
||||
for _, itemResponseConfig := range pathConfig.ResponseList {
|
||||
for _, itemResponseInput := range itemResponseConfig.List {
|
||||
if len(itemResponseInput.Field) == 0 {
|
||||
@ -359,7 +369,7 @@ func initAnyDefinition(swaggerInfo *define.Swagger, definitionName string) {
|
||||
}
|
||||
swaggerInfo.Definitions[definitionName] = &define.SwaggerDefinition{
|
||||
Type: consts.SwaggerDataTypeObject,
|
||||
Format: "",
|
||||
Format: consts.DataTypeMapStrAny,
|
||||
Required: make([]string, 0),
|
||||
Properties: make(map[string]*define.SwaggerDefinitionProperty),
|
||||
}
|
||||
@ -371,5 +381,5 @@ func initAnyDefinition(swaggerInfo *define.Swagger, definitionName string) {
|
||||
//
|
||||
// Date : 16:31 2024/4/25
|
||||
func getRefValue(path string) string {
|
||||
return "#/definitions/" + strings.TrimLeft(path, "/")
|
||||
return consts.SwaggerRefValPrefix + strings.TrimLeft(path, "/")
|
||||
}
|
||||
|
Reference in New Issue
Block a user