Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.24.0
require (
github.com/vmkteam/meta-schema/v2 v2.0.1
github.com/vmkteam/zenrpc v1.1.1
github.com/vmkteam/zenrpc/v2 v2.3.0
github.com/vmkteam/zenrpc/v2 v2.3.1
golang.org/x/text v0.29.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/vmkteam/meta-schema/v2 v2.0.1 h1:7eoImKpnCs2wiCcBB8AUCtfVVhGa6L6DDqih
github.com/vmkteam/meta-schema/v2 v2.0.1/go.mod h1:GQzU4Rid0Q9dDIz/OeSDyL/aB/QG7tD0gOUt5nQ4JMk=
github.com/vmkteam/zenrpc v1.1.1 h1:WmModRVCwgs7XEkeJcVvmDOwEtAQk0TuYV91wdpAaCw=
github.com/vmkteam/zenrpc v1.1.1/go.mod h1:x3fCkb9HHOpqwqC7TKXf8pyXWdPxEt2Zrndl50YxexM=
github.com/vmkteam/zenrpc/v2 v2.3.0 h1:C3jBi0FkseKmVVh2WTvdMuG0THdL84jOut4Xsqx5NeM=
github.com/vmkteam/zenrpc/v2 v2.3.0/go.mod h1:HSnsZXbtiRDdnga3YjG8x2lQsQha7Jy/pZSFnNN+XeM=
github.com/vmkteam/zenrpc/v2 v2.3.1 h1:JbQXzlYJWNdMXL2xClItf5bK0aLZFozTbqKXJZRyfGo=
github.com/vmkteam/zenrpc/v2 v2.3.1/go.mod h1:HSnsZXbtiRDdnga3YjG8x2lQsQha7Jy/pZSFnNN+XeM=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
Expand Down
2 changes: 1 addition & 1 deletion golang/go_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
version = "1.0.0"
version = "1.1.0"
lang = "golang"
)

Expand Down
1 change: 1 addition & 0 deletions golang/rpcgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestGenerateGoClient(t *testing.T) {
rpc.Register("catalogue", testdata.CatalogueService{})
rpc.Register("phonebook", testdata.PhoneBook{})
rpc.Register("arith", testdata.ArithService{})
rpc.Register("print", testdata.PrintService{})

cl := NewClient(rpc.SMD(), Settings{})

Expand Down
15 changes: 8 additions & 7 deletions golang/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ func (v *Value) GoType() string {
}

return fmt.Sprintf("[]%s", simpleGoType(v.ArrayItemType))
} else if v.Type == smd.Object {
} else if v.Type == smd.Object && v.ModelName != "" {
return v.LocalModelName()
} else if v.Type == smd.Object {
return "any"
}

return simpleGoType(v.Type)
Expand Down Expand Up @@ -293,11 +295,6 @@ func newMethod(service smd.Service, namespace, methodName string) Method {

if service.Returns.Type != "" {
method.Returns = newValuePointer(service.Returns, namespace, methodName)

// fix return model name
if method.Returns.Type == smd.Object && method.Returns.ModelName == "" {
method.Returns.ModelName = fmt.Sprintf("%s%sResponse", titleFirstLetter(namespace), titleFirstLetter(methodName))
}
}

return method
Expand Down Expand Up @@ -327,6 +324,8 @@ func newValue(in smd.JSONSchema, namespace, methodName string, isParam, isReturn
value.ModelName = in.TypeName
} else if in.Description != "" && smd.IsSMDTypeName(in.Description, in.Type) {
value.ModelName = in.Description
} else if len(in.Properties) == 0 && len(in.Definitions) == 0 && len(in.Items) == 0 {
value.ModelName = ""
} else if isParam {
value.ModelName = fmt.Sprintf("%s%s%sParam", titleFirstLetter(namespace), titleFirstLetter(methodName), titleFirstLetter(in.Name))
} else if isReturn {
Expand Down Expand Up @@ -400,7 +399,9 @@ func cleanModelList(models []Model, namespace, methodName string) (res []Model)
for _, model := range models {
// fix empty model names
if model.Name == "" {
if model.IsParamModel {
if len(model.Fields) == 0 {
continue
} else if model.IsParamModel {
model.Name = fmt.Sprintf("%s%s%sParam", titleFirstLetter(namespace), titleFirstLetter(methodName), titleFirstLetter(model.ParamName))
} else if model.IsReturnModel {
model.Name = fmt.Sprintf("%s%sResponse", titleFirstLetter(namespace), titleFirstLetter(methodName))
Expand Down
40 changes: 40 additions & 0 deletions golang/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,46 @@ func TestConvertJSONSchema(t *testing.T) {
},
},
},
// object param with no properties/definitions should result in "any"
{
in: smd.Schema{
Services: map[string]smd.Service{
"simple.anyParam": {
Parameters: []smd.JSONSchema{
{
Name: "data",
Type: "object",
},
},
Returns: smd.JSONSchema{
Type: smd.Object,
},
},
},
},
out: Schema{
Namespaces: []Namespace{
{
Name: "simple",
Methods: []Method{
{
Name: "anyParam",
Params: []Value{
{
Name: "data",
Type: "object",
ModelName: "",
},
},
Returns: &Value{
Type: "object",
},
},
},
},
},
},
},
}

for _, tt := range tc {
Expand Down
74 changes: 73 additions & 1 deletion golang/testdata/catalogue_client.go.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code generated from jsonrpc schema by rpcgen v2.5.x with golang v1.0.0; DO NOT EDIT.
// Code generated from jsonrpc schema by rpcgen v2.5.x with golang v1.1.0; DO NOT EDIT.

package client

Expand Down Expand Up @@ -30,6 +30,7 @@ type Client struct {
Arith *svcArith
Catalogue *svcCatalogue
Phonebook *svcPhonebook
Print *svcPrint
}

func NewClient(endpoint string, httpClient *http.Client) *Client {
Expand All @@ -43,6 +44,7 @@ func NewClient(endpoint string, httpClient *http.Client) *Client {
c.Arith = newClientArith(c.rpcClient)
c.Catalogue = newClientCatalogue(c.rpcClient)
c.Phonebook = newClientPhonebook(c.rpcClient)
c.Print = newClientPrint(c.rpcClient)

return c
}
Expand Down Expand Up @@ -462,6 +464,76 @@ func (c *svcPhonebook) ValidateSearch(ctx context.Context, search *PersonSearch)
return
}

type svcPrint struct {
client *rpcClient
}

func newClientPrint(client *rpcClient) *svcPrint {
return &svcPrint{
client: client,
}
}

func (c *svcPrint) PrintAnything(ctx context.Context, s any) (res any, err error) {
_req := struct {
S any
}{
S: s,
}

err = c.client.call(ctx, "print.PrintAnything", _req, &res)

return
}

func (c *svcPrint) PrintOptional(ctx context.Context, s *string) (res string, err error) {
_req := struct {
S *string
}{
S: s,
}

err = c.client.call(ctx, "print.PrintOptional", _req, &res)

return
}

func (c *svcPrint) PrintOptionalWithDefault(ctx context.Context, s *string) (res string, err error) {
_req := struct {
S *string
}{
S: s,
}

err = c.client.call(ctx, "print.PrintOptionalWithDefault", _req, &res)

return
}

func (c *svcPrint) PrintRequired(ctx context.Context, s string) (res string, err error) {
_req := struct {
S string
}{
S: s,
}

err = c.client.call(ctx, "print.PrintRequired", _req, &res)

return
}

func (c *svcPrint) PrintRequiredDefault(ctx context.Context, s *string) (res string, err error) {
_req := struct {
S *string
}{
S: s,
}

err = c.client.call(ctx, "print.PrintRequiredDefault", _req, &res)

return
}

type rpcClient struct {
endpoint string
cl *http.Client
Expand Down