完成基础的返回结果数据机构解析
This commit is contained in:
68
swagger.go
68
swagger.go
@ -99,7 +99,7 @@ func buildSwagger2ParamConfig(swaggerDoc *define.Swagger, paramConfigList []*def
|
||||
paramConfigBuildConfig := &define.ParamConfig{
|
||||
Location: GetParamLocation(paramConfig.In).String(),
|
||||
Path: paramConfig.Name,
|
||||
Type: GetParamType(paramConfig.Type, paramConfig.Format).String(),
|
||||
Type: GetDataType(paramConfig.Type, paramConfig.Format).String(),
|
||||
Title: paramConfig.Name,
|
||||
Description: paramConfig.Description,
|
||||
Required: paramConfig.Required,
|
||||
@ -122,7 +122,7 @@ func buildSwagger2ParamConfig(swaggerDoc *define.Swagger, paramConfigList []*def
|
||||
paramConfigBuildConfig := &define.ParamConfig{
|
||||
Location: GetParamLocation(paramConfig.In).String(),
|
||||
Path: paramName,
|
||||
Type: GetParamType(paramMoreConfig.Type, "").String(),
|
||||
Type: GetDataType(paramMoreConfig.Type, "").String(),
|
||||
Title: paramMoreConfig.Description,
|
||||
Description: paramMoreConfig.Description,
|
||||
Required: requiredTable[paramName],
|
||||
@ -140,19 +140,26 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
|
||||
if nil == resultConfig || len(resultConfig) == 0 {
|
||||
return res
|
||||
}
|
||||
if _, exist := resultConfig["200"]; !exist {
|
||||
result204Config := resultConfig["204"]
|
||||
resultConfig["200"] = result204Config
|
||||
}
|
||||
|
||||
if nil == resultConfig["200"] {
|
||||
successResponseConfig := GetSuccessResponseConfig(resultConfig)
|
||||
if nil == successResponseConfig {
|
||||
return res
|
||||
}
|
||||
definitionsKey := ""
|
||||
if swaggerDoc.Responses == nil {
|
||||
definitionsKey = GetRealDefinitionsKey(resultConfig["200"].Schema.Ref)
|
||||
definitionsKey = successResponseConfig.Schema.Ref
|
||||
} else {
|
||||
responseKey := GetRealResponseKey(resultConfig["200"].Ref)
|
||||
responseKey := GetRealResponseKey(successResponseConfig.Ref)
|
||||
if len(responseKey) == 0 {
|
||||
// 204 场景下,可能没有响应body
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: consts.ResponseDataLocationBodyRoot.String(),
|
||||
Type: consts.DataTypeAny.String(),
|
||||
Title: "response body no content",
|
||||
Description: "no content",
|
||||
})
|
||||
return res
|
||||
}
|
||||
ref := swaggerDoc.Responses[responseKey].Ref
|
||||
if len(ref) == 0 {
|
||||
if nil != swaggerDoc.Responses[responseKey].Schema {
|
||||
@ -163,14 +170,37 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
|
||||
}
|
||||
if len(definitionsKey) == 0 {
|
||||
// 不是引用类型, 直接定义的具体类型
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: "",
|
||||
Type: "",
|
||||
Title: "",
|
||||
Description: "",
|
||||
})
|
||||
responseKey := GetRealResponseKey(successResponseConfig.Ref)
|
||||
responseTypeDefine := swaggerDoc.Responses[responseKey]
|
||||
if nil == responseTypeDefine.Schema {
|
||||
// 204 场景下,可能没有响应body
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: consts.ResponseDataLocationBodyRoot.String(),
|
||||
Type: consts.DataTypeAny.String(),
|
||||
Title: "response body",
|
||||
Description: responseTypeDefine.Description,
|
||||
})
|
||||
} else {
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: consts.ResponseDataLocationBodyRoot.String(),
|
||||
Type: GetDataType(responseTypeDefine.Schema.Type, "").String(),
|
||||
Title: "response body",
|
||||
Description: responseTypeDefine.Description,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
responseTypeDefine := swaggerDoc.Definitions[definitionsKey]
|
||||
for responseKey, responseKeyConfig := range responseTypeDefine.Properties {
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: responseKey,
|
||||
Type: GetDataType(responseKeyConfig.Type, "").String(),
|
||||
Title: responseKey,
|
||||
Description: responseKeyConfig.Description,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return res
|
||||
}
|
||||
|
Reference in New Issue
Block a user