From a736cff68747df52ab8508c87995353744b3ae6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 11 Apr 2025 21:38:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- swagger/parser.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/swagger/parser.go b/swagger/parser.go index 61e434d..a9028fe 100644 --- a/swagger/parser.go +++ b/swagger/parser.go @@ -130,7 +130,7 @@ func (hod *handleOpenapiDoc) apiPathConfigToProjectConfig(uri string, method str Title: itemParam.Name, Name: itemParam.Name, Location: hod.openapiDocLocation2GatewayLocation(itemParam.In), - ParamType: hod.openapiDocType2GatewayType(fmt.Sprintf("%v", itemParam.Schema.Type), itemParam.Schema.Format), + ParamType: hod.openapiDocType2GoType(fmt.Sprintf("%v", itemParam.Schema.Type), itemParam.Schema.Format), IsRequired: itemParam.Required, DefaultValue: "∂", ExampleValue: "", @@ -206,7 +206,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD Title: currentPropertyName, Name: currentPropertyName, Location: consts.RequestDataLocationBody.String(), - ParamType: hod.openapiDocType2GatewayType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format), + ParamType: hod.openapiDocType2GoType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format), IsRequired: requestBodyRequiredParamTable[currentPropertyName], DefaultValue: defaultValue, ExampleValue: "", @@ -236,7 +236,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD // 数组类型, 如果是基础类型的数组, 直接返回, map 数组或嵌套数组层层展开 if currentProperty.Items.Type == consts.SwaggerDataTypeObject || currentProperty.Items.Type == consts.SwaggerDataTypeArray || len(currentProperty.Items.Ref) > 0 { if !strings.HasSuffix(parentPath, ".[]") { - dataType := hod.openapiDocType2GatewayType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) + dataType := hod.openapiDocType2GoType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) // 数组根key没设置过进行set importUriConfig.ParamList = append(importUriConfig.ParamList, &apiDocDefine.ApiParamItem{ Title: currentPropertyName, @@ -292,7 +292,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD return nil } else { // 数组子项是基础类型 - dataType := hod.openapiDocType2GatewayType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) + dataType := hod.openapiDocType2GoType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) if len(currentProperty.Format) == 0 { // 未指定format, dataType 添加 [] 前缀 dataType = "[]" + dataType @@ -330,7 +330,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD Title: fieldName, Name: fieldName, Location: consts.RequestDataLocationBody.String(), - ParamType: hod.openapiDocType2GatewayType(fmt.Sprintf("%v", fieldVal.Type), fieldVal.Format), + ParamType: hod.openapiDocType2GoType(fmt.Sprintf("%v", fieldVal.Type), fieldVal.Format), IsRequired: requestBodyRequiredParamTable[currentPropertyName], DefaultValue: defaultValue, Description: fieldVal.Description, @@ -438,7 +438,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi Title: currentPropertyName, DataPath: currentPropertyName, DataLocation: consts.RequestDataLocationBody.String(), - DataType: hod.openapiDocType2GatewayType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format), + DataType: hod.openapiDocType2GoType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format), DefaultValue: defaultValue, ExampleValue: defaultValue, Description: currentProperty.Description, @@ -516,7 +516,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi return nil } else { // 数组子项是基础类型 - dataType := hod.openapiDocType2GatewayType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) + dataType := hod.openapiDocType2GoType(fmt.Sprintf("%v", currentProperty.Type), currentProperty.Format) if len(currentProperty.Format) == 0 { // 未指定format, dataType 添加 [] 前缀 dataType = "[]" + dataType @@ -552,7 +552,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi Title: fieldName, DataPath: fieldName, DataLocation: consts.RequestDataLocationBody.String(), - DataType: hod.openapiDocType2GatewayType(fmt.Sprintf("%v", fieldVal.Type), fieldVal.Format), + DataType: hod.openapiDocType2GoType(fmt.Sprintf("%v", fieldVal.Type), fieldVal.Format), Description: fieldVal.Description, DefaultValue: defaultValue, ExampleValue: defaultValue, @@ -613,12 +613,12 @@ func (hod *handleOpenapiDoc) openapiDocLocation2GatewayLocation(openapiDocLocati return consts.RequestDataLocationAny.String() } -// openapiDocType2GatewayType 文档数据类型转为网关数据类型 +// openapiDocType2GoType 文档数据类型转为网关数据类型 // // Author : go_developer@163.com<白茶清欢> // // Date : 21:07 2025/2/26 -func (hod *handleOpenapiDoc) openapiDocType2GatewayType(openapiDocType string, formatType string) string { +func (hod *handleOpenapiDoc) openapiDocType2GoType(openapiDocType string, formatType string) string { openapiDocType = strings.ToLower(openapiDocType) if formatType == "" { formatType = openapiDocType