From 24c120896de49aefb58e07b24ee3d31616f91381 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Mon, 27 Sep 2021 12:12:33 +0100 Subject: [PATCH] Fix golang clients string -> int64 unmarshale error (#217) --- clients/go/cache/cache.go | 12 ++++++------ clients/go/helloworld/helloworld.go | 2 +- clients/go/holidays/holidays.go | 2 +- clients/go/image/image.go | 4 ++-- clients/go/location/location.go | 4 ++-- clients/go/otp/otp.go | 4 ++-- clients/go/qr/qr.go | 2 +- clients/go/rss/rss.go | 4 ++-- clients/go/time/time.go | 2 +- clients/go/twitter/twitter.go | 12 ++++++------ clients/go/url/url.go | 4 ++-- clients/go/user/user.go | 10 +++++----- clients/ts/package.json | 2 +- cmd/clients/main.go | 11 ++++++++--- examples/db/create/go/createARecord.go | 4 ++-- 15 files changed, 42 insertions(+), 37 deletions(-) diff --git a/clients/go/cache/cache.go b/clients/go/cache/cache.go index 63fea8e..ebbc9b1 100755 --- a/clients/go/cache/cache.go +++ b/clients/go/cache/cache.go @@ -50,14 +50,14 @@ type DecrementRequest struct { // The key to decrement Key string `json:"key"` // The amount to decrement the value by - Value int64 `json:"value"` + Value int64 `json:"value,string"` } type DecrementResponse struct { // The key decremented Key string `json:"key"` // The new value - Value int64 `json:"value"` + Value int64 `json:"value,string"` } type DeleteRequest struct { @@ -79,7 +79,7 @@ type GetResponse struct { // The key Key string `json:"key"` // Time to live in seconds - Ttl int64 `json:"ttl"` + Ttl int64 `json:"ttl,string"` // The value Value string `json:"value"` } @@ -88,21 +88,21 @@ type IncrementRequest struct { // The key to increment Key string `json:"key"` // The amount to increment the value by - Value int64 `json:"value"` + Value int64 `json:"value,string"` } type IncrementResponse struct { // The key incremented Key string `json:"key"` // The new value - Value int64 `json:"value"` + Value int64 `json:"value,string"` } type SetRequest struct { // The key to update Key string `json:"key"` // Time to live in seconds - Ttl int64 `json:"ttl"` + Ttl int64 `json:"ttl,string"` // The value to set Value string `json:"value"` } diff --git a/clients/go/helloworld/helloworld.go b/clients/go/helloworld/helloworld.go index 0777b7e..075fd71 100755 --- a/clients/go/helloworld/helloworld.go +++ b/clients/go/helloworld/helloworld.go @@ -38,7 +38,7 @@ type CallResponse struct { type StreamRequest struct { // the number of messages to send back - Messages int64 `json:"messages"` + Messages int64 `json:"messages,string"` Name string `json:"name"` } diff --git a/clients/go/holidays/holidays.go b/clients/go/holidays/holidays.go index 37f4540..db338a7 100755 --- a/clients/go/holidays/holidays.go +++ b/clients/go/holidays/holidays.go @@ -61,7 +61,7 @@ type ListRequest struct { // The 2 letter country code (as defined in ISO 3166-1 alpha-2) CountryCode string `json:"countryCode"` // The year to list holidays for - Year int64 `json:"year"` + Year int64 `json:"year,string"` } type ListResponse struct { diff --git a/clients/go/image/image.go b/clients/go/image/image.go index 37bf373..e323614 100755 --- a/clients/go/image/image.go +++ b/clients/go/image/image.go @@ -85,14 +85,14 @@ type ResizeRequest struct { // if provided, after resize, the image // will be cropped CropOptions *CropOptions `json:"cropOptions"` - Height int64 `json:"height"` + Height int64 `json:"height,string"` // output name of the image including extension, ie. "cat.png" Name string `json:"name"` // make output a URL and not a base64 response OutputUrl bool `json:"outputUrl"` // url of the image to resize Url string `json:"url"` - Width int64 `json:"width"` + Width int64 `json:"width,string"` } type ResizeResponse struct { diff --git a/clients/go/location/location.go b/clients/go/location/location.go index 5c477f9..1acca4d 100755 --- a/clients/go/location/location.go +++ b/clients/go/location/location.go @@ -43,7 +43,7 @@ type Entity struct { type Point struct { Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` - Timestamp int64 `json:"timestamp"` + Timestamp int64 `json:"timestamp,string"` } type ReadRequest struct { @@ -66,7 +66,7 @@ type SearchRequest struct { // Central position to search from Center *Point `json:"center"` // Maximum number of entities to return - NumEntities int64 `json:"numEntities"` + NumEntities int64 `json:"numEntities,string"` // radius in meters Radius float64 `json:"radius"` // type of entities to filter diff --git a/clients/go/otp/otp.go b/clients/go/otp/otp.go index 17764cd..5cc952f 100755 --- a/clients/go/otp/otp.go +++ b/clients/go/otp/otp.go @@ -30,11 +30,11 @@ func (t *OtpService) Validate(request *ValidateRequest) (*ValidateResponse, erro type GenerateRequest struct { // expiration in seconds (default: 60) - Expiry int64 `json:"expiry"` + Expiry int64 `json:"expiry,string"` // unique id, email or user to generate an OTP for Id string `json:"id"` // number of characters (default: 6) - Size int64 `json:"size"` + Size int64 `json:"size,string"` } type GenerateResponse struct { diff --git a/clients/go/qr/qr.go b/clients/go/qr/qr.go index 90d3136..b0e4a34 100755 --- a/clients/go/qr/qr.go +++ b/clients/go/qr/qr.go @@ -24,7 +24,7 @@ func (t *QrService) Generate(request *GenerateRequest) (*GenerateResponse, error type GenerateRequest struct { // the size (height and width) in pixels of the generated QR code. Defaults to 256 - Size int64 `json:"size"` + Size int64 `json:"size,string"` // the text to encode as a QR code (URL, phone number, email, etc) Text string `json:"text"` } diff --git a/clients/go/rss/rss.go b/clients/go/rss/rss.go index 04acf3d..9348dc6 100755 --- a/clients/go/rss/rss.go +++ b/clients/go/rss/rss.go @@ -86,11 +86,11 @@ type Feed struct { type FeedRequest struct { // limit entries returned - Limit int64 `json:"limit"` + Limit int64 `json:"limit,string"` // rss feed name Name string `json:"name"` // offset entries - Offset int64 `json:"offset"` + Offset int64 `json:"offset,string"` } type FeedResponse struct { diff --git a/clients/go/time/time.go b/clients/go/time/time.go index cbda864..aa61e65 100755 --- a/clients/go/time/time.go +++ b/clients/go/time/time.go @@ -43,7 +43,7 @@ type NowResponse struct { // the timezone as BST Timezone string `json:"timezone"` // the unix timestamp - Unix int64 `json:"unix"` + Unix int64 `json:"unix,string"` } type ZoneRequest struct { diff --git a/clients/go/twitter/twitter.go b/clients/go/twitter/twitter.go index 358ecef..a855bfe 100755 --- a/clients/go/twitter/twitter.go +++ b/clients/go/twitter/twitter.go @@ -46,9 +46,9 @@ type Profile struct { // the user description Description string `json:"description"` // the follower count - Followers int64 `json:"followers"` + Followers int64 `json:"followers,string"` // the user id - Id int64 `json:"id"` + Id int64 `json:"id,string"` // The user's profile picture ImageUrl string `json:"imageUrl"` // the user's location @@ -91,7 +91,7 @@ type Trend struct { // name of the trend Name string `json:"name"` // the volume of tweets in last 24 hours - TweetVolume int64 `json:"tweetVolume"` + TweetVolume int64 `json:"tweetVolume,string"` // the twitter url Url string `json:"url"` } @@ -108,11 +108,11 @@ type Tweet struct { // time of tweet CreatedAt string `json:"createdAt"` // number of times favourited - FavouritedCount int64 `json:"favouritedCount"` + FavouritedCount int64 `json:"favouritedCount,string"` // id of the tweet - Id int64 `json:"id"` + Id int64 `json:"id,string"` // number of times retweeted - RetweetedCount int64 `json:"retweetedCount"` + RetweetedCount int64 `json:"retweetedCount,string"` // text of the tweet Text string `json:"text"` // username of the person who tweeted diff --git a/clients/go/url/url.go b/clients/go/url/url.go index 75fb17e..cb3b79a 100755 --- a/clients/go/url/url.go +++ b/clients/go/url/url.go @@ -62,12 +62,12 @@ type ShortenResponse struct { } type URLPair struct { - Created int64 `json:"created"` + Created int64 `json:"created,string"` DestinationUrl string `json:"destinationUrl"` // HitCount keeps track many times the short URL has been resolved. // Hitcount only gets saved to disk (database) after every 10th hit, so // its not intended to be 100% accurate, more like an almost correct estimate. - HitCount int64 `json:"hitCount"` + HitCount int64 `json:"hitCount,string"` Owner string `json:"owner"` ShortUrl string `json:"shortUrl"` } diff --git a/clients/go/user/user.go b/clients/go/user/user.go index f4aa7d9..8387486 100755 --- a/clients/go/user/user.go +++ b/clients/go/user/user.go @@ -85,7 +85,7 @@ func (t *UserService) VerifyEmail(request *VerifyEmailRequest) (*VerifyEmailResp type Account struct { // unix timestamp - Created int64 `json:"created"` + Created int64 `json:"created,string"` // an email address Email string `json:"email"` // unique account id @@ -93,10 +93,10 @@ type Account struct { // Store any custom data you want about your users in this fields. Profile map[string]string `json:"profile"` // unix timestamp - Updated int64 `json:"updated"` + Updated int64 `json:"updated,string"` // alphanumeric username Username string `json:"username"` - VerificationDate int64 `json:"verificationDate"` + VerificationDate int64 `json:"verificationDate,string"` Verified bool `json:"verified"` } @@ -185,9 +185,9 @@ type SendVerificationEmailResponse struct { type Session struct { // unix timestamp - Created int64 `json:"created"` + Created int64 `json:"created,string"` // unix timestamp - Expires int64 `json:"expires"` + Expires int64 `json:"expires,string"` // the session id Id string `json:"id"` // the associated user id diff --git a/clients/ts/package.json b/clients/ts/package.json index 3c49768..d0c5a72 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -61,5 +61,5 @@ }, "type": "module", "types": "dist/index.d.ts", - "version": "1.0.529" + "version": "1.0.530" } \ No newline at end of file diff --git a/cmd/clients/main.go b/cmd/clients/main.go index e6c4185..412897e 100644 --- a/cmd/clients/main.go +++ b/cmd/clients/main.go @@ -710,6 +710,7 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op if fieldUpperCase { k = strcase.UpperCamelCase(k) } + var typ string // @todo clean up this piece of code by // separating out type string marshaling and not // repeating code @@ -765,7 +766,7 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op case "string": ret += k + fieldSeparator + stringType + fieldDelimiter case "number": - typ := numberType + typ = numberType switch v.Value.Format { case "int32": typ = int32Type @@ -780,9 +781,13 @@ func schemaToType(language, serviceName, typeName string, schemas map[string]*op case "boolean": ret += k + fieldSeparator + boolType + fieldDelimiter } - // go specific hack for lowercase son + // go specific hack for lowercase json if language == "go" { - ret += " " + "`json:\"" + strcase.LowerCamelCase(k) + "\"`" + ret += " " + "`json:\"" + strcase.LowerCamelCase(k) + if typ == int64Type { + ret += ",string" + } + ret += "\"`" } if i < len(props) { diff --git a/examples/db/create/go/createARecord.go b/examples/db/create/go/createARecord.go index ed2b1c4..c57135b 100755 --- a/examples/db/create/go/createARecord.go +++ b/examples/db/create/go/createARecord.go @@ -11,10 +11,10 @@ func CreateArecord() { dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ - "id": "1", - "name": "Jane", "age": 42, "isActive": true, + "id": "1", + "name": "Jane", }, Table: "users", })