Skip to content

Commit

Permalink
Handle *ast.InterfaceType as any type
Browse files Browse the repository at this point in the history
  • Loading branch information
ubogdan committed Aug 31, 2021
1 parent eef90d0 commit 0616cef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 6 additions & 1 deletion parser.go
Expand Up @@ -871,6 +871,10 @@ func fullTypeName(pkgName, typeName string) string {
// given name and package, and returns swagger schema for it.
func (parser *Parser) parseTypeExpr(file *ast.File, typeExpr ast.Expr, ref bool) (*spec.Schema, error) {
switch expr := typeExpr.(type) {
// type Foo interface{}
case *ast.InterfaceType:
return &spec.Schema{}, nil

// type Foo struct {...}
case *ast.StructType:
return parser.parseStruct(file, expr.Fields)
Expand Down Expand Up @@ -907,6 +911,7 @@ func (parser *Parser) parseTypeExpr(file *ast.File, typeExpr ast.Expr, ref bool)
}

return spec.MapProperty(schema), nil

case *ast.FuncType:
return nil, ErrFuncTypeField
// ...
Expand Down Expand Up @@ -1323,7 +1328,7 @@ func (parser *Parser) GetSchemaTypePath(schema *spec.Schema, depth int) []string
return []string{schema.Type[0]}
}

return nil
return []string{ANY}
}

func replaceLastTag(slice []spec.Tag, element spec.Tag) {
Expand Down
12 changes: 3 additions & 9 deletions parser_test.go
Expand Up @@ -881,9 +881,7 @@ func TestParseSimpleApi_ForSnakecase(t *testing.T) {
"type": "string"
}
},
"data": {
"type": "object"
},
"data": {},
"decimal": {
"type": "number"
},
Expand Down Expand Up @@ -1341,9 +1339,7 @@ func TestParseSimpleApi_ForLowerCamelcase(t *testing.T) {
}
}
},
"data": {
"type": "object"
},
"data": {},
"decimal": {
"type": "number"
},
Expand Down Expand Up @@ -1964,9 +1960,7 @@ type ResponseWrapper struct {
"type": "string"
}
},
"result": {
"type": "object"
},
"result": {},
"status": {
"type": "string"
}
Expand Down
2 changes: 2 additions & 0 deletions schema.go
Expand Up @@ -26,6 +26,8 @@ const (
STRING = "string"
// FUNC func.
FUNC = "func"
// ANY any
ANY = "any"
// NIL nil
NIL = "nil"
)
Expand Down
4 changes: 1 addition & 3 deletions testdata/simple/expected.json
Expand Up @@ -488,9 +488,7 @@
}
}
},
"data": {
"type": "object"
},
"data": {},
"decimal": {
"type": "number"
},
Expand Down

0 comments on commit 0616cef

Please sign in to comment.