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
20 changes: 10 additions & 10 deletions kotlin/kotlin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
DefaultMap = "emptyMap()"
DefaultLocalTime = "LocalTime.now()"

version = "1.0.0"
version = "1.0.1"
)

var (
Expand Down Expand Up @@ -139,7 +139,6 @@ func (g *Generator) prepareTemplateData() templateData {
data := templateData{GeneratorData: gen.DefaultGeneratorData().AddLangAndLocalVersion(version, "kotlin"), PackageAPI: g.settings.PackageAPI, Imports: g.settings.Imports, Class: g.settings.Class}

modelsMap := make(map[string]Model)
servicesMap := make(map[string][]Method)

for serviceName, service := range g.schema.Services {
var (
Expand All @@ -166,14 +165,8 @@ func (g *Generator) prepareTemplateData() templateData {
params = append(params, p)
}
method.Parameters = params
normalizeMethodReturnType(&method)
data.Methods = append(data.Methods, method)
if g.settings.IsProtocol {
parts := strings.SplitN(method.Name, ".", 2)
if len(parts) != 2 {
continue
}
servicesMap[parts[0]] = append(servicesMap[parts[0]], method)
}
}

for _, v := range modelsMap {
Expand All @@ -188,6 +181,13 @@ func (g *Generator) prepareTemplateData() templateData {
return data
}

// normalizeMethodReturnType check suffix ids and type list convert to List<Long>
func normalizeMethodReturnType(method *Method) {
if strings.HasSuffix(strings.ToLower(method.Name), "ids") && method.Returns.Type == "List<Int>" {
method.Returns.Type = "List<Long>"
}
}

func (g *Generator) fillIsInitial(data *templateData) {
modelByName := make(map[string]*Model, len(data.Models))
for i := range data.Models {
Expand Down Expand Up @@ -468,7 +468,7 @@ func kotlinDefault(smdType string) string {
}

if strings.HasPrefix(smdType, Map) {
return DefaultList
return DefaultMap
}

return smdType
Expand Down
8 changes: 6 additions & 2 deletions kotlin/testdata/arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Point struct {
Z int `json:"-"`
CartId string `json:"cartOd"` // version string id - 1
ID int `json:"id"` // version id - 1
BaseID int `json:"baseId"` // version id - 2
SecondID int `json:"secondID"` // version id - 3
BaseID int64 `json:"baseId"` // version id - 2
SecondID int32 `json:"secondID"` // version id - 3
SecondIDs []int `json:"secondIDs"` // version multi id
CartIDs []string `json:"cartIDs"` // version multi string id
CreatedAt string `json:"createdAt"` // version date - 1
Expand Down Expand Up @@ -48,6 +48,10 @@ func (as ArithService) GetByID(ctx context.Context, cartId string, categoryId in
return &Point{}, nil
}

func (as ArithService) GetSecondIds(ctx context.Context) []int {
return nil
}

func (as ArithService) GetByLatLong(ctx context.Context, categoryId int, baseID int, lat, lon float64) (*Point, error) {
return &Point{}, nil
}
Expand Down
10 changes: 9 additions & 1 deletion kotlin/testdata/protocol.generated.kt
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 kotlin v1.0.0; DO NOT EDIT.
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.1; DO NOT EDIT.
package api

import com.google.gson.reflect.TypeToken
Expand Down Expand Up @@ -171,6 +171,14 @@ interface Api : Transport {
"arith.GetPoints",
)

fun arithGetSecondIds(
vararg transportOptions: TransportOption,
) = request(
transportOptions,
object : TypeToken<ApiResponse<List<Long>>>() {},
"arith.GetSecondIds",
)

/**
* Multiply multiples two digits and returns result.
* @return
Expand Down
2 changes: 1 addition & 1 deletion kotlin/testdata/rpc.generated.kt
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 kotlin v1.0.0; DO NOT EDIT.
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.1; DO NOT EDIT.
package api.model

import java.time.LocalTime
Expand Down
18 changes: 16 additions & 2 deletions kotlin/testdata/testdata_zenrpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.