支持openapi文档的解析 #20
@ -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
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user