feat(goctl): better generate the api code of typescript (#2483)
This commit is contained in:
15
tools/goctl/api/spec/example_test.go
Normal file
15
tools/goctl/api/spec/example_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package spec_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
)
|
||||
|
||||
func ExampleMember_GetEnumOptions() {
|
||||
member := spec.Member{
|
||||
Tag: `json:"foo,options=foo|bar|options|123"`,
|
||||
}
|
||||
fmt.Println(member.GetEnumOptions())
|
||||
// Output:
|
||||
// [foo bar options 123]
|
||||
}
|
||||
@@ -154,6 +154,27 @@ func (m Member) IsTagMember(tagKey string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetEnumOptions return a slice contains all enumeration options
|
||||
func (m Member) GetEnumOptions() []string {
|
||||
if !m.IsBodyMember() {
|
||||
return nil
|
||||
}
|
||||
|
||||
tags := m.Tags()
|
||||
for _, tag := range tags {
|
||||
if tag.Key == bodyTagKey {
|
||||
options := tag.Options
|
||||
for _, option := range options {
|
||||
if strings.Index(option, "options=") == 0 {
|
||||
option = strings.TrimPrefix(option, "options=")
|
||||
return strings.Split(option, "|")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBodyMembers returns all json fields
|
||||
func (t DefineStruct) GetBodyMembers() []Member {
|
||||
var result []Member
|
||||
|
||||
Reference in New Issue
Block a user