递归生成参数结构
This commit is contained in:
		| @ -229,10 +229,20 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren | ||||
| 		parentPath = uri + ".input" | ||||
| 	} | ||||
| 	if len(subPathArr) == 2 { | ||||
| 		if _, exist := swaggerInfo.Definitions[parentPath]; !exist { | ||||
| 			swaggerInfo.Definitions[parentPath] = &define.SwaggerDefinition{ | ||||
| 				Type:       "object", | ||||
| 				Required:   make([]string, 0), | ||||
| 				Properties: make(map[string]*define.SwaggerDefinitionProperty), | ||||
| 			} | ||||
| 		} | ||||
| 		if subPathArr[1] == "[]" { | ||||
| 			swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{ | ||||
| 				Description: paramConfig.Description, | ||||
| 				Type:        "Array", | ||||
| 				Type:        "array", | ||||
| 				Items: map[string]string{ | ||||
| 					"type": util.GetSwaggerType(paramConfig.Type), | ||||
| 				}, | ||||
| 			} | ||||
| 		} else { | ||||
| 			swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{ | ||||
| @ -256,11 +266,23 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren | ||||
| 			} | ||||
| 			swaggerInfo.Definitions[storageSubPath].Properties[subPathArr[1]] = &define.SwaggerDefinitionProperty{ | ||||
| 				Description: paramConfig.Description, | ||||
| 				Type:        paramConfig.Type, | ||||
| 				Type:        util.GetSwaggerType(paramConfig.Type), | ||||
| 			} | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, exist := swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]]; !exist { | ||||
| 		swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{ | ||||
| 			Description: "对象描述", | ||||
| 			Type:        "object", | ||||
| 			Items:       nil, | ||||
| 			AllOf: []map[string]string{map[string]string{ | ||||
| 				"$ref": "#/definitions/" + parentPath + "." + subPathArr[0], | ||||
| 			}}, | ||||
| 		} | ||||
| 	} | ||||
| 	// fmt.Println(parentPath + "." + subPathArr[0]) | ||||
| 	generateParameterDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), paramConfig) | ||||
| } | ||||
|  | ||||
| @ -299,7 +321,7 @@ func generateResponseDefinitions(swaggerInfo *define.Swagger, uri string, parent | ||||
| 		if subPathArr[1] == "[]" { | ||||
| 			swaggerInfo.Definitions[parentPath].Properties[subPathArr[0]] = &define.SwaggerDefinitionProperty{ | ||||
| 				Description: responseConfig.Description, | ||||
| 				Type:        "Array", | ||||
| 				Type:        "array", | ||||
| 			} | ||||
| 		} else { | ||||
| 			generateResponseDefinitions(swaggerInfo, uri, parentPath+"."+subPathArr[0], strings.Join(subPathArr[1:], "."), responseConfig) | ||||
|  | ||||
| @ -61,6 +61,30 @@ func TestGenerate(t *testing.T) { | ||||
| 						Required:    true, | ||||
| 						EnumList:    []interface{}{"man", "woman", "other"}, | ||||
| 					}, | ||||
| 					&define.SwaggerParameterInput{ | ||||
| 						Type:        consts.DataTypeString, | ||||
| 						Description: "性别", | ||||
| 						Name:        "person.job.list.[]", | ||||
| 						In:          "body", | ||||
| 						Required:    true, | ||||
| 						EnumList:    nil, | ||||
| 					}, | ||||
| 					&define.SwaggerParameterInput{ | ||||
| 						Type:        consts.DataTypeInt, | ||||
| 						Description: "年份", | ||||
| 						Name:        "person.job.year.[]", | ||||
| 						In:          "body", | ||||
| 						Required:    true, | ||||
| 						EnumList:    nil, | ||||
| 					}, | ||||
| 					&define.SwaggerParameterInput{ | ||||
| 						Type:        consts.DataTypeInt, | ||||
| 						Description: "测试工作", | ||||
| 						Name:        "person.job.test", | ||||
| 						In:          "body", | ||||
| 						Required:    true, | ||||
| 						EnumList:    nil, | ||||
| 					}, | ||||
| 					&define.SwaggerParameterInput{ | ||||
| 						Type:        consts.DataTypeInt, | ||||
| 						Description: "年龄", | ||||
|  | ||||
		Reference in New Issue
	
	Block a user