fix
This commit is contained in:
43
swagger.go
43
swagger.go
@ -57,7 +57,7 @@ func buildUriList(swaggerDoc *define.Swagger) ([]*define.UriBaseConfig, error) {
|
||||
Summary: methodConfig.Summary,
|
||||
Description: methodConfig.Description,
|
||||
ParamList: buildSwagger2ParamConfig(swaggerDoc, methodConfig.Parameters),
|
||||
ResultList: nil,
|
||||
ResultList: buildSwagger2ResultConfig(swaggerDoc, itemUri, methodConfig.Responses),
|
||||
}
|
||||
uriList = append(uriList, uriResult)
|
||||
}
|
||||
@ -133,3 +133,44 @@ func buildSwagger2ParamConfig(swaggerDoc *define.Swagger, paramConfigList []*def
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// buildSwagger2ResultConfig 构建响应结果配置
|
||||
func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultConfig map[string]*define.SwaggerPathConfigResponse) []*define.ResultConfig {
|
||||
res := make([]*define.ResultConfig, 0)
|
||||
if nil == resultConfig || len(resultConfig) == 0 {
|
||||
return res
|
||||
}
|
||||
if _, exist := resultConfig["200"]; !exist {
|
||||
result204Config := resultConfig["204"]
|
||||
resultConfig["200"] = result204Config
|
||||
}
|
||||
|
||||
if nil == resultConfig["200"] {
|
||||
return res
|
||||
}
|
||||
definitionsKey := ""
|
||||
if swaggerDoc.Responses == nil {
|
||||
definitionsKey = GetRealDefinitionsKey(resultConfig["200"].Schema.Ref)
|
||||
} else {
|
||||
responseKey := GetRealResponseKey(resultConfig["200"].Ref)
|
||||
ref := swaggerDoc.Responses[responseKey].Ref
|
||||
if len(ref) == 0 {
|
||||
if nil != swaggerDoc.Responses[responseKey].Schema {
|
||||
ref = swaggerDoc.Responses[responseKey].Schema.Ref
|
||||
}
|
||||
}
|
||||
definitionsKey = GetRealDefinitionsKey(ref)
|
||||
}
|
||||
if len(definitionsKey) == 0 {
|
||||
// 不是引用类型, 直接定义的具体类型
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: "",
|
||||
Type: "",
|
||||
Title: "",
|
||||
Description: "",
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user