generics_other.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //go:build !go1.18
  2. // +build !go1.18
  3. package swag
  4. import (
  5. "fmt"
  6. "github.com/go-openapi/spec"
  7. "go/ast"
  8. )
  9. type genericTypeSpec struct {
  10. ArrayDepth int
  11. TypeSpec *TypeSpecDef
  12. Name string
  13. }
  14. func typeSpecFullName(typeSpecDef *TypeSpecDef) string {
  15. return typeSpecDef.FullName()
  16. }
  17. func (pkgDefs *PackagesDefinitions) parametrizeGenericType(file *ast.File, original *TypeSpecDef, fullGenericForm string, parseDependency bool) *TypeSpecDef {
  18. return original
  19. }
  20. func getGenericFieldType(file *ast.File, field ast.Expr, genericParamTypeDefs map[string]*genericTypeSpec) (string, error) {
  21. return "", fmt.Errorf("unknown field type %#v", field)
  22. }
  23. func (parser *Parser) parseGenericTypeExpr(file *ast.File, typeExpr ast.Expr) (*spec.Schema, error) {
  24. switch typeExpr.(type) {
  25. // suppress debug messages for these types
  26. case *ast.InterfaceType:
  27. case *ast.StructType:
  28. case *ast.Ident:
  29. case *ast.StarExpr:
  30. case *ast.SelectorExpr:
  31. case *ast.ArrayType:
  32. case *ast.MapType:
  33. case *ast.FuncType:
  34. default:
  35. parser.debug.Printf("Type definition of type '%T' is not supported yet. Using 'object' instead.\n", typeExpr)
  36. }
  37. return PrimitiveSchema(OBJECT), nil
  38. }