diff --git a/kotlin/kotlin_client.go b/kotlin/kotlin_client.go index 04d7826..cbab05f 100644 --- a/kotlin/kotlin_client.go +++ b/kotlin/kotlin_client.go @@ -50,10 +50,10 @@ var ( Long: DefaultInteger, } doubleSuffixes = map[string]struct{}{ - "Lat": {}, - "Lon": {}, - "Latitude": {}, - "Longitude": {}, + "lat": {}, + "lon": {}, + "latitude": {}, + "longitude": {}, } reservedKeywords = []string{"as", "as?", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in", "!in", "interface", "is", "!is", "null", "object", "package", "return", "super", "this", "throw", "true", @@ -182,6 +182,7 @@ func (g *Generator) prepareTemplateData() templateData { g.sortTemplateData(&data) g.prepareModelFieldName(&data) + g.resolveTypes(&data) return data } @@ -288,6 +289,44 @@ func (g *Generator) executeTemplate(data templateData) ([]byte, error) { return buf.Bytes(), nil } +// resolveTypes last check and update params in methods +func (g *Generator) resolveTypes(data *templateData) { + for i := range data.Methods { + method := &data.Methods[i] + for j := range method.Parameters { + param := &method.Parameters[j] + if newType, ok := inferKotlinType(param.Type, param.Name); ok { + param.setType(newType) + } + } + } +} + +func inferKotlinType(valType, name string) (string, bool) { + switch valType { + case Int: + if kotlinTypeID(name) { + return Long, true + } + case Float: + if kotlinTypeDouble(name) { + return Double, true + } + case String: + if kotlinTypeTimestamp(name) { + return Timestamp, true + } + } + return "", false +} + +// setType update all types +func (p *Parameter) setType(t string) { + p.Type = t + p.BaseType = t + p.ReturnType = t +} + // propertiesToParams convert smd.PropertyList to []Parameter func (g *Generator) propertiesToParams(typeName string, list smd.PropertyList) []Parameter { parameters := make([]Parameter, 0, len(list)) @@ -435,6 +474,7 @@ func kotlinDefault(smdType string) string { // kotlinTypeDouble check if property need set type Double func kotlinTypeDouble(name string) bool { + name = strings.ToLower(name) if _, ok := doubleSuffixes[name]; ok { return true } @@ -448,17 +488,18 @@ func kotlinTypeDouble(name string) bool { return false } -// kotlinTypeID check if property is ID set type Long +// kotlinTypeID check if property is ID or IDs set type Long func kotlinTypeID(name string) bool { return name == id || strings.HasSuffix(name, strings.ToUpper(id)) || strings.HasSuffix(name, "Id") || - strings.HasSuffix(name, "Ids") + strings.HasSuffix(name, "Id"+"s") || + strings.HasSuffix(name, strings.ToUpper(id)+"s") } // kotlinTypeTimestamp check if is time property set Timestamp func kotlinTypeTimestamp(name string) bool { - return strings.HasSuffix(name, "edAt") + return strings.HasSuffix(name, "At") } func arrayType(items map[string]string, isReturnType bool) string { diff --git a/kotlin/kotlin_client_test.go b/kotlin/kotlin_client_test.go index cd3235f..947c90c 100644 --- a/kotlin/kotlin_client_test.go +++ b/kotlin/kotlin_client_test.go @@ -2,6 +2,7 @@ package kotlin import ( "bytes" + "flag" "os" "testing" @@ -12,12 +13,13 @@ import ( const testDataPath = "./testdata/rpc.generated.kt" const testDataProtocolPath = "./testdata/protocol.generated.kt" +var update = flag.Bool("update", false, "update .kt files") + func TestGenerator_Generate(t *testing.T) { type fields struct { settings Settings servicesMap map[string]zenrpc.Invoker } - var replace bool tests := []struct { name string @@ -62,7 +64,7 @@ func TestGenerator_Generate(t *testing.T) { t.Fatalf("generate client: %v", err) } - if replace { + if *update { var f *os.File f, err = os.Create(tt.outputFile) if err != nil { @@ -91,8 +93,6 @@ func TestGenerator_Generate(t *testing.T) { } func Test_kotlinTypeID(t *testing.T) { - type args struct { - } tests := []struct { name string typeName string @@ -113,6 +113,11 @@ func Test_kotlinTypeID(t *testing.T) { typeName: "nameIds", want: true, }, + { + name: "nameIDs", + typeName: "nameIDs", + want: true, + }, { name: "ID", typeName: "ID", @@ -123,6 +128,11 @@ func Test_kotlinTypeID(t *testing.T) { typeName: "nameId", want: true, }, + { + name: "nameID", + typeName: "nameID", + want: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/kotlin/testdata/arith.go b/kotlin/testdata/arith.go index 81367bb..fdee625 100644 --- a/kotlin/testdata/arith.go +++ b/kotlin/testdata/arith.go @@ -15,12 +15,16 @@ type ArithService struct{ zenrpc.Service } type Point struct { X, Y int // coordinate 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 + SecondIDs []int `json:"secondIDs"` // version multi id + CartIDs []string `json:"cartIDs"` // version multi string id CreatedAt string `json:"createdAt"` // version date - 1 UpdatedAt string `json:"updatedAt"` // version date - 2 ManualChangedAt string `json:"manualChangedAt"` // version date - 3 + StartAt string `json:"startAt"` // version date - 4 NewLat float64 `json:"newLat"` // version group geo coordinate № - 1 NewLon float64 `json:"newLon"` // version group geo coordinate № - 1 Lat float64 `json:"lat"` // version group geo coordinate № - 2 @@ -40,6 +44,18 @@ type Point struct { type SecondPoint struct { } +func (as ArithService) GetByID(ctx context.Context, cartId string, categoryId int, baseID int, id int) (*Point, error) { + return &Point{}, nil +} + +func (as ArithService) GetByLatLong(ctx context.Context, categoryId int, baseID int, lat, lon float64) (*Point, error) { + return &Point{}, nil +} + +func (as ArithService) GetByTime(ctx context.Context, createdAt string, updateAt string, startAt string) (*Point, error) { + return &Point{}, nil +} + // Sum sums two digits and returns error with error code as result and IP from context. func (as ArithService) Sum(ctx context.Context, a, b int) (bool, *zenrpc.Error) { r, _ := zenrpc.RequestFromContext(ctx) diff --git a/kotlin/testdata/protocol.generated.kt b/kotlin/testdata/protocol.generated.kt index cc0063e..83dce54 100644 --- a/kotlin/testdata/protocol.generated.kt +++ b/kotlin/testdata/protocol.generated.kt @@ -1,4 +1,4 @@ -/// Code generated from jsonrpc schema by rpcgen v2.4.8; DO NOT EDIT. +/// Code generated from jsonrpc schema by rpcgen v2.7.0; DO NOT EDIT. package api import com.google.gson.reflect.TypeToken @@ -108,6 +108,61 @@ interface Api : Transport { "pp" to pp, ) + /** + * @return + */ + fun arithGetByID( + cartId: String, + categoryId: Long, + baseID: Long, + id: Long, + vararg transportOptions: TransportOption, + ) = request( + transportOptions, + object : TypeToken>() {}, + "arith.GetByID", + "cartId" to cartId, + "categoryId" to categoryId, + "baseID" to baseID, + "id" to id, + ) + + /** + * @return + */ + fun arithGetByLatLong( + categoryId: Long, + baseID: Long, + lat: Double, + lon: Double, + vararg transportOptions: TransportOption, + ) = request( + transportOptions, + object : TypeToken>() {}, + "arith.GetByLatLong", + "categoryId" to categoryId, + "baseID" to baseID, + "lat" to lat, + "lon" to lon, + ) + + /** + * @return + */ + fun arithGetByTime( + createdAt: ZonedDateTime, + updateAt: ZonedDateTime, + startAt: ZonedDateTime, + vararg transportOptions: TransportOption, + ) = request( + transportOptions, + object : TypeToken>() {}, + "arith.GetByTime", + "createdAt" to createdAt, + "updateAt" to updateAt, + "startAt" to startAt, + ) + fun arithGetPoints( vararg transportOptions: TransportOption, ) = request( diff --git a/kotlin/testdata/rpc.generated.kt b/kotlin/testdata/rpc.generated.kt index 67d4ca8..f8cb50a 100644 --- a/kotlin/testdata/rpc.generated.kt +++ b/kotlin/testdata/rpc.generated.kt @@ -1,4 +1,4 @@ -/// Code generated from jsonrpc schema by rpcgen v2.4.8; DO NOT EDIT. +/// Code generated from jsonrpc schema by rpcgen v2.7.0; DO NOT EDIT. package api.model import java.time.LocalTime @@ -30,6 +30,14 @@ data class Point( * version id - 2 */ val baseId: Long = 0, + /** + * version multi string id + */ + val cartIDs: List = emptyList(), + /** + * version string id - 1 + */ + val cartOd: String = "", val `class`: String = "", /** * version date - 1 @@ -43,19 +51,19 @@ data class Point( /** * version group geo coordinate № - 2 */ - val lat: Float = 0f, + val lat: Double = 0.0, /** * version group geo coordinate № - 3 */ - val latitude: Float = 0f, + val latitude: Double = 0.0, /** * version group geo coordinate № - 2 */ - val lon: Float = 0f, + val lon: Double = 0.0, /** * version group geo coordinate № - 3 */ - val longitude: Float = 0f, + val longitude: Double = 0.0, /** * version date - 3 */ @@ -78,8 +86,16 @@ data class Point( * version id - 3 */ val secondID: Long = 0, + /** + * version multi id + */ + val secondIDs: List = emptyList(), val secondPoints: List = emptyList(), val secondQuotient: Quotient? = null, + /** + * version date - 4 + */ + val startAt: ZonedDateTime = ZonedDateTime.now(), /** * version date - 2 */ diff --git a/kotlin/testdata/testdata_zenrpc.go b/kotlin/testdata/testdata_zenrpc.go index f6b437b..86ecdf2 100644 --- a/kotlin/testdata/testdata_zenrpc.go +++ b/kotlin/testdata/testdata_zenrpc.go @@ -11,9 +11,12 @@ import ( ) var RPC = struct { - ArithService struct{ Sum, Positive, DoSomething, DoSomethingV2, GetPoints, DoSomethingWithPoint, Multiply, CheckError, CheckZenRPCError, Divide, Pow, Pi, SumArray string } + ArithService struct{ GetByID, GetByLatLong, GetByTime, Sum, Positive, DoSomething, DoSomethingV2, GetPoints, DoSomethingWithPoint, Multiply, CheckError, CheckZenRPCError, Divide, Pow, Pi, SumArray string } }{ - ArithService: struct{ Sum, Positive, DoSomething, DoSomethingV2, GetPoints, DoSomethingWithPoint, Multiply, CheckError, CheckZenRPCError, Divide, Pow, Pi, SumArray string }{ + ArithService: struct{ GetByID, GetByLatLong, GetByTime, Sum, Positive, DoSomething, DoSomethingV2, GetPoints, DoSomethingWithPoint, Multiply, CheckError, CheckZenRPCError, Divide, Pow, Pi, SumArray string }{ + GetByID: "getbyid", + GetByLatLong: "getbylatlong", + GetByTime: "getbytime", Sum: "sum", Positive: "positive", DoSomething: "dosomething", @@ -33,6 +36,1040 @@ var RPC = struct { func (ArithService) SMD() smd.ServiceInfo { return smd.ServiceInfo{ Methods: map[string]smd.Service{ + "GetByID": { + Parameters: []smd.JSONSchema{ + { + Name: "cartId", + Type: smd.String, + }, + { + Name: "categoryId", + Type: smd.Integer, + }, + { + Name: "baseID", + Type: smd.Integer, + }, + { + Name: "id", + Type: smd.Integer, + }, + }, + Returns: smd.JSONSchema{ + Optional: true, + Type: smd.Object, + TypeName: "Point", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + Definitions: map[string]smd.Definition{ + "Point": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + }, + "Quotient": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "Quo", + Description: `Quo docs`, + Type: smd.Integer, + }, + { + Name: "rem", + Description: `Rem docs`, + Type: smd.Integer, + }, + { + Name: "baseRow", + Type: smd.String, + }, + { + Name: "rowNil", + Optional: true, + Type: smd.String, + }, + { + Name: "data", + Ref: "#/definitions/CycleInitStruct", + Type: smd.Object, + }, + }, + }, + "CycleInitStruct": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "isCycleInit", + Type: smd.Boolean, + }, + }, + }, + }, + }, + }, + "GetByLatLong": { + Parameters: []smd.JSONSchema{ + { + Name: "categoryId", + Type: smd.Integer, + }, + { + Name: "baseID", + Type: smd.Integer, + }, + { + Name: "lat", + Type: smd.Float, + }, + { + Name: "lon", + Type: smd.Float, + }, + }, + Returns: smd.JSONSchema{ + Optional: true, + Type: smd.Object, + TypeName: "Point", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + Definitions: map[string]smd.Definition{ + "Point": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + }, + "Quotient": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "Quo", + Description: `Quo docs`, + Type: smd.Integer, + }, + { + Name: "rem", + Description: `Rem docs`, + Type: smd.Integer, + }, + { + Name: "baseRow", + Type: smd.String, + }, + { + Name: "rowNil", + Optional: true, + Type: smd.String, + }, + { + Name: "data", + Ref: "#/definitions/CycleInitStruct", + Type: smd.Object, + }, + }, + }, + "CycleInitStruct": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "isCycleInit", + Type: smd.Boolean, + }, + }, + }, + }, + }, + }, + "GetByTime": { + Parameters: []smd.JSONSchema{ + { + Name: "createdAt", + Type: smd.String, + }, + { + Name: "updateAt", + Type: smd.String, + }, + { + Name: "startAt", + Type: smd.String, + }, + }, + Returns: smd.JSONSchema{ + Optional: true, + Type: smd.Object, + TypeName: "Point", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + Definitions: map[string]smd.Definition{ + "Point": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "X", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "Y", + Description: `coordinate`, + Type: smd.Integer, + }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, + { + Name: "id", + Description: `version id - 1`, + Type: smd.Integer, + }, + { + Name: "baseId", + Description: `version id - 2`, + Type: smd.Integer, + }, + { + Name: "secondID", + Description: `version id - 3`, + Type: smd.Integer, + }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, + { + Name: "createdAt", + Description: `version date - 1`, + Type: smd.String, + }, + { + Name: "updatedAt", + Description: `version date - 2`, + Type: smd.String, + }, + { + Name: "manualChangedAt", + Description: `version date - 3`, + Type: smd.String, + }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, + { + Name: "newLat", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "newLon", + Description: `version group geo coordinate № - 1`, + Type: smd.Float, + }, + { + Name: "lat", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "lon", + Description: `version group geo coordinate № - 2`, + Type: smd.Float, + }, + { + Name: "latitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "longitude", + Description: `version group geo coordinate № - 3`, + Type: smd.Float, + }, + { + Name: "baseFloat", + Description: `version group float - 1`, + Type: smd.Float, + }, + { + Name: "secondFloat", + Description: `version group float - 2`, + Type: smd.Float, + }, + { + Name: "emptyString", + Optional: true, + Type: smd.String, + }, + { + Name: "name", + Type: smd.String, + }, + { + Name: "secondPoints", + Type: smd.Array, + Items: map[string]string{ + "$ref": "#/definitions/Point", + }, + }, + { + Name: "nextQuotient", + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "secondQuotient", + Optional: true, + Ref: "#/definitions/Quotient", + Type: smd.Object, + }, + { + Name: "class", + Type: smd.String, + }, + }, + }, + "Quotient": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "Quo", + Description: `Quo docs`, + Type: smd.Integer, + }, + { + Name: "rem", + Description: `Rem docs`, + Type: smd.Integer, + }, + { + Name: "baseRow", + Type: smd.String, + }, + { + Name: "rowNil", + Optional: true, + Type: smd.String, + }, + { + Name: "data", + Ref: "#/definitions/CycleInitStruct", + Type: smd.Object, + }, + }, + }, + "CycleInitStruct": { + Type: "object", + Properties: smd.PropertyList{ + { + Name: "isCycleInit", + Type: smd.Boolean, + }, + }, + }, + }, + }, + }, "Sum": { Description: `Sum sums two digits and returns error with error code as result and IP from context.`, Parameters: []smd.JSONSchema{ @@ -93,6 +1130,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -108,6 +1150,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -123,6 +1181,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -254,6 +1317,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -269,6 +1337,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -284,6 +1368,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -370,6 +1459,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -385,6 +1479,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -400,6 +1510,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -534,6 +1649,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -549,6 +1669,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -564,6 +1700,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -693,6 +1834,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -708,6 +1854,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -723,6 +1885,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -809,6 +1976,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `coordinate`, Type: smd.Integer, }, + { + Name: "cartOd", + Description: `version string id - 1`, + Type: smd.String, + }, { Name: "id", Description: `version id - 1`, @@ -824,6 +1996,22 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version id - 3`, Type: smd.Integer, }, + { + Name: "secondIDs", + Description: `version multi id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.Integer, + }, + }, + { + Name: "cartIDs", + Description: `version multi string id`, + Type: smd.Array, + Items: map[string]string{ + "type": smd.String, + }, + }, { Name: "createdAt", Description: `version date - 1`, @@ -839,6 +2027,11 @@ func (ArithService) SMD() smd.ServiceInfo { Description: `version date - 3`, Type: smd.String, }, + { + Name: "startAt", + Description: `version date - 4`, + Type: smd.String, + }, { Name: "newLat", Description: `version group geo coordinate № - 1`, @@ -1107,6 +2300,71 @@ func (s ArithService) Invoke(ctx context.Context, method string, params json.Raw var err error switch method { + case RPC.ArithService.GetByID: + var args = struct { + CartId string `json:"cartId"` + CategoryId int `json:"categoryId"` + BaseID int `json:"baseID"` + Id int `json:"id"` + }{} + + if zenrpc.IsArray(params) { + if params, err = zenrpc.ConvertToObject([]string{"cartId", "categoryId", "baseID", "id"}, params); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + if len(params) > 0 { + if err := json.Unmarshal(params, &args); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + resp.Set(s.GetByID(ctx, args.CartId, args.CategoryId, args.BaseID, args.Id)) + + case RPC.ArithService.GetByLatLong: + var args = struct { + CategoryId int `json:"categoryId"` + BaseID int `json:"baseID"` + Lat float64 `json:"lat"` + Lon float64 `json:"lon"` + }{} + + if zenrpc.IsArray(params) { + if params, err = zenrpc.ConvertToObject([]string{"categoryId", "baseID", "lat", "lon"}, params); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + if len(params) > 0 { + if err := json.Unmarshal(params, &args); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + resp.Set(s.GetByLatLong(ctx, args.CategoryId, args.BaseID, args.Lat, args.Lon)) + + case RPC.ArithService.GetByTime: + var args = struct { + CreatedAt string `json:"createdAt"` + UpdateAt string `json:"updateAt"` + StartAt string `json:"startAt"` + }{} + + if zenrpc.IsArray(params) { + if params, err = zenrpc.ConvertToObject([]string{"createdAt", "updateAt", "startAt"}, params); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + if len(params) > 0 { + if err := json.Unmarshal(params, &args); err != nil { + return zenrpc.NewResponseError(nil, zenrpc.InvalidParams, "", err.Error()) + } + } + + resp.Set(s.GetByTime(ctx, args.CreatedAt, args.UpdateAt, args.StartAt)) + case RPC.ArithService.Sum: var args = struct { A int `json:"a"`