swagger2版本文档解析1.0版本 #2

Merged
zhangdeman merged 14 commits from feature/upgrade_parse_swag into master 2024-12-25 15:00:17 +08:00
2 changed files with 17 additions and 19 deletions
Showing only changes of commit f58f8da722 - Show all commits

View File

@ -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)
}

View File

@ -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 {
responseType = GetDataType(responseTypeDefine.Schema.Type, "").String()
}
res = append(res, &define.ResultConfig{
Location: consts.ResponseDataLocationBody.String(),
Path: consts.ResponseDataLocationBodyRoot.String(),
Type: GetDataType(responseTypeDefine.Schema.Type, "").String(),
Type: responseType,
Title: "response body",
Description: responseTypeDefine.Description,
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,
})
}
}