From 1c3657f712296053e9a7f720f43789ce5cc8be03 Mon Sep 17 00:00:00 2001 From: Bogdan Ungureanu Date: Wed, 5 Apr 2023 23:28:03 +0300 Subject: [PATCH] chore: remove GOPATH support and go1.17 --- .github/workflows/ci.yml | 18 ----------- README.md | 2 +- README_zh-CN.md | 2 +- generics.go | 3 -- generics_other.go | 42 ------------------------- generics_other_test.go | 67 ---------------------------------------- generics_test.go | 3 -- 7 files changed, 2 insertions(+), 135 deletions(-) delete mode 100644 generics_other.go delete mode 100644 generics_other_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d16a00809..7dad15e83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,36 +15,18 @@ jobs: runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 - with: - path: ./src/github.com/${{ github.repository }} - name: Set up Go uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: deps - working-directory: ./src/github.com/${{ github.repository }} run: make deps - env: - GOPATH: ${{ runner.workspace }} - name: static program analysis - working-directory: ./src/github.com/${{ github.repository }} run: | - export PATH=$PATH:$(go env GOPATH)/bin # https://github.com/actions/setup-go/issues/14 - mkdir -p $(go env GOPATH)/src/github.com/swaggo - ln -s $(pwd) $(go env GOPATH)/src/github.com/swaggo/swag make fmt-check lint vet - env: - GOPATH: ${{ runner.workspace }} - name: build run: make build - working-directory: ./src/github.com/${{ github.repository }} - env: - GOPATH: ${{ runner.workspace }} - name: test - working-directory: ./src/github.com/${{ github.repository }} run: make test - env: - GOPATH: ${{ runner.workspace }} - name: coverage - working-directory: ./src/github.com/${{ github.repository }} run: bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index 4a48fa6ff..36fa48a89 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie ```sh go install github.com/swaggo/swag/cmd/swag@latest ``` -To build from source you need [Go](https://golang.org/dl/) (1.17 or newer). +To build from source you need [Go](https://golang.org/dl/) (1.18 or newer). Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases). diff --git a/README_zh-CN.md b/README_zh-CN.md index 60b6fb559..3ff52d0be 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -50,7 +50,7 @@ Swag将Go的注释转换为Swagger2.0文档。我们为流行的 [Go Web Framewo go install github.com/swaggo/swag/cmd/swag@latest ``` -从源码开始构建的话,需要有Go环境(1.17及以上版本)。 +从源码开始构建的话,需要有Go环境(1.18及以上版本)。 或者从github的release页面下载预编译好的二进制文件。 diff --git a/generics.go b/generics.go index c14b3ab01..c22dbaa8b 100644 --- a/generics.go +++ b/generics.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package swag import ( diff --git a/generics_other.go b/generics_other.go deleted file mode 100644 index 5fd9e8231..000000000 --- a/generics_other.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package swag - -import ( - "fmt" - "github.com/go-openapi/spec" - "go/ast" -) - -type genericTypeSpec struct { - ArrayDepth int - TypeSpec *TypeSpecDef - Name string -} - -func (pkgDefs *PackagesDefinitions) parametrizeGenericType(file *ast.File, original *TypeSpecDef, fullGenericForm string) *TypeSpecDef { - return original -} - -func getGenericFieldType(file *ast.File, field ast.Expr, genericParamTypeDefs map[string]*genericTypeSpec) (string, error) { - return "", fmt.Errorf("unknown field type %#v", field) -} - -func (parser *Parser) parseGenericTypeExpr(file *ast.File, typeExpr ast.Expr) (*spec.Schema, error) { - switch typeExpr.(type) { - // suppress debug messages for these types - case *ast.InterfaceType: - case *ast.StructType: - case *ast.Ident: - case *ast.StarExpr: - case *ast.SelectorExpr: - case *ast.ArrayType: - case *ast.MapType: - case *ast.FuncType: - default: - parser.debug.Printf("Type definition of type '%T' is not supported yet. Using 'object' instead.\n", typeExpr) - } - - return PrimitiveSchema(OBJECT), nil -} diff --git a/generics_other_test.go b/generics_other_test.go deleted file mode 100644 index 1a396a04b..000000000 --- a/generics_other_test.go +++ /dev/null @@ -1,67 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package swag - -import ( - "fmt" - "github.com/stretchr/testify/assert" - "go/ast" - "testing" -) - -type testLogger struct { - Messages []string -} - -func (t *testLogger) Printf(format string, v ...interface{}) { - t.Messages = append(t.Messages, fmt.Sprintf(format, v...)) -} - -func TestParametrizeStruct(t *testing.T) { - t.Parallel() - - pd := PackagesDefinitions{ - packages: make(map[string]*PackageDefinitions), - } - - tSpec := &TypeSpecDef{ - TypeSpec: &ast.TypeSpec{ - Name: &ast.Ident{Name: "Field"}, - Type: &ast.StructType{Struct: 100, Fields: &ast.FieldList{Opening: 101, Closing: 102}}, - }, - } - - tr := pd.parametrizeGenericType(&ast.File{}, tSpec, "") - assert.Equal(t, tr, tSpec) - - tr = pd.parametrizeGenericType(&ast.File{}, tSpec, "") - assert.Equal(t, tr, tSpec) -} - -func TestParseGenericTypeExpr(t *testing.T) { - t.Parallel() - - parser := New() - logger := &testLogger{} - SetDebugger(logger)(parser) - - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.InterfaceType{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.StructType{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.Ident{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.StarExpr{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.SelectorExpr{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.ArrayType{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.MapType{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.FuncType{}) - assert.Empty(t, logger.Messages) - _, _ = parser.parseGenericTypeExpr(&ast.File{}, &ast.BadExpr{}) - assert.NotEmpty(t, logger.Messages) -} diff --git a/generics_test.go b/generics_test.go index 8fa7bdfc3..bd79f93de 100644 --- a/generics_test.go +++ b/generics_test.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package swag import (