mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-31 02:25:29 +08:00
Compare commits
3 Commits
v1.8.5
...
tools/goct
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12e03c8843 | ||
|
|
8cf4f95bd7 | ||
|
|
ba0febf308 |
@@ -1,7 +1,7 @@
|
|||||||
coverage:
|
coverage:
|
||||||
status:
|
status:
|
||||||
patch: true
|
patch: true
|
||||||
project: false # disabled because project coverage is not stable
|
project: true
|
||||||
comment:
|
comment:
|
||||||
layout: "flags, files"
|
layout: "flags, files"
|
||||||
behavior: once
|
behavior: once
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func isPostJson(ctx Context, method string, tp apiSpec.Type) (string, bool) {
|
func isPostJson(ctx Context, method string, tp apiSpec.Type) (string, bool) {
|
||||||
if strings.EqualFold(method, http.MethodPost) {
|
if !strings.EqualFold(method, http.MethodPost) {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
structType, ok := tp.(apiSpec.DefineStruct)
|
structType, ok := tp.(apiSpec.DefineStruct)
|
||||||
|
|||||||
91
tools/goctl/api/swagger/parameter_test.go
Normal file
91
tools/goctl/api/swagger/parameter_test.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package swagger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
apiSpec "github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsPostJson(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
method string
|
||||||
|
hasJson bool
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{"POST with JSON", http.MethodPost, true, true},
|
||||||
|
{"POST without JSON", http.MethodPost, false, false},
|
||||||
|
{"GET with JSON", http.MethodGet, true, false},
|
||||||
|
{"PUT with JSON", http.MethodPut, true, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
testStruct := createTestStruct("TestStruct", tt.hasJson)
|
||||||
|
_, result := isPostJson(testingContext(t), tt.method, testStruct)
|
||||||
|
assert.Equal(t, tt.expected, result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParametersFromType(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
method string
|
||||||
|
useDefinitions bool
|
||||||
|
hasJson bool
|
||||||
|
expectedCount int
|
||||||
|
expectedBody bool
|
||||||
|
}{
|
||||||
|
{"POST JSON with definitions", http.MethodPost, true, true, 1, true},
|
||||||
|
{"POST JSON without definitions", http.MethodPost, false, true, 1, true},
|
||||||
|
{"GET with form", http.MethodGet, false, false, 1, false},
|
||||||
|
{"POST with form", http.MethodPost, false, false, 1, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
ctx := Context{UseDefinitions: tt.useDefinitions}
|
||||||
|
testStruct := createTestStruct("TestStruct", tt.hasJson)
|
||||||
|
params := parametersFromType(ctx, tt.method, testStruct)
|
||||||
|
|
||||||
|
assert.Equal(t, tt.expectedCount, len(params))
|
||||||
|
if tt.expectedBody {
|
||||||
|
assert.Equal(t, paramsInBody, params[0].In)
|
||||||
|
} else if len(params) > 0 {
|
||||||
|
assert.NotEqual(t, paramsInBody, params[0].In)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParametersFromType_EdgeCases(t *testing.T) {
|
||||||
|
ctx := testingContext(t)
|
||||||
|
|
||||||
|
params := parametersFromType(ctx, http.MethodPost, nil)
|
||||||
|
assert.Empty(t, params)
|
||||||
|
|
||||||
|
primitiveType := apiSpec.PrimitiveType{RawName: "string"}
|
||||||
|
params = parametersFromType(ctx, http.MethodPost, primitiveType)
|
||||||
|
assert.Empty(t, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTestStruct(name string, hasJson bool) apiSpec.DefineStruct {
|
||||||
|
tag := `form:"username"`
|
||||||
|
if hasJson {
|
||||||
|
tag = `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiSpec.DefineStruct{
|
||||||
|
RawName: name,
|
||||||
|
Members: []apiSpec.Member{
|
||||||
|
{
|
||||||
|
Name: "Username",
|
||||||
|
Type: apiSpec.PrimitiveType{RawName: "string"},
|
||||||
|
Tag: tag,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@ model:
|
|||||||
decimal:
|
decimal:
|
||||||
null_type: sql.NullFloat64
|
null_type: sql.NullFloat64
|
||||||
type: float64
|
type: float64
|
||||||
|
numeric:
|
||||||
|
null_type: sql.NullFloat64
|
||||||
|
type: float64
|
||||||
double:
|
double:
|
||||||
null_type: sql.NullFloat64
|
null_type: sql.NullFloat64
|
||||||
type: float64
|
type: float64
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ require (
|
|||||||
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1
|
||||||
github.com/zeromicro/antlr v0.0.1
|
github.com/zeromicro/antlr v0.0.1
|
||||||
github.com/zeromicro/ddl-parser v1.0.5
|
github.com/zeromicro/ddl-parser v1.0.5
|
||||||
github.com/zeromicro/go-zero v1.8.4
|
github.com/zeromicro/go-zero v1.8.5
|
||||||
golang.org/x/text v0.22.0
|
golang.org/x/text v0.22.0
|
||||||
google.golang.org/grpc v1.65.0
|
google.golang.org/grpc v1.65.0
|
||||||
google.golang.org/protobuf v1.36.5
|
google.golang.org/protobuf v1.36.5
|
||||||
@@ -73,7 +73,7 @@ require (
|
|||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.62.0 // indirect
|
github.com/prometheus/common v0.62.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/redis/go-redis/v9 v9.10.0 // indirect
|
github.com/redis/go-redis/v9 v9.11.0 // indirect
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
github.com/yuin/gopher-lua v1.1.1 // indirect
|
github.com/yuin/gopher-lua v1.1.1 // indirect
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ
|
|||||||
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
|
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
|
||||||
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
@@ -185,8 +185,8 @@ github.com/zeromicro/antlr v0.0.1 h1:CQpIn/dc0pUjgGQ81y98s/NGOm2Hfru2NNio2I9mQgk
|
|||||||
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
github.com/zeromicro/antlr v0.0.1/go.mod h1:nfpjEwFR6Q4xGDJMcZnCL9tEfQRgszMwu3rDz2Z+p5M=
|
||||||
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
github.com/zeromicro/ddl-parser v1.0.5 h1:LaVqHdzMTjasua1yYpIYaksxKqRzFrEukj2Wi2EbWaQ=
|
||||||
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
github.com/zeromicro/ddl-parser v1.0.5/go.mod h1:ISU/8NuPyEpl9pa17Py9TBPetMjtsiHrb9f5XGiYbo8=
|
||||||
github.com/zeromicro/go-zero v1.8.4 h1:3s7kOoThCnkDoqCafsqSX58Y9osYTBIa5QEmomw07TE=
|
github.com/zeromicro/go-zero v1.8.5 h1:YkdQhYllE+BPOrxcni0oCewebs7qHfXvjN9glnpcmJQ=
|
||||||
github.com/zeromicro/go-zero v1.8.4/go.mod h1:eM5f6If/RF+jG1wSCmlvfXD2h2l23vJwETI8oDpjYt4=
|
github.com/zeromicro/go-zero v1.8.5/go.mod h1:P0DKW1vJx+2J3TReptbeg0H9tRSvehymr0HX4SCfZ6g=
|
||||||
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
|
||||||
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildVersion is the version of goctl.
|
// BuildVersion is the version of goctl.
|
||||||
const BuildVersion = "1.8.4"
|
const BuildVersion = "1.8.5"
|
||||||
|
|
||||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
|
|
||||||
var p2m = map[string]string{
|
var p2m = map[string]string{
|
||||||
"int8": "bigint",
|
"int8": "bigint",
|
||||||
"numeric": "double",
|
|
||||||
"decimal": "double",
|
|
||||||
"float8": "double",
|
"float8": "double",
|
||||||
"float4": "float",
|
"float4": "float",
|
||||||
"int2": "smallint",
|
"int2": "smallint",
|
||||||
|
|||||||
Reference in New Issue
Block a user