优化类型处理
This commit is contained in:
parent
0da14a1492
commit
a736cff687
@ -130,7 +130,7 @@ func (hod *handleOpenapiDoc) apiPathConfigToProjectConfig(uri string, method str
|
|||||||
Title: itemParam.Name,
|
Title: itemParam.Name,
|
||||||
Name: itemParam.Name,
|
Name: itemParam.Name,
|
||||||
Location: hod.openapiDocLocation2GatewayLocation(itemParam.In),
|
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,
|
IsRequired: itemParam.Required,
|
||||||
DefaultValue: "∂",
|
DefaultValue: "∂",
|
||||||
ExampleValue: "",
|
ExampleValue: "",
|
||||||
@ -206,7 +206,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD
|
|||||||
Title: currentPropertyName,
|
Title: currentPropertyName,
|
||||||
Name: currentPropertyName,
|
Name: currentPropertyName,
|
||||||
Location: consts.RequestDataLocationBody.String(),
|
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],
|
IsRequired: requestBodyRequiredParamTable[currentPropertyName],
|
||||||
DefaultValue: defaultValue,
|
DefaultValue: defaultValue,
|
||||||
ExampleValue: "",
|
ExampleValue: "",
|
||||||
@ -236,7 +236,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD
|
|||||||
// 数组类型, 如果是基础类型的数组, 直接返回, map 数组或嵌套数组层层展开
|
// 数组类型, 如果是基础类型的数组, 直接返回, map 数组或嵌套数组层层展开
|
||||||
if currentProperty.Items.Type == consts.SwaggerDataTypeObject || currentProperty.Items.Type == consts.SwaggerDataTypeArray || len(currentProperty.Items.Ref) > 0 {
|
if currentProperty.Items.Type == consts.SwaggerDataTypeObject || currentProperty.Items.Type == consts.SwaggerDataTypeArray || len(currentProperty.Items.Ref) > 0 {
|
||||||
if !strings.HasSuffix(parentPath, ".[]") {
|
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
|
// 数组根key没设置过进行set
|
||||||
importUriConfig.ParamList = append(importUriConfig.ParamList, &apiDocDefine.ApiParamItem{
|
importUriConfig.ParamList = append(importUriConfig.ParamList, &apiDocDefine.ApiParamItem{
|
||||||
Title: currentPropertyName,
|
Title: currentPropertyName,
|
||||||
@ -292,7 +292,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD
|
|||||||
return nil
|
return nil
|
||||||
} else {
|
} 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 {
|
if len(currentProperty.Format) == 0 {
|
||||||
// 未指定format, dataType 添加 [] 前缀
|
// 未指定format, dataType 添加 [] 前缀
|
||||||
dataType = "[]" + dataType
|
dataType = "[]" + dataType
|
||||||
@ -330,7 +330,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD
|
|||||||
Title: fieldName,
|
Title: fieldName,
|
||||||
Name: fieldName,
|
Name: fieldName,
|
||||||
Location: consts.RequestDataLocationBody.String(),
|
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],
|
IsRequired: requestBodyRequiredParamTable[currentPropertyName],
|
||||||
DefaultValue: defaultValue,
|
DefaultValue: defaultValue,
|
||||||
Description: fieldVal.Description,
|
Description: fieldVal.Description,
|
||||||
@ -438,7 +438,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi
|
|||||||
Title: currentPropertyName,
|
Title: currentPropertyName,
|
||||||
DataPath: currentPropertyName,
|
DataPath: currentPropertyName,
|
||||||
DataLocation: consts.RequestDataLocationBody.String(),
|
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,
|
DefaultValue: defaultValue,
|
||||||
ExampleValue: defaultValue,
|
ExampleValue: defaultValue,
|
||||||
Description: currentProperty.Description,
|
Description: currentProperty.Description,
|
||||||
@ -516,7 +516,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi
|
|||||||
return nil
|
return nil
|
||||||
} else {
|
} 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 {
|
if len(currentProperty.Format) == 0 {
|
||||||
// 未指定format, dataType 添加 [] 前缀
|
// 未指定format, dataType 添加 [] 前缀
|
||||||
dataType = "[]" + dataType
|
dataType = "[]" + dataType
|
||||||
@ -552,7 +552,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi
|
|||||||
Title: fieldName,
|
Title: fieldName,
|
||||||
DataPath: fieldName,
|
DataPath: fieldName,
|
||||||
DataLocation: consts.RequestDataLocationBody.String(),
|
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,
|
Description: fieldVal.Description,
|
||||||
DefaultValue: defaultValue,
|
DefaultValue: defaultValue,
|
||||||
ExampleValue: defaultValue,
|
ExampleValue: defaultValue,
|
||||||
@ -613,12 +613,12 @@ func (hod *handleOpenapiDoc) openapiDocLocation2GatewayLocation(openapiDocLocati
|
|||||||
return consts.RequestDataLocationAny.String()
|
return consts.RequestDataLocationAny.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// openapiDocType2GatewayType 文档数据类型转为网关数据类型
|
// openapiDocType2GoType 文档数据类型转为网关数据类型
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 21:07 2025/2/26
|
// 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)
|
openapiDocType = strings.ToLower(openapiDocType)
|
||||||
if formatType == "" {
|
if formatType == "" {
|
||||||
formatType = openapiDocType
|
formatType = openapiDocType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user