修复最大值、最小值处理翻了的BUG
This commit is contained in:
parent
f76641346f
commit
bd7f6d2cfd
@ -554,8 +554,8 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|||||||
} else {
|
} else {
|
||||||
// 当做默认基础类型, 默认不会出现 *map *[]
|
// 当做默认基础类型, 默认不会出现 *map *[]
|
||||||
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
||||||
minVal := ValidateRule.Maximum(inputType.Field(i))
|
maxVal := ValidateRule.Maximum(inputType.Field(i))
|
||||||
maxVal := ValidateRule.Minimum(inputType.Field(i))
|
minVal := ValidateRule.Minimum(inputType.Field(i))
|
||||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
||||||
Type: convertBaseType,
|
Type: convertBaseType,
|
||||||
Format: inputType.Field(i).Type.String(),
|
Format: inputType.Field(i).Type.String(),
|
||||||
@ -613,8 +613,8 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|||||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = g.anyTypeConfig(inputType.Field(i))
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = g.anyTypeConfig(inputType.Field(i))
|
||||||
} else {
|
} else {
|
||||||
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
||||||
minVal := ValidateRule.Maximum(inputType.Field(i))
|
maxVal := ValidateRule.Maximum(inputType.Field(i))
|
||||||
maxVal := ValidateRule.Minimum(inputType.Field(i))
|
minVal := ValidateRule.Minimum(inputType.Field(i))
|
||||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
||||||
Type: convertBaseType,
|
Type: convertBaseType,
|
||||||
Format: inputType.Field(i).Type.String(),
|
Format: inputType.Field(i).Type.String(),
|
||||||
|
@ -126,8 +126,8 @@ func (r validateRule) Maximum(structField reflect.StructField) *int64 {
|
|||||||
ruleTable := r.getValidateRuleTable(structField)
|
ruleTable := r.getValidateRuleTable(structField)
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
maxVal, gleVal int64
|
maxVal, lteVal int64
|
||||||
maxStr, gleStr string
|
maxStr, lteStr string
|
||||||
maxStrExist, gleStrExist bool
|
maxStrExist, gleStrExist bool
|
||||||
)
|
)
|
||||||
if maxStr, maxStrExist = ruleTable[consts.ValidatorRuleCommonMax.String()]; maxStrExist && len(maxStr) > 0 {
|
if maxStr, maxStrExist = ruleTable[consts.ValidatorRuleCommonMax.String()]; maxStrExist && len(maxStr) > 0 {
|
||||||
@ -135,9 +135,9 @@ func (r validateRule) Maximum(structField reflect.StructField) *int64 {
|
|||||||
panic("validate rule min val = " + maxStr + " : " + err.Error())
|
panic("validate rule min val = " + maxStr + " : " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gleStr, gleStrExist = ruleTable[consts.ValidateRuleLte.String()]; gleStrExist && len(gleStr) > 0 {
|
if lteStr, gleStrExist = ruleTable[consts.ValidateRuleLte.String()]; gleStrExist && len(lteStr) > 0 {
|
||||||
if gleVal, err = strconv.ParseInt(gleStr, 10, 64); nil != err {
|
if lteVal, err = strconv.ParseInt(lteStr, 10, 64); nil != err {
|
||||||
panic("validate rule gte val = " + gleStr + " : " + err.Error())
|
panic("validate rule gte val = " + lteStr + " : " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !maxStrExist && !gleStrExist {
|
if !maxStrExist && !gleStrExist {
|
||||||
@ -145,15 +145,15 @@ func (r validateRule) Maximum(structField reflect.StructField) *int64 {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(maxStr) > 0 {
|
if len(maxStr) > 0 {
|
||||||
if len(gleStr) > 0 {
|
if len(lteStr) > 0 {
|
||||||
if gleVal > maxVal {
|
if lteVal > maxVal {
|
||||||
return &gleVal
|
return <eVal
|
||||||
}
|
}
|
||||||
return &maxVal
|
return &maxVal
|
||||||
}
|
}
|
||||||
return &maxVal
|
return &maxVal
|
||||||
}
|
}
|
||||||
return &gleVal
|
return <eVal
|
||||||
}
|
}
|
||||||
|
|
||||||
// getValidateRuleTable 解析验证规则表
|
// getValidateRuleTable 解析验证规则表
|
||||||
|
Loading…
x
Reference in New Issue
Block a user