基础简版swagger文档生成
This commit is contained in:
parent
d86880c329
commit
8bc001fc79
@ -61,7 +61,7 @@ type SwaggerPathConfig struct {
|
||||
//
|
||||
// Date : 16:53 2024/4/19
|
||||
type SwaggerPathConfigParameter struct {
|
||||
Type string `json:"type"` // 类型
|
||||
Type string `json:"type,omitempty"` // 类型
|
||||
Description string `json:"description"` // 描述
|
||||
Name string `json:"name"` // 参数名称
|
||||
In string `json:"in"` // 参数位置
|
||||
@ -86,9 +86,9 @@ type SwaggerPathConfigResponse struct {
|
||||
//
|
||||
// Date : 17:01 2024/4/19
|
||||
type SwaggerDefinition struct {
|
||||
Type string `json:"type"` // 类型
|
||||
Required []string `json:"required"` // 必传参数列表
|
||||
Properties map[string]*SwaggerDefinitionProperty `json:"properties"` // 参数名 => 参数配置
|
||||
Type string `json:"type"` // 类型
|
||||
Required []string `json:"required,omitempty"` // 必传参数列表
|
||||
Properties map[string]*SwaggerDefinitionProperty `json:"properties"` // 参数名 => 参数配置
|
||||
}
|
||||
|
||||
// SwaggerDefinitionProperty ...
|
||||
|
@ -121,7 +121,7 @@ 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{}
|
||||
hasDealResponseTable := map[string]bool{}
|
||||
|
||||
for _, itemParamInput := range pathConfig.ParameterList {
|
||||
if len(itemParamInput.Name) == 0 {
|
||||
@ -140,8 +140,8 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
if _, exist := hasDealTable[namePath[0]]; !exist {
|
||||
hasDealTable[namePath[0]] = true
|
||||
generateParam := &define.SwaggerPathConfigParameter{
|
||||
Type: wrapper.TernaryOperator.String(realParamName == "jsonBody", "object", wrapper.String(itemParamInput.Type)).Value(),
|
||||
Description: wrapper.TernaryOperator.String(realParamName == "jsonBody", "object", wrapper.String(itemParamInput.Description)).Value(),
|
||||
Type: wrapper.TernaryOperator.String(realParamName == "jsonBody", "", wrapper.String(itemParamInput.Type)).Value(),
|
||||
Description: wrapper.TernaryOperator.String(realParamName == "jsonBody", "参数结构", wrapper.String(itemParamInput.Description)).Value(),
|
||||
Name: realParamName,
|
||||
In: itemParamInput.In,
|
||||
Required: itemParamInput.Required,
|
||||
@ -154,28 +154,27 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
||||
}
|
||||
}
|
||||
|
||||
/*for _, itemResponseConfig := range pathConfig.ResponseList {
|
||||
for _, itemResponseConfig := range pathConfig.ResponseList {
|
||||
for _, itemResponseInput := range itemResponseConfig.List {
|
||||
if len(itemResponseInput.Field) == 0 {
|
||||
// 未指定参数名, 忽略
|
||||
continue
|
||||
}
|
||||
// name 可能是 x.x.x 递归数组, 或者 x.x.[].x
|
||||
outputDefine := pathConfig.Uri + "." + itemResponseConfig.Code + ".output"
|
||||
outputDefine := strings.TrimLeft(pathConfig.Uri, "/") + "." + itemResponseConfig.Code + ".output"
|
||||
generateResponseDefinitions(swaggerInfo, pathConfig.Uri, outputDefine, itemResponseInput.Field, itemResponseInput)
|
||||
namePath := strings.Split(itemResponseInput.Field, ".")
|
||||
if _, exist := hasDealResponseTable[namePath[0]]; !exist {
|
||||
hasDealResponseTable[namePath[0]] = true
|
||||
swaggerInfo.Paths[pathConfig.Uri][pathConfig.Method].Responses[itemResponseConfig.Code] = &define.SwaggerPathConfigResponse{
|
||||
Description: itemResponseInput.Description,
|
||||
Description: "返回数据",
|
||||
Schema: map[string]string{
|
||||
"$ref": "#/definitions" + outputDefine,
|
||||
"$ref": "#/definitions/" + outputDefine,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
// generateParameterDefinitions 生成请求参数的描述
|
||||
@ -258,11 +257,11 @@ func generateResponseDefinitions(swaggerInfo *define.Swagger, uri string, parent
|
||||
if len(parentPath) == 0 {
|
||||
return
|
||||
}
|
||||
swaggerInfo.Definitions[parentPath].Type = responseConfig.Type
|
||||
/*swaggerInfo.Definitions[parentPath].Properties[paramConfig.Name] = &define.SwaggerDefinitionProperty{
|
||||
Description: paramConfig.Description,
|
||||
Type: paramConfig.Type,
|
||||
}*/
|
||||
// swaggerInfo.Definitions[parentPath].Type = responseConfig.Type
|
||||
swaggerInfo.Definitions[parentPath].Properties[responseConfig.Field] = &define.SwaggerDefinitionProperty{
|
||||
Description: responseConfig.Description,
|
||||
Type: responseConfig.Type,
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(parentPath) == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user