fix type of default value in swagger ui for package goai (#2413)

This commit is contained in:
HaiLaz 2023-02-08 14:16:12 +08:00 committed by GitHub
parent 21ebf48072
commit 3adae3a9aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import (
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
type SchemaRefs []SchemaRef
@ -54,13 +55,23 @@ func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap
}
schemaRef.Value = schema
switch oaiType {
case
TypeInteger,
TypeNumber,
TypeString,
TypeBoolean:
// Nothing to do.
case TypeString:
// Nothing to do.
case TypeInteger:
if schemaRef.Value.Default != nil {
schemaRef.Value.Default = gconv.Int64(schemaRef.Value.Default)
}
// keep the default value as nil.
case TypeNumber:
if schemaRef.Value.Default != nil {
schemaRef.Value.Default = gconv.Float64(schemaRef.Value.Default)
}
// keep the default value as nil.
case TypeBoolean:
if schemaRef.Value.Default != nil {
schemaRef.Value.Default = gconv.Bool(schemaRef.Value.Default)
}
// keep the default value as nil.
case
TypeArray:
subSchemaRef, err := oai.newSchemaRefWithGolangType(golangType.Elem(), nil)