Fix golang clients string -> int64 unmarshale error (#217)

This commit is contained in:
Janos Dobronszki
2021-09-27 12:12:33 +01:00
committed by GitHub
parent 6992fae6cf
commit 24c120896d
15 changed files with 42 additions and 37 deletions

View File

@@ -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"`
}

View File

@@ -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"`
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {

View File

@@ -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"`
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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"`
}

View File

@@ -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

View File

@@ -61,5 +61,5 @@
},
"type": "module",
"types": "dist/index.d.ts",
"version": "1.0.529"
"version": "1.0.530"
}

View File

@@ -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) {

View File

@@ -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",
})