Merge pull request '修复类型为字符串时,最大值 最小值的配置' (#15) from feature/fix_str_length into master
Reviewed-on: #15
This commit is contained in:
commit
f76641346f
@ -138,6 +138,8 @@ type Schema struct {
|
||||
Format string `json:"format,omitempty"` // 格式化类型
|
||||
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
||||
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
||||
MinLength *int64 `json:"minLength,omitempty"` // 字符串最小长度
|
||||
MaxLength *int64 `json:"maxLength,omitempty"` // 字符串最大长度
|
||||
Default any `json:"default,omitempty"` // 默认值
|
||||
}
|
||||
|
||||
@ -155,6 +157,8 @@ type Property struct {
|
||||
Description string `json:"description,omitempty"` // 数据描述, CommonMark syntax可以被用来呈现富文本格式.
|
||||
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
||||
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
||||
MinLength *int64 `json:"minLength,omitempty"` // 字符串最小长度
|
||||
MaxLength *int64 `json:"maxLength,omitempty"` // 字符串最大长度
|
||||
AllOf []*PropertyXOf `json:"allOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
||||
OneOf []*PropertyXOf `json:"oneOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
||||
AnyOf []*PropertyXOf `json:"anyOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
||||
|
38
generate.go
38
generate.go
@ -347,15 +347,15 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
||||
}*/
|
||||
if isBaseType {
|
||||
// 当做默认基础类型, 默认不会出现 *map *[]
|
||||
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
||||
minVal := ValidateRule.Minimum(inputType.Field(i))
|
||||
maxVal := ValidateRule.Maximum(inputType.Field(i))
|
||||
itemParam := &define.PathConfigParameter{
|
||||
Name: propertyName,
|
||||
In: consts.SwaggerParameterInQuery,
|
||||
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
||||
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
||||
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
||||
Schema: &define.Schema{
|
||||
Minimum: ValidateRule.Minimum(inputType.Field(i)),
|
||||
Maximum: ValidateRule.Maximum(inputType.Field(i)),
|
||||
Type: convertBaseType,
|
||||
Format: realInputTypeFormat,
|
||||
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||
@ -366,7 +366,15 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
||||
Style: "",
|
||||
Explode: false,
|
||||
AllowReserved: false,
|
||||
})
|
||||
}
|
||||
if itemParam.Schema.Type == consts.SwaggerDataTypeString {
|
||||
itemParam.Schema.MinLength = minVal
|
||||
itemParam.Schema.MaxLength = maxVal
|
||||
} else {
|
||||
itemParam.Schema.Minimum = minVal
|
||||
itemParam.Schema.Maximum = maxVal
|
||||
}
|
||||
baseReqCfg.Parameters = append(baseReqCfg.Parameters, itemParam)
|
||||
continue
|
||||
}
|
||||
if inputType.Field(i).Type.Kind() == reflect.Interface {
|
||||
@ -546,16 +554,23 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
||||
} else {
|
||||
// 当做默认基础类型, 默认不会出现 *map *[]
|
||||
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
||||
minVal := ValidateRule.Maximum(inputType.Field(i))
|
||||
maxVal := ValidateRule.Minimum(inputType.Field(i))
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
||||
Type: convertBaseType,
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Enum: ValidateRule.Enum(inputType.Field(i)),
|
||||
XEnumDescription: ParseStructFieldTag.EnumDescription(inputType.Field(i)),
|
||||
Maximum: ValidateRule.Maximum(inputType.Field(i)),
|
||||
Minimum: ValidateRule.Minimum(inputType.Field(i)),
|
||||
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
||||
}
|
||||
if g.docData.Components.Schemas[schemaName].Properties[propertyName].Type == consts.SwaggerDataTypeString {
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].MinLength = minVal
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].MaxLength = maxVal
|
||||
} else {
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].Minimum = minVal
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].Maximum = maxVal
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
@ -598,14 +613,21 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = g.anyTypeConfig(inputType.Field(i))
|
||||
} else {
|
||||
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
||||
minVal := ValidateRule.Maximum(inputType.Field(i))
|
||||
maxVal := ValidateRule.Minimum(inputType.Field(i))
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
||||
Type: convertBaseType,
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Maximum: ValidateRule.Maximum(inputType.Field(i)),
|
||||
Minimum: ValidateRule.Minimum(inputType.Field(i)),
|
||||
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
||||
}
|
||||
if g.docData.Components.Schemas[schemaName].Properties[propertyName].Type == consts.SwaggerDataTypeString {
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].MinLength = minVal
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].MaxLength = maxVal
|
||||
} else {
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].Minimum = minVal
|
||||
g.docData.Components.Schemas[schemaName].Properties[propertyName].Maximum = maxVal
|
||||
}
|
||||
}
|
||||
}
|
||||
// 设置参数各种属性
|
||||
|
Loading…
x
Reference in New Issue
Block a user