From f58f8da72205e65e5ddedc993157964e9de8fefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 25 Dec 2024 12:04:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parser_test.go | 4 +++- swagger.go | 32 ++++++++++++++------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/parser_test.go b/parser_test.go index 149598a..1bcfa94 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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) } diff --git a/swagger.go b/swagger.go index c197b4f..b5d35fe 100644 --- a/swagger.go +++ b/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, }) } }