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