swagger2版本文档解析1.0版本 #2
@ -11,6 +11,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"testing"
|
"testing"
|
||||||
@ -35,5 +36,6 @@ func Test_parser_Openapi3(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseForSwagger(t *testing.T) {
|
func TestParseForSwagger(t *testing.T) {
|
||||||
docUrl := "https://git.zhangdeman.cn/swagger.v1.json"
|
docUrl := "https://git.zhangdeman.cn/swagger.v1.json"
|
||||||
_, _ = Parse(docUrl)
|
res, _ := Parse(docUrl)
|
||||||
|
serialize.JSON.ConsoleOutput(res)
|
||||||
}
|
}
|
||||||
|
32
swagger.go
32
swagger.go
@ -123,7 +123,7 @@ func buildSwagger2ParamConfig(swaggerDoc *define.Swagger, paramConfigList []*def
|
|||||||
Location: GetParamLocation(paramConfig.In).String(),
|
Location: GetParamLocation(paramConfig.In).String(),
|
||||||
Path: paramName,
|
Path: paramName,
|
||||||
Type: GetDataType(paramMoreConfig.Type, "").String(),
|
Type: GetDataType(paramMoreConfig.Type, "").String(),
|
||||||
Title: paramMoreConfig.Description,
|
Title: paramName,
|
||||||
Description: paramMoreConfig.Description,
|
Description: paramMoreConfig.Description,
|
||||||
Required: requiredTable[paramName],
|
Required: requiredTable[paramName],
|
||||||
}
|
}
|
||||||
@ -172,24 +172,20 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
|
|||||||
// 不是引用类型, 直接定义的具体类型
|
// 不是引用类型, 直接定义的具体类型
|
||||||
responseKey := GetRealResponseKey(successResponseConfig.Ref)
|
responseKey := GetRealResponseKey(successResponseConfig.Ref)
|
||||||
responseTypeDefine := swaggerDoc.Responses[responseKey]
|
responseTypeDefine := swaggerDoc.Responses[responseKey]
|
||||||
if nil == responseTypeDefine.Schema {
|
responseType := ""
|
||||||
// 204 场景下,可能没有响应body
|
if nil != responseTypeDefine.Schema {
|
||||||
res = append(res, &define.ResultConfig{
|
// 204 等场景下,可能没有响应body
|
||||||
Location: consts.ResponseDataLocationBody.String(),
|
responseType = consts.DataTypeAny.String()
|
||||||
Path: consts.ResponseDataLocationBodyRoot.String(),
|
|
||||||
Type: consts.DataTypeAny.String(),
|
|
||||||
Title: "response body",
|
|
||||||
Description: responseTypeDefine.Description,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
res = append(res, &define.ResultConfig{
|
responseType = GetDataType(responseTypeDefine.Schema.Type, "").String()
|
||||||
Location: consts.ResponseDataLocationBody.String(),
|
|
||||||
Path: consts.ResponseDataLocationBodyRoot.String(),
|
|
||||||
Type: GetDataType(responseTypeDefine.Schema.Type, "").String(),
|
|
||||||
Title: "response body",
|
|
||||||
Description: responseTypeDefine.Description,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
res = append(res, &define.ResultConfig{
|
||||||
|
Location: consts.ResponseDataLocationBody.String(),
|
||||||
|
Path: consts.ResponseDataLocationBodyRoot.String(),
|
||||||
|
Type: responseType,
|
||||||
|
Title: "response body",
|
||||||
|
Description: "response body",
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
responseTypeDefine := swaggerDoc.Definitions[definitionsKey]
|
responseTypeDefine := swaggerDoc.Definitions[definitionsKey]
|
||||||
for responseKey, responseKeyConfig := range responseTypeDefine.Properties {
|
for responseKey, responseKeyConfig := range responseTypeDefine.Properties {
|
||||||
@ -198,7 +194,7 @@ func buildSwagger2ResultConfig(swaggerDoc *define.Swagger, uri string, resultCon
|
|||||||
Path: responseKey,
|
Path: responseKey,
|
||||||
Type: GetDataType(responseKeyConfig.Type, "").String(),
|
Type: GetDataType(responseKeyConfig.Type, "").String(),
|
||||||
Title: responseKey,
|
Title: responseKey,
|
||||||
Description: responseKeyConfig.Description,
|
Description: responseKey,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user