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"` // 格式化类型
|
Format string `json:"format,omitempty"` // 格式化类型
|
||||||
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
||||||
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
||||||
|
MinLength *int64 `json:"minLength,omitempty"` // 字符串最小长度
|
||||||
|
MaxLength *int64 `json:"maxLength,omitempty"` // 字符串最大长度
|
||||||
Default any `json:"default,omitempty"` // 默认值
|
Default any `json:"default,omitempty"` // 默认值
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +157,8 @@ type Property struct {
|
|||||||
Description string `json:"description,omitempty"` // 数据描述, CommonMark syntax可以被用来呈现富文本格式.
|
Description string `json:"description,omitempty"` // 数据描述, CommonMark syntax可以被用来呈现富文本格式.
|
||||||
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
Maximum *int64 `json:"maximum,omitempty"` // 最大值
|
||||||
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
Minimum *int64 `json:"minimum,omitempty"` // 最小值
|
||||||
|
MinLength *int64 `json:"minLength,omitempty"` // 字符串最小长度
|
||||||
|
MaxLength *int64 `json:"maxLength,omitempty"` // 字符串最大长度
|
||||||
AllOf []*PropertyXOf `json:"allOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
AllOf []*PropertyXOf `json:"allOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
||||||
OneOf []*PropertyXOf `json:"oneOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
OneOf []*PropertyXOf `json:"oneOf,omitempty"` // type 是一个对象, allOf 指向对象描述
|
||||||
AnyOf []*PropertyXOf `json:"anyOf,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 {
|
if isBaseType {
|
||||||
// 当做默认基础类型, 默认不会出现 *map *[]
|
// 当做默认基础类型, 默认不会出现 *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,
|
Name: propertyName,
|
||||||
In: consts.SwaggerParameterInQuery,
|
In: consts.SwaggerParameterInQuery,
|
||||||
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
||||||
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
||||||
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
||||||
Schema: &define.Schema{
|
Schema: &define.Schema{
|
||||||
Minimum: ValidateRule.Minimum(inputType.Field(i)),
|
|
||||||
Maximum: ValidateRule.Maximum(inputType.Field(i)),
|
|
||||||
Type: convertBaseType,
|
Type: convertBaseType,
|
||||||
Format: realInputTypeFormat,
|
Format: realInputTypeFormat,
|
||||||
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||||
@ -366,7 +366,15 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
|||||||
Style: "",
|
Style: "",
|
||||||
Explode: false,
|
Explode: false,
|
||||||
AllowReserved: 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
|
continue
|
||||||
}
|
}
|
||||||
if inputType.Field(i).Type.Kind() == reflect.Interface {
|
if inputType.Field(i).Type.Kind() == reflect.Interface {
|
||||||
@ -546,16 +554,23 @@ 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.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(),
|
||||||
Enum: ValidateRule.Enum(inputType.Field(i)),
|
Enum: ValidateRule.Enum(inputType.Field(i)),
|
||||||
XEnumDescription: ParseStructFieldTag.EnumDescription(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)),
|
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||||
Description: ParseStructFieldTag.GetParamDesc(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
|
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))
|
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.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(),
|
||||||
Maximum: ValidateRule.Maximum(inputType.Field(i)),
|
|
||||||
Minimum: ValidateRule.Minimum(inputType.Field(i)),
|
|
||||||
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
||||||
Description: ParseStructFieldTag.GetParamDesc(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