Skip to content

Commit 639809e

Browse files
qnqatopandrey
andauthored
Kotlin: check methods to contains name 'ids' and with type List convert to List<Long> (#35)
Co-authored-by: andrey <palchikov@uteka.ru>
1 parent 66b7ab9 commit 639809e

5 files changed

Lines changed: 42 additions & 16 deletions

File tree

kotlin/kotlin_client.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
DefaultMap = "emptyMap()"
3737
DefaultLocalTime = "LocalTime.now()"
3838

39-
version = "1.0.0"
39+
version = "1.0.1"
4040
)
4141

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

141141
modelsMap := make(map[string]Model)
142-
servicesMap := make(map[string][]Method)
143142

144143
for serviceName, service := range g.schema.Services {
145144
var (
@@ -166,14 +165,8 @@ func (g *Generator) prepareTemplateData() templateData {
166165
params = append(params, p)
167166
}
168167
method.Parameters = params
168+
normalizeMethodReturnType(&method)
169169
data.Methods = append(data.Methods, method)
170-
if g.settings.IsProtocol {
171-
parts := strings.SplitN(method.Name, ".", 2)
172-
if len(parts) != 2 {
173-
continue
174-
}
175-
servicesMap[parts[0]] = append(servicesMap[parts[0]], method)
176-
}
177170
}
178171

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

184+
// normalizeMethodReturnType check suffix ids and type list convert to List<Long>
185+
func normalizeMethodReturnType(method *Method) {
186+
if strings.HasSuffix(strings.ToLower(method.Name), "ids") && method.Returns.Type == "List<Int>" {
187+
method.Returns.Type = "List<Long>"
188+
}
189+
}
190+
191191
func (g *Generator) fillIsInitial(data *templateData) {
192192
modelByName := make(map[string]*Model, len(data.Models))
193193
for i := range data.Models {
@@ -468,7 +468,7 @@ func kotlinDefault(smdType string) string {
468468
}
469469

470470
if strings.HasPrefix(smdType, Map) {
471-
return DefaultList
471+
return DefaultMap
472472
}
473473

474474
return smdType

kotlin/testdata/arith.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type Point struct {
1717
Z int `json:"-"`
1818
CartId string `json:"cartOd"` // version string id - 1
1919
ID int `json:"id"` // version id - 1
20-
BaseID int `json:"baseId"` // version id - 2
21-
SecondID int `json:"secondID"` // version id - 3
20+
BaseID int64 `json:"baseId"` // version id - 2
21+
SecondID int32 `json:"secondID"` // version id - 3
2222
SecondIDs []int `json:"secondIDs"` // version multi id
2323
CartIDs []string `json:"cartIDs"` // version multi string id
2424
CreatedAt string `json:"createdAt"` // version date - 1
@@ -48,6 +48,10 @@ func (as ArithService) GetByID(ctx context.Context, cartId string, categoryId in
4848
return &Point{}, nil
4949
}
5050

51+
func (as ArithService) GetSecondIds(ctx context.Context) []int {
52+
return nil
53+
}
54+
5155
func (as ArithService) GetByLatLong(ctx context.Context, categoryId int, baseID int, lat, lon float64) (*Point, error) {
5256
return &Point{}, nil
5357
}

kotlin/testdata/protocol.generated.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.0; DO NOT EDIT.
1+
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.1; DO NOT EDIT.
22
package api
33

44
import com.google.gson.reflect.TypeToken
@@ -171,6 +171,14 @@ interface Api : Transport {
171171
"arith.GetPoints",
172172
)
173173

174+
fun arithGetSecondIds(
175+
vararg transportOptions: TransportOption,
176+
) = request(
177+
transportOptions,
178+
object : TypeToken<ApiResponse<List<Long>>>() {},
179+
"arith.GetSecondIds",
180+
)
181+
174182
/**
175183
* Multiply multiples two digits and returns result.
176184
* @return

kotlin/testdata/rpc.generated.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.0; DO NOT EDIT.
1+
/// Code generated from jsonrpc schema by rpcgen v2.5.x with kotlin v1.0.1; DO NOT EDIT.
22
package api.model
33

44
import java.time.LocalTime

kotlin/testdata/testdata_zenrpc.go

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)