diff --git a/parser.go b/parser.go index b3d1dac56..438630d98 100644 --- a/parser.go +++ b/parser.go @@ -1133,6 +1133,11 @@ func (parser *Parser) parseField(field *ast.Field) (*structField, error) { } } + // Skip func fields. + if prop.SchemaType == "func" { + return &structField{name: ""}, nil + } + structField := &structField{ name: field.Names[0].Name, schemaType: prop.SchemaType, diff --git a/property.go b/property.go index 04ae649f5..f65f17849 100644 --- a/property.go +++ b/property.go @@ -118,6 +118,11 @@ func getPropertyName(expr ast.Expr, parser *Parser) (propertyName, error) { if _, ok := expr.(*ast.InterfaceType); ok { // if interface{} return propertyName{SchemaType: "object", ArrayType: "object"}, nil } + + if _, ok := expr.(*ast.FuncType); ok { // if func() + return propertyName{SchemaType: "func", ArrayType: ""}, nil + } + return propertyName{}, errors.New("not supported" + fmt.Sprint(expr)) } diff --git a/schema.go b/schema.go index ba5fe19e1..c05a08c12 100644 --- a/schema.go +++ b/schema.go @@ -23,7 +23,7 @@ func IsSimplePrimitiveType(typeName string) bool { // IsPrimitiveType determine whether the type name is a primitive type func IsPrimitiveType(typeName string) bool { switch typeName { - case "string", "number", "integer", "boolean", "array", "object": + case "string", "number", "integer", "boolean", "array", "object", "func": return true default: return false diff --git a/testdata/simple3/web/handler.go b/testdata/simple3/web/handler.go index b10849525..0447e4d26 100644 --- a/testdata/simple3/web/handler.go +++ b/testdata/simple3/web/handler.go @@ -31,6 +31,7 @@ type Pet struct { Hidden string `json:"-"` UUID uuid.UUID Decimal decimal.Decimal + Function func() } type Tag struct {